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

Function _get_signature_object

Lib/unittest/mock.py:93–125  ·  view source on GitHub ↗

Given an arbitrary, possibly callable object, try to create a suitable signature object. Return a (reduced func, signature) tuple, or None.

(func, as_instance, eat_self)

Source from the content-addressed store, hash-verified

91
92
93def _get_signature_object(func, as_instance, eat_self):
94 """
95 Given an arbitrary, possibly callable object, try to create a suitable
96 signature object.
97 Return a (reduced func, signature) tuple, or None.
98 """
99 if isinstance(func, type) and not as_instance:
100 # If it's a type and should be modelled as a type, use __init__.
101 func = func.__init__
102 # Skip the `self` argument in __init__
103 eat_self = True
104 elif isinstance(func, (classmethod, staticmethod)):
105 if isinstance(func, classmethod):
106 # Skip the `cls` argument of a class method
107 eat_self = True
108 # Use the original decorated method to extract the correct function signature
109 func = func.__func__
110 elif not isinstance(func, FunctionTypes):
111 # If we really want to model an instance of the passed type,
112 # __call__ should be looked up, not __init__.
113 try:
114 func = func.__call__
115 except AttributeError:
116 return None
117 if eat_self:
118 sig_func = partial(func, None)
119 else:
120 sig_func = func
121 try:
122 return func, inspect.signature(sig_func)
123 except ValueError:
124 # Certain callable types are not supported by inspect.signature()
125 return None
126
127
128def _check_signature(func, mock, skipfirst, instance=False):

Callers 4

_check_signatureFunction · 0.85
_set_signatureFunction · 0.85
_set_async_signatureFunction · 0.85
_mock_add_specMethod · 0.85

Calls 3

partialClass · 0.90
isinstanceFunction · 0.85
signatureMethod · 0.45

Tested by

no test coverage detected