[3.12] gh-130164: Fix inspect.Signature.bind() handling of positional-only args without defaults (GH-130192) by miss-islington · Pull Request #132259 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Lib/inspect.py
8 changes: 6 additions & 2 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -4701,7 +4701,11 @@ class TestSignatureBind(unittest.TestCase):
def call(func, *args, **kwargs):
sig = inspect.signature(func)
ba = sig.bind(*args, **kwargs)
return func(*ba.args, **ba.kwargs)
# Prevent unexpected success of assertRaises(TypeError, ...)
try:
return func(*ba.args, **ba.kwargs)
except TypeError as e:
raise AssertionError from e

def test_signature_bind_empty(self):
def test():
Expand Down Expand Up @@ -4901,7 +4905,7 @@ def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs):
self.assertEqual(self.call(test, 1, 2, c_po=4),
(1, 2, 3, 42, 50, {'c_po': 4}))

with self.assertRaisesRegex(TypeError, "missing 2 required positional arguments"):
with self.assertRaisesRegex(TypeError, "missing a required positional-only argument: 'a_po'"):
self.call(test, a_po=1, b_po=2)

def without_var_kwargs(c_po=3, d_po=4, /):
Expand Down