Skip to content

Commit dffd57d

Browse files
Change error type when constants are used as an identifier
1 parent 171133a commit dffd57d

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

Lib/test/test_ast/test_ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ def test_constant_as_unicode_name(self):
954954
("None", b"N\xc2\xbane"),
955955
]
956956
for constant in constants:
957-
with self.assertRaisesRegex(ValueError,
957+
with self.assertRaisesRegex(SyntaxError,
958958
f"identifier field can't represent '{constant[0]}' constant"):
959959
ast.parse(constant[1], mode="eval")
960960

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Raise :exc:`SyntaxError` when constants ``True``, ``False`` or ``None`` are
2+
used as an identifier after NFKC normalization.

Parser/pegen.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ _PyPegen_new_identifier(Parser *p, const char *n)
539539
};
540540
for (int i = 0; forbidden[i] != NULL; i++) {
541541
if (_PyUnicode_EqualToASCIIString(id, forbidden[i])) {
542-
PyErr_Format(PyExc_ValueError,
542+
RAISE_SYNTAX_ERROR(
543543
"identifier field can't represent '%s' constant",
544544
forbidden[i]);
545545
Py_DECREF(id);

0 commit comments

Comments
 (0)