Skip to content

Commit 387a055

Browse files
miss-islingtonYury Selivanov
andauthored
bpo-33009: Fix inspect.signature() for single-parameter partialmethods. (GH-6004)
(cherry picked from commit 8a38721) Co-authored-by: Yury Selivanov <yury@magic.io>
1 parent baa4507 commit 387a055

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lib/inspect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,8 @@ def _signature_from_callable(obj, *,
22512251
return sig
22522252
else:
22532253
sig_params = tuple(sig.parameters.values())
2254-
assert first_wrapped_param is not sig_params[0]
2254+
assert (not sig_params or
2255+
first_wrapped_param is not sig_params[0])
22552256
new_params = (first_wrapped_param,) + sig_params
22562257
return sig.replace(parameters=new_params)
22572258

Lib/test/test_inspect.py

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

2529+
class Spam:
2530+
def test(self: 'anno', x):
2531+
pass
2532+
2533+
g = partialmethod(test, 1)
2534+
2535+
self.assertEqual(self.signature(Spam.g),
2536+
((('self', ..., 'anno', 'positional_or_keyword'),),
2537+
...))
2538+
25292539
def test_signature_on_fake_partialmethod(self):
25302540
def foo(a): pass
25312541
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)