Skip to content

Commit 44f103f

Browse files
committed
Simplify branches
1 parent 2517a21 commit 44f103f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Lib/inspect.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,19 +1910,20 @@ def _signature_get_user_defined_method(cls, method_name, *, follow_wrapper_chain
19101910
meth = getattr(cls, method_name, None)
19111911
else:
19121912
meth = getattr_static(cls, method_name, None)
1913-
if meth is not None and follow_wrapper_chains:
1914-
unwrapped_meth = unwrap(meth)
1915-
if isinstance(meth, (classmethod, staticmethod)):
1916-
# Rewrap with the original type
1917-
meth = type(meth)(unwrapped_meth)
1918-
else:
1919-
meth = unwrapped_meth
1920-
if meth is None or isinstance(meth, _NonUserDefinedCallables):
1913+
if meth is None:
1914+
return None
1915+
1916+
if follow_wrapper_chains:
1917+
meth = unwrap(meth, stop=(lambda m: hasattr(m, "__signature__")
1918+
or isinstance(m, (classmethod, staticmethod))))
1919+
if isinstance(meth, _NonUserDefinedCallables):
19211920
# Once '__signature__' will be added to 'C'-level
19221921
# callables, this check won't be necessary
19231922
return None
19241923
if method_name != '__new__':
19251924
meth = _descriptor_get(meth, cls)
1925+
if follow_wrapper_chains:
1926+
meth = unwrap(meth, stop=lambda m: hasattr(m, "__signature__"))
19261927
return meth
19271928

19281929

0 commit comments

Comments
 (0)