mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-29418: Implement inspect.ismethodwrapper and fix inspect.isroutine for cases where methodwrapper is given (GH-19261)
Automerge-Triggered-By: GH:isidentical
This commit is contained in:
parent
3954fcb83f
commit
562c13f573
4 changed files with 63 additions and 12 deletions
|
@ -121,6 +121,7 @@ __all__ = [
|
|||
"ismemberdescriptor",
|
||||
"ismethod",
|
||||
"ismethoddescriptor",
|
||||
"ismethodwrapper",
|
||||
"ismodule",
|
||||
"isroutine",
|
||||
"istraceback",
|
||||
|
@ -509,12 +510,17 @@ def isbuiltin(object):
|
|||
__self__ instance to which a method is bound, or None"""
|
||||
return isinstance(object, types.BuiltinFunctionType)
|
||||
|
||||
def ismethodwrapper(object):
|
||||
"""Return true if the object is a method wrapper."""
|
||||
return isinstance(object, types.MethodWrapperType)
|
||||
|
||||
def isroutine(object):
|
||||
"""Return true if the object is any kind of function or method."""
|
||||
return (isbuiltin(object)
|
||||
or isfunction(object)
|
||||
or ismethod(object)
|
||||
or ismethoddescriptor(object))
|
||||
or ismethoddescriptor(object)
|
||||
or ismethodwrapper(object))
|
||||
|
||||
def isabstract(object):
|
||||
"""Return true if the object is an abstract base class (ABC)."""
|
||||
|
@ -1887,13 +1893,9 @@ def getcoroutinelocals(coroutine):
|
|||
###############################################################################
|
||||
|
||||
|
||||
_WrapperDescriptor = type(type.__call__)
|
||||
_MethodWrapper = type(all.__call__)
|
||||
_ClassMethodWrapper = type(int.__dict__['from_bytes'])
|
||||
|
||||
_NonUserDefinedCallables = (_WrapperDescriptor,
|
||||
_MethodWrapper,
|
||||
_ClassMethodWrapper,
|
||||
_NonUserDefinedCallables = (types.WrapperDescriptorType,
|
||||
types.MethodWrapperType,
|
||||
types.ClassMethodDescriptorType,
|
||||
types.BuiltinFunctionType)
|
||||
|
||||
|
||||
|
@ -2533,7 +2535,7 @@ def _signature_from_callable(obj, *,
|
|||
elif not isinstance(obj, _NonUserDefinedCallables):
|
||||
# An object with __call__
|
||||
# We also check that the 'obj' is not an instance of
|
||||
# _WrapperDescriptor or _MethodWrapper to avoid
|
||||
# types.WrapperDescriptorType or types.MethodWrapperType to avoid
|
||||
# infinite recursion (and even potential segfault)
|
||||
call = _signature_get_user_defined_method(type(obj), '__call__')
|
||||
if call is not None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue