bpo-33009: Fix inspect.signature() for single-parameter partialmethods. (GH-6004)
This commit is contained in:
parent
5d92647102
commit
8a387219bd
|
@ -2254,7 +2254,8 @@ def _signature_from_callable(obj, *,
|
|||
return sig
|
||||
else:
|
||||
sig_params = tuple(sig.parameters.values())
|
||||
assert first_wrapped_param is not sig_params[0]
|
||||
assert (not sig_params or
|
||||
first_wrapped_param is not sig_params[0])
|
||||
new_params = (first_wrapped_param,) + sig_params
|
||||
return sig.replace(parameters=new_params)
|
||||
|
||||
|
|
|
@ -2580,6 +2580,16 @@ class TestSignatureObject(unittest.TestCase):
|
|||
('c', 1, ..., 'keyword_only')),
|
||||
'spam'))
|
||||
|
||||
class Spam:
|
||||
def test(self: 'anno', x):
|
||||
pass
|
||||
|
||||
g = partialmethod(test, 1)
|
||||
|
||||
self.assertEqual(self.signature(Spam.g),
|
||||
((('self', ..., 'anno', 'positional_or_keyword'),),
|
||||
...))
|
||||
|
||||
def test_signature_on_fake_partialmethod(self):
|
||||
def foo(a): pass
|
||||
foo._partialmethod = 'spam'
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix inspect.signature() for single-parameter partialmethods.
|
Loading…
Reference in New Issue