diff options
author | Hakan Çelik <hakancelik96@outlook.com> | 2022-02-16 12:46:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-16 12:46:20 (GMT) |
commit | 562c13f5734d406b2283cfca673611f4b496fdc7 (patch) | |
tree | 143bae4befe45ab85669c278feb93202867ecb2c /Lib/inspect.py | |
parent | 3954fcb83fe471911ff01c0410a71d184d9984e7 (diff) | |
download | cpython-562c13f5734d406b2283cfca673611f4b496fdc7.zip cpython-562c13f5734d406b2283cfca673611f4b496fdc7.tar.gz cpython-562c13f5734d406b2283cfca673611f4b496fdc7.tar.bz2 |
bpo-29418: Implement inspect.ismethodwrapper and fix inspect.isroutine for cases where methodwrapper is given (GH-19261)
Automerge-Triggered-By: GH:isidentical
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r-- | Lib/inspect.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py index eb45f81..9c1283a 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -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: |