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

Function _signature_is_functionlike

Lib/inspect.py:2078–2098  ·  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

2076
2077
2078def _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
2101def _signature_strip_non_python_syntax(signature):

Callers 3

_has_code_flagFunction · 0.85
_signature_from_functionFunction · 0.85
_signature_from_callableFunction · 0.85

Calls 1

isclassFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…