From bc92e7878f252fffbabfce6a0a453f99248b5f94 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 27 Jan 2026 20:37:35 -0800 Subject: [PATCH] [3.13] gh-144169: Fix three crashes in AST objects with non-str kwargs (GH-144178) (#144260) (cherry picked from commit 639c1ad4f1ef5c2409a62fa8ed16e6aa3a6f9ab8) Co-authored-by: Jelle Zijlstra Co-authored-by: Victor Stinner --- Lib/test/test_ast/test_ast.py | 21 +++++++++++++++++++ ...-01-23-06-43-21.gh-issue-144169.LFy9yi.rst | 2 ++ Parser/asdl_c.py | 4 ++-- Python/Python-ast.c | 4 ++-- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-01-23-06-43-21.gh-issue-144169.LFy9yi.rst diff --git a/Lib/test/test_ast/test_ast.py b/Lib/test/test_ast/test_ast.py index a8d111a4afe7..38dfc533c7eb 100644 --- a/Lib/test/test_ast/test_ast.py +++ b/Lib/test/test_ast/test_ast.py @@ -3141,6 +3141,27 @@ class ASTConstructorTests(unittest.TestCase): self.assertIs(obj.a, None) self.assertEqual(obj.b, []) + def test_non_str_kwarg(self): + warn_msg = "got an unexpected keyword argument tp_name, key); res = -1; goto cleanup; @@ -962,7 +962,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) else if (contains == 0) { if (PyErr_WarnFormat( PyExc_DeprecationWarning, 1, - "%.400s.__init__ got an unexpected keyword argument '%U'. " + "%.400s.__init__ got an unexpected keyword argument %R. " "Support for arbitrary keyword arguments is deprecated " "and will be removed in Python 3.15.", Py_TYPE(self)->tp_name, key diff --git a/Python/Python-ast.c b/Python/Python-ast.c index a71262c7f84a..1871ca3fb3dd 100644 --- a/Python/Python-ast.c +++ b/Python/Python-ast.c @@ -5136,7 +5136,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) } if (p == 0) { PyErr_Format(PyExc_TypeError, - "%.400s got multiple values for argument '%U'", + "%.400s got multiple values for argument %R", Py_TYPE(self)->tp_name, key); res = -1; goto cleanup; @@ -5159,7 +5159,7 @@ ast_type_init(PyObject *self, PyObject *args, PyObject *kw) else if (contains == 0) { if (PyErr_WarnFormat( PyExc_DeprecationWarning, 1, - "%.400s.__init__ got an unexpected keyword argument '%U'. " + "%.400s.__init__ got an unexpected keyword argument %R. " "Support for arbitrary keyword arguments is deprecated " "and will be removed in Python 3.15.", Py_TYPE(self)->tp_name, key -- 2.47.3