Private helper to test if `obj` is a duck type of FunctionType. A good example of such objects are functions compiled with Cython, which have all attributes that a pure Python function would have, but have their code statically compiled.
(obj)
| 2076 | |
| 2077 | |
| 2078 | def _signature_is_functionlike(obj): |
| 2079 | """Private helper to test if `obj` is a duck type of FunctionType. |
| 2080 | A good example of such objects are functions compiled with |
| 2081 | Cython, which have all attributes that a pure Python function |
| 2082 | would have, but have their code statically compiled. |
| 2083 | """ |
| 2084 | |
| 2085 | if not callable(obj) or isclass(obj): |
| 2086 | # All function-like objects are obviously callables, |
| 2087 | # and not classes. |
| 2088 | return False |
| 2089 | |
| 2090 | name = getattr(obj, '__name__', None) |
| 2091 | code = getattr(obj, '__code__', None) |
| 2092 | defaults = getattr(obj, '__defaults__', _void) # Important to use _void ... |
| 2093 | kwdefaults = getattr(obj, '__kwdefaults__', _void) # ... and not None here |
| 2094 | |
| 2095 | return (isinstance(code, types.CodeType) and |
| 2096 | isinstance(name, str) and |
| 2097 | (defaults is None or isinstance(defaults, tuple)) and |
| 2098 | (kwdefaults is None or isinstance(kwdefaults, dict))) |
| 2099 | |
| 2100 | |
| 2101 | def _signature_strip_non_python_syntax(signature): |
no test coverage detected
searching dependent graphs…