mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
inspect.signature: Add support for 'functools.partialmethod' #20223
This commit is contained in:
parent
eedf1c1ebf
commit
da5fe4f2da
3 changed files with 95 additions and 40 deletions
|
|
@ -1877,6 +1877,33 @@ class TestSignatureObject(unittest.TestCase):
|
|||
ba = inspect.signature(_foo).bind(12, 14)
|
||||
self.assertEqual(_foo(*ba.args, **ba.kwargs), (12, 14, 13))
|
||||
|
||||
def test_signature_on_partialmethod(self):
|
||||
from functools import partialmethod
|
||||
|
||||
class Spam:
|
||||
def test():
|
||||
pass
|
||||
ham = partialmethod(test)
|
||||
|
||||
with self.assertRaisesRegex(ValueError, "has incorrect arguments"):
|
||||
inspect.signature(Spam.ham)
|
||||
|
||||
class Spam:
|
||||
def test(it, a, *, c) -> 'spam':
|
||||
pass
|
||||
ham = partialmethod(test, c=1)
|
||||
|
||||
self.assertEqual(self.signature(Spam.ham),
|
||||
((('it', ..., ..., 'positional_or_keyword'),
|
||||
('a', ..., ..., 'positional_or_keyword'),
|
||||
('c', 1, ..., 'keyword_only')),
|
||||
'spam'))
|
||||
|
||||
self.assertEqual(self.signature(Spam().ham),
|
||||
((('a', ..., ..., 'positional_or_keyword'),
|
||||
('c', 1, ..., 'keyword_only')),
|
||||
'spam'))
|
||||
|
||||
def test_signature_on_decorated(self):
|
||||
import functools
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue