[3.13] gh-87106: Fix inspect.signature.bind() handling of positional-only arguments with **kwargs (GH-103404) by miss-islington · Pull Request #118985 · 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
28 changes: 16 additions & 12 deletions Lib/inspect.py
25 changes: 20 additions & 5 deletions Lib/test/test_inspect/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -5089,15 +5089,30 @@ def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs):
self.assertEqual(self.call(test, 1, 2, foo=4, bar=5),
(1, 2, 3, 4, 5, {}))

with self.assertRaisesRegex(TypeError, "but was passed as a keyword"):
self.call(test, 1, 2, foo=4, bar=5, c_po=10)
self.assertEqual(self.call(test, 1, 2, foo=4, bar=5, c_po=10),
(1, 2, 3, 4, 5, {'c_po': 10}))

with self.assertRaisesRegex(TypeError, "parameter is positional only"):
self.call(test, 1, 2, c_po=4)
self.assertEqual(self.call(test, 1, 2, 30, c_po=31, foo=4, bar=5),
(1, 2, 30, 4, 5, {'c_po': 31}))

with self.assertRaisesRegex(TypeError, "parameter is positional only"):
self.assertEqual(self.call(test, 1, 2, 30, foo=4, bar=5, c_po=31),
(1, 2, 30, 4, 5, {'c_po': 31}))

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"):
self.call(test, a_po=1, b_po=2)

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

with self.assertRaisesRegex(
TypeError,
"positional-only arguments passed as keyword arguments: 'c_po, d_po'",
):
self.call(without_var_kwargs, c_po=33, d_po=44)

def test_signature_bind_with_self_arg(self):
# Issue #17071: one of the parameters is named "self
def test(a, self, b):
Expand Down