diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-04-29 16:30:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-29 16:30:48 (GMT) |
commit | 444ac0b7a64ff6b6caba9c2731bd33151ce18ad1 (patch) | |
tree | 572fd300a05e5a177da821c2afc371e3d2122f4a /Lib/test/test_inspect | |
parent | 51c70de998ead35674bf4b2b236e9ce8e89d17b4 (diff) | |
download | cpython-444ac0b7a64ff6b6caba9c2731bd33151ce18ad1.zip cpython-444ac0b7a64ff6b6caba9c2731bd33151ce18ad1.tar.gz cpython-444ac0b7a64ff6b6caba9c2731bd33151ce18ad1.tar.bz2 |
gh-118285: Fix signatures of operator.{attrgetter,itemgetter,methodcaller} instances (GH-118316)
* Allow to specify the signature of custom callable instances of extension
type by the __text_signature__ attribute.
* Specify signatures of operator.attrgetter, operator.itemgetter, and
operator.methodcaller instances.
Diffstat (limited to 'Lib/test/test_inspect')
-rw-r--r-- | Lib/test/test_inspect/test_inspect.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 169d1edb..6b57709 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -4090,6 +4090,28 @@ class TestSignatureObject(unittest.TestCase): ((('a', ..., ..., "positional_or_keyword"),), ...)) + def test_signature_on_callable_objects_with_text_signature_attr(self): + class C: + __text_signature__ = '(a, /, b, c=True)' + def __call__(self, *args, **kwargs): + pass + + self.assertEqual(self.signature(C), ((), ...)) + self.assertEqual(self.signature(C()), + ((('a', ..., ..., "positional_only"), + ('b', ..., ..., "positional_or_keyword"), + ('c', True, ..., "positional_or_keyword"), + ), + ...)) + + c = C() + c.__text_signature__ = '(x, y)' + self.assertEqual(self.signature(c), + ((('x', ..., ..., "positional_or_keyword"), + ('y', ..., ..., "positional_or_keyword"), + ), + ...)) + def test_signature_on_wrapper(self): class Wrapper: def __call__(self, b): |