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

@ -2960,8 +2960,6 @@ class TestSignatureObject(unittest.TestCase):
self.assertEqual(str(inspect.signature(foo)), '(a)')
def test_signature_on_decorated(self):
import functools
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs) -> int:
@ -2973,6 +2971,8 @@ class TestSignatureObject(unittest.TestCase):
def bar(self, a, b):
pass
bar = decorator(Foo().bar)
self.assertEqual(self.signature(Foo.bar),
((('self', ..., ..., "positional_or_keyword"),
('a', ..., ..., "positional_or_keyword"),
@ -2991,6 +2991,11 @@ class TestSignatureObject(unittest.TestCase):
# from "func" to "wrapper", hence no
# return_annotation
self.assertEqual(self.signature(bar),
((('a', ..., ..., "positional_or_keyword"),
('b', ..., ..., "positional_or_keyword")),
...))
# Test that we handle method wrappers correctly
def decorator(func):
@functools.wraps(func)