MCPcopy Index your code
hub / github.com/python/cpython / _set_signature

Function _set_signature

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

Source from the content-addressed store, hash-verified

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

Callers 1

create_autospecFunction · 0.85

Calls 4

_get_signature_objectFunction · 0.85
_copy_func_detailsFunction · 0.85
_setup_funcFunction · 0.85
isidentifierMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…