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