diff options
author | Jacob Walls <jacobtylerwalls@gmail.com> | 2024-05-13 07:56:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-13 07:56:09 (GMT) |
commit | 9c1520244151f36e010c1b04bedf14747a28517d (patch) | |
tree | e81108b9b1400f06881b638bf221f85dbad7b119 /Lib/test/test_inspect | |
parent | a705c1e44984afda2f7fb6d0816345d0843a6635 (diff) | |
download | cpython-9c1520244151f36e010c1b04bedf14747a28517d.zip cpython-9c1520244151f36e010c1b04bedf14747a28517d.tar.gz cpython-9c1520244151f36e010c1b04bedf14747a28517d.tar.bz2 |
gh-87106: Fix inspect.signature.bind() handling of positional-only arguments with **kwargs (GH-103404)
Diffstat (limited to 'Lib/test/test_inspect')
-rw-r--r-- | Lib/test/test_inspect/test_inspect.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 8bd1303..011d42f 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -5089,15 +5089,30 @@ class TestSignatureBind(unittest.TestCase): 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): |