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

Function _signature_is_functionlike

Lib/inspect.py:2071–2091  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 3

_has_code_flagFunction · 0.85
_signature_from_functionFunction · 0.85
_signature_from_callableFunction · 0.85

Calls 4

callableFunction · 0.85
isclassFunction · 0.85
getattrFunction · 0.85
isinstanceFunction · 0.85

Tested by

no test coverage detected