Skip to content

Commit 112f799

Browse files
miss-islington1st1
andauthored
bpo-33009: Fix inspect.signature() for single-parameter partialmethods. (GH-6004)
(cherry picked from commit 8a38721) Co-authored-by: Yury Selivanov <[email protected]>
1 parent 5a0c398 commit 112f799

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

‎Lib/inspect.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,8 @@ def _signature_from_callable(obj, *,
22542254
return sig
22552255
else:
22562256
sig_params = tuple(sig.parameters.values())
2257-
assert first_wrapped_param is not sig_params[0]
2257+
assert (not sig_params or
2258+
first_wrapped_param is not sig_params[0])
22582259
new_params = (first_wrapped_param,) + sig_params
22592260
return sig.replace(parameters=new_params)
22602261

‎Lib/test/test_inspect.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,6 +2580,16 @@ def test(it, a, *, c) -> 'spam':
25802580
('c', 1, ..., 'keyword_only')),
25812581
'spam'))
25822582

2583+
class Spam:
2584+
def test(self: 'anno', x):
2585+
pass
2586+
2587+
g = partialmethod(test, 1)
2588+
2589+
self.assertEqual(self.signature(Spam.g),
2590+
((('self', ..., 'anno', 'positional_or_keyword'),),
2591+
...))
2592+
25832593
def test_signature_on_fake_partialmethod(self):
25842594
def foo(a): pass
25852595
foo._partialmethod = 'spam'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix inspect.signature() for single-parameter partialmethods.

0 commit comments

Comments
 (0)