bpo-36542: Allow to overwrite the signature for Python functions. (GH-12705)

This commit is contained in:
Serhiy Storchaka 2019-05-06 22:40:27 +03:00 committed by GitHub
parent 96aeaec647
commit d53cf99dca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 40 additions and 3 deletions

View file

@ -3782,6 +3782,17 @@ class TestSignatureDefinitions(unittest.TestCase):
with self.subTest(builtin=name):
self.assertIsNone(obj.__text_signature__)
def test_python_function_override_signature(self):
def func(*args, **kwargs):
pass
func.__text_signature__ = '($self, a, b=1, *args, c, d=2, **kwargs)'
sig = inspect.signature(func)
self.assertIsNotNone(sig)
self.assertEqual(str(sig), '(self, /, a, b=1, *args, c, d=2, **kwargs)')
func.__text_signature__ = '($self, a, b=1, /, *args, c, d=2, **kwargs)'
sig = inspect.signature(func)
self.assertEqual(str(sig), '(self, a, b=1, /, *args, c, d=2, **kwargs)')
class NTimesUnwrappable:
def __init__(self, n):