(obj)
return (isinstance(code, types.CodeType) and
            isinstance(name, str) and
            (defaults is None or isinstance(defaults, tuple)) and
            (kwdefaults is None or isinstance(kwdefaults, dict)) and
            (isinstance(annotations, (dict)) or annotations is None) )
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.
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.
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 .
def _signature_is_functionlike(obj):
    """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.
    """

    if not callable(obj) or isclass(obj):
        # All function-like objects are obviously callables,
        # and not classes.
        return False

    name = getattr(obj, '__name__', None)
    code = getattr(obj, '__code__', None)
    defaults = getattr(obj, '__defaults__', _void) # Important to use _void ...
    kwdefaults = getattr(obj, '__kwdefaults__', _void) # ... and not None here
    annotations = getattr(obj, '__annotations__', None)

    return (isinstance(code, types.CodeType) and
            isinstance(name, str) and
            (defaults is None or isinstance(defaults, tuple)) and
            (kwdefaults is None or isinstance(kwdefaults, dict)) and
            (isinstance(annotations, (dict)) or annotations is None) )
def _signature_is_functionlike ( obj ) : if not callable ( obj ) or isclass ( obj ) : # All function-like objects are obviously callables, # and not classes. return False name = getattr ( obj , '__name__' , None ) code = getattr ( obj , '__code__' , None ) defaults = getattr ( obj , '__defaults__' , _void ) # Important to use _void ... kwdefaults = getattr ( obj , '__kwdefaults__' , _void ) # ... and not None here annotations = getattr ( obj , '__annotations__' , None ) return ( isinstance ( code , types . CodeType ) and isinstance ( name , str ) and ( defaults is None or isinstance ( defaults , tuple ) ) and ( kwdefaults is None or isinstance ( kwdefaults , dict ) ) and ( isinstance ( annotations , ( dict ) ) or annotations is None ) )