MCPcopy Index your code
hub / github.com/RustPython/RustPython / _set_signature

Function _set_signature

Lib/unittest/mock.py:184–208  ·  view source on GitHub ↗
(mock, original, instance=False)

Source from the content-addressed store, hash-verified

182
183
184def _set_signature(mock, original, instance=False):
185 # creates a function with signature (*args, **kwargs) that delegates to a
186 # mock. It still does signature checking by calling a lambda with the same
187 # signature as the original.
188
189 skipfirst = isinstance(original, type)
190 result = _get_signature_object(original, instance, skipfirst)
191 if result is None:
192 return mock
193 func, sig = result
194 def checksig(*args, **kwargs):
195 sig.bind(*args, **kwargs)
196 _copy_func_details(func, checksig)
197
198 name = original.__name__
199 if not name.isidentifier():
200 name = 'funcopy'
201 context = {'_checksig_': checksig, 'mock': mock}
202 src = """def %s(*args, **kwargs):
203 _checksig_(*args, **kwargs)
204 return mock(*args, **kwargs)""" % name
205 exec (src, context)
206 funcopy = context[name]
207 _setup_func(funcopy, mock, sig)
208 return funcopy
209
210def _set_async_signature(mock, original, instance=False, is_async_mock=False):
211 # creates an async function with signature (*args, **kwargs) that delegates to a

Callers 1

create_autospecFunction · 0.85

Calls 6

isinstanceFunction · 0.85
_get_signature_objectFunction · 0.85
_copy_func_detailsFunction · 0.85
_setup_funcFunction · 0.85
execFunction · 0.50
isidentifierMethod · 0.45

Tested by

no test coverage detected