From 5b7dab710fc623d12de62c2fe3389c1c846826f8 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 25 Jan 2026 17:28:58 -0800 Subject: [PATCH 1/2] [3.13] gh-144169: Fix three crashes in AST objects with non-str kwargs (GH-144178) (cherry picked from commit 639c1ad4f1ef5c2409a62fa8ed16e6aa3a6f9ab8) Co-authored-by: Jelle Zijlstra Co-authored-by: Victor Stinner --- Lib/test/test_ast/test_ast.py | 28 +++++++++++++++++++ ...-01-23-06-43-21.gh-issue-144169.LFy9yi.rst | 2 ++ Parser/asdl_c.py | 4 +-- Python/Python-ast.c | 4 +-- 4 files changed, 34 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 a8d111a4afe797..153fe8926caddf 100644 --- a/Lib/test/test_ast/test_ast.py +++ b/Lib/test/test_ast/test_ast.py @@ -1141,6 +1141,13 @@ def test_copy_with_parents(self): self.assertEqual(to_tuple(child.parent), to_tuple(node)) + def test_replace_non_str_kwarg(self): + node = ast.Name(id="x") + errmsg = "got an unexpected keyword argument tp_name, key); res = -1; goto cleanup; @@ -962,7 +962,7 @@ def visitModule(self, mod): 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 a71262c7f84abe..1871ca3fb3dd65 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 From 8d33433493430662acf42e48a74513c4a4124c65 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 27 Jan 2026 18:57:17 -0800 Subject: [PATCH 2/2] remove nonapplicable test --- Lib/test/test_ast/test_ast.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Lib/test/test_ast/test_ast.py b/Lib/test/test_ast/test_ast.py index 153fe8926caddf..38dfc533c7eb2c 100644 --- a/Lib/test/test_ast/test_ast.py +++ b/Lib/test/test_ast/test_ast.py @@ -1141,13 +1141,6 @@ def test_copy_with_parents(self): self.assertEqual(to_tuple(child.parent), to_tuple(node)) - def test_replace_non_str_kwarg(self): - node = ast.Name(id="x") - errmsg = "got an unexpected keyword argument