MCPcopy Create free account
hub / github.com/apache/arrow / _apply_patches

Method _apply_patches

dev/archery/archery/lang/python.py:153–192  ·  view source on GitHub ↗

Patch Docstring class to bypass loading already loaded python objects.

(self)

Source from the content-addressed store, hash-verified

151
152 @contextmanager
153 def _apply_patches(self):
154 """
155 Patch Docstring class to bypass loading already loaded python objects.
156 """
157 orig_load_obj = Docstring._load_obj
158 orig_signature = inspect.signature
159
160 @staticmethod
161 def _load_obj(obj):
162 # By default it expects a qualname and import the object, but we
163 # have already loaded object after the API traversal.
164 if isinstance(obj, str):
165 return orig_load_obj(obj)
166 else:
167 return obj
168
169 def signature(obj):
170 # inspect.signature tries to parse __text_signature__ if other
171 # properties like __signature__ doesn't exists, but cython
172 # doesn't set that property despite that embedsignature cython
173 # directive is set. The only way to inspect a cython compiled
174 # callable's signature to parse it from __doc__ while
175 # embedsignature directive is set during the build phase.
176 # So path inspect.signature function to attempt to parse the first
177 # line of callable.__doc__ as a signature.
178 try:
179 return orig_signature(obj)
180 except Exception as orig_error:
181 try:
182 return inspect_signature(obj)
183 except Exception:
184 raise orig_error
185
186 try:
187 Docstring._load_obj = _load_obj
188 inspect.signature = signature
189 yield
190 finally:
191 Docstring._load_obj = orig_load_obj
192 inspect.signature = orig_signature
193
194 def validate(self, from_package='', allow_rules=None,
195 disallow_rules=None):

Callers 1

validateMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected