This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dennis Sweeney
Recipients Dennis Sweeney, apostofes
Date 2022-04-04.14:44:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1649083464.02.0.50582302154.issue47214@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2022-04-04 14:44:24Dennis Sweeneysetrecipients: + Dennis Sweeney, apostofes
2022-04-04 14:44:24Dennis Sweeneysetmessageid: <1649083464.02.0.50582302154.issue47214@roundup.psfhosted.org>
2022-04-04 14:44:24Dennis Sweeneylinkissue47214 messages
2022-04-04 14:44:23Dennis Sweeneycreate