-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
builtin_function_or_method is also either a function or a method #91370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
the.
does not consider a
as a function.
gives,
in the background even the builtin the way this check is implemented is by matching the type of a builtin_function_or_method with,
and since, |
https://docs.python.org/3/library/inspect.html#inspect.isfunction says this: """ Emphasis on the "Python function", as in, something written in Python using a >>> 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? |
but I want some way to return And similarly, some way to return Should the documentation for Should I create a PR to add these two sentences to the documentation? |
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. |
yes, I think |
I believe this issue can be closed. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: