diff --git a/Lib/test/test_ast/test_ast.py b/Lib/test/test_ast/test_ast.py index f29f98beb2d048..459bc3ff0c06d0 100644 --- a/Lib/test/test_ast/test_ast.py +++ b/Lib/test/test_ast/test_ast.py @@ -954,7 +954,7 @@ def test_constant_as_unicode_name(self): ("None", b"N\xc2\xbane"), ] for constant in constants: - with self.assertRaisesRegex(ValueError, + with self.assertRaisesRegex(SyntaxError, f"identifier field can't represent '{constant[0]}' constant"): ast.parse(constant[1], mode="eval") diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-03-09-17-19-04.gh-issue-145675.9YPpYi.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-03-09-17-19-04.gh-issue-145675.9YPpYi.rst new file mode 100644 index 00000000000000..0774246638e267 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-03-09-17-19-04.gh-issue-145675.9YPpYi.rst @@ -0,0 +1,2 @@ +Raise :exc:`SyntaxError` when constants ``True``, ``False`` or ``None`` are +used as an identifier after NFKC normalization. diff --git a/Parser/pegen.c b/Parser/pegen.c index 7ecc55eee13775..fd7360e8350f91 100644 --- a/Parser/pegen.c +++ b/Parser/pegen.c @@ -539,7 +539,7 @@ _PyPegen_new_identifier(Parser *p, const char *n) }; for (int i = 0; forbidden[i] != NULL; i++) { if (_PyUnicode_EqualToASCIIString(id, forbidden[i])) { - PyErr_Format(PyExc_ValueError, + RAISE_SYNTAX_ERROR( "identifier field can't represent '%s' constant", forbidden[i]); Py_DECREF(id);