diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-10-16 11:42:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-16 11:42:44 (GMT) |
commit | c2192a2bee17e2ce80c5af34410ccd0c8b6e08aa (patch) | |
tree | e7415e1d5892ed5401ccc73dc4924d24a2aac4d3 /Lib | |
parent | db656aebc659e5023d004053db44031176bbe9f5 (diff) | |
download | cpython-c2192a2bee17e2ce80c5af34410ccd0c8b6e08aa.zip cpython-c2192a2bee17e2ce80c5af34410ccd0c8b6e08aa.tar.gz cpython-c2192a2bee17e2ce80c5af34410ccd0c8b6e08aa.tar.bz2 |
gh-110864: Fix _PyArg_UnpackKeywordsWithVararg overwriting vararg with NULL (#110868)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_clinic.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 627a329..0499828 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -3154,6 +3154,10 @@ class ClinicFunctionalTest(unittest.TestCase): self.assertEqual(ac_tester.posonly_vararg(1, 2), (1, 2, ())) self.assertEqual(ac_tester.posonly_vararg(1, b=2), (1, 2, ())) self.assertEqual(ac_tester.posonly_vararg(1, 2, 3, 4), (1, 2, (3, 4))) + with self.assertRaises(TypeError): + ac_tester.posonly_vararg(b=4) + with self.assertRaises(TypeError): + ac_tester.posonly_vararg(1, 2, 3, b=4) def test_vararg_and_posonly(self): with self.assertRaises(TypeError): @@ -3204,6 +3208,37 @@ class ClinicFunctionalTest(unittest.TestCase): with self.assertRaisesRegex(TypeError, err): ac_tester.gh_99240_double_free('a', '\0b') + def test_null_or_tuple_for_varargs(self): + # All of these should not crash: + valid_args_for_test = [ + (('a',), {}, + ('a', (), False)), + (('a', 1, 2, 3), {'covariant': True}, + ('a', (1, 2, 3), True)), + ((), {'name': 'a'}, + ('a', (), False)), + ((), {'name': 'a', 'covariant': True}, + ('a', (), True)), + ((), {'covariant': True, 'name': 'a'}, + ('a', (), True)), + ] + for args, kwargs, expected in valid_args_for_test: + with self.subTest(args=args, kwargs=kwargs): + self.assertEqual( + ac_tester.null_or_tuple_for_varargs(*args, **kwargs), + expected, + ) + + def test_null_or_tuple_for_varargs_error(self): + with self.assertRaises(TypeError): + ac_tester.null_or_tuple_for_varargs(covariant=True) + with self.assertRaises(TypeError): + ac_tester.null_or_tuple_for_varargs(1, name='a') + with self.assertRaises(TypeError): + ac_tester.null_or_tuple_for_varargs(1, 2, 3, name='a', covariant=True) + with self.assertRaises(TypeError): + ac_tester.null_or_tuple_for_varargs(1, 2, 3, covariant=True, name='a') + def test_cloned_func_exception_message(self): incorrect_arg = -1 # f1() and f2() accept a single str with self.assertRaisesRegex(TypeError, "clone_f1"): |