Message416682
Perhaps what you want is inspect.isroutine ?
https://docs.python.org/3/library/inspect.html#inspect.isroutine
I agree with Dennis that the isfunction test is for **Python** (def or lambda) functions, not builtins. The docstring for the inspect.is* methods make promises about what attributes an object will have:
def isbuiltin(object):
"""Return true if the object is a built-in function or method.
Built-in functions and methods provide these attributes:
__doc__ documentation string
__name__ original name of this function or method
__self__ instance to which a method is bound, or None"""
def isfunction(object):
"""Return true if the object is a user-defined function.
Function objects provide these attributes:
__doc__ documentation string
__name__ name with which this function was defined
__code__ code object containing compiled function bytecode
__defaults__ tuple of any default values for arguments
__globals__ global namespace in which this function was defined
__annotations__ dict of parameter annotations
__kwdefaults__ dict of keyword only parameters with defaults"""
def (and lambda) functions have a different API from builtin_function_or_method objects. They should be kept separate. |
|
Date |
User |
Action |
Args |
2022-04-04 17:33:18 | steven.daprano | set | recipients:
+ steven.daprano, Dennis Sweeney, apostofes |
2022-04-04 17:33:18 | steven.daprano | set | messageid: <1649093598.44.0.49091179356.issue47214@roundup.psfhosted.org> |
2022-04-04 17:33:18 | steven.daprano | link | issue47214 messages |
2022-04-04 17:33:18 | steven.daprano | create | |
|