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

(cherry picked from commit dbf2faf579)

Co-authored-by: Anton Ryzhov <anton@ryzhov.me>
This commit is contained in:
Miss Islington (bot) 2022-11-10 04:58:06 -08:00 committed by GitHub
parent 921f235367
commit 1de088ca95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View file

@ -2457,7 +2457,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).