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

Function _set_async_signature

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

Source from the content-addressed store, hash-verified

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
213 # mock. It still does signature checking by calling a lambda with the same
214 # signature as the original.
215
216 skipfirst = isinstance(original, type)
217 func, sig = _get_signature_object(original, instance, skipfirst)
218 def checksig(*args, **kwargs):
219 sig.bind(*args, **kwargs)
220 _copy_func_details(func, checksig)
221
222 name = original.__name__
223 context = {'_checksig_': checksig, 'mock': mock}
224 src = """async def %s(*args, **kwargs):
225 _checksig_(*args, **kwargs)
226 return await mock(*args, **kwargs)""" % name
227 exec (src, context)
228 funcopy = context[name]
229 _setup_func(funcopy, mock, sig)
230 _setup_async_mock(funcopy)
231 return funcopy
232
233
234def _setup_func(funcopy, mock, sig):

Callers 1

create_autospecFunction · 0.85

Calls 4

_get_signature_objectFunction · 0.85
_copy_func_detailsFunction · 0.85
_setup_funcFunction · 0.85
_setup_async_mockFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…