Message416673
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? |
|
Date |
User |
Action |
Args |
2022-04-04 14:44:24 | Dennis Sweeney | set | recipients:
+ Dennis Sweeney, apostofes |
2022-04-04 14:44:24 | Dennis Sweeney | set | messageid: <1649083464.02.0.50582302154.issue47214@roundup.psfhosted.org> |
2022-04-04 14:44:24 | Dennis Sweeney | link | issue47214 messages |
2022-04-04 14:44:23 | Dennis Sweeney | create | |
|