Message 416673 - Python tracker (original) (raw)
https://docs.python.org/3/library/inspect.html#inspect.isfunction says this:
""" inspect.isfunction(object) Return True if the object is a Python function, which includes functions created by a lambda expression. """
Emphasis on the "Python function", as in, something written in Python using a def
statement or a lambda
expression. If isfunction returns True, you can presumably access function-specific implementation details like the functions's f.code attribute. If you need to check for "anything that works as a function", you can use callable()
:
callable(lambda: 2) True callable(abs) True def f(x): return x callable(f) True
I'm not an expert on the inspect module, but I'm guessing it's not worth breaking backwards-compatibility to change this behavior.
Would extra emphasis in the documentation have been helpful for you, or were you mostly attempting to rely on the function's name?