gh-74044: inspect.signature for wrappers around decorated bound methods (GH-736)

This commit is contained in:
Anton Ryzhov 2022-11-10 13:32:01 +01:00 committed by GitHub
parent 9d69284169
commit dbf2faf579
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View file

@ -2442,7 +2442,10 @@ def _signature_from_callable(obj, *,
# Was this function wrapped by a decorator?
if follow_wrapper_chains:
obj = unwrap(obj, stop=(lambda f: hasattr(f, "__signature__")))
# Unwrap until we find an explicit signature or a MethodType (which will be
# handled explicitly below).
obj = unwrap(obj, stop=(lambda f: hasattr(f, "__signature__")
or isinstance(f, types.MethodType)))
if isinstance(obj, types.MethodType):
# If the unwrapped object is a *method*, we might want to
# skip its first parameter (self).