Skip to content

Commit b2729e9

Browse files
gh-88943: Improve syntax error for non-ASCII character that follows a numerical literal (GH-109081)
It now points on the invalid non-ASCII character, not on the valid numerical literal.
1 parent ac31f71 commit b2729e9

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

Lib/test/test_grammar.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ def check(test, error=False):
236236
check(f"[{num}for x in ()]")
237237
check(f"{num}spam", error=True)
238238

239+
# gh-88943: Invalid non-ASCII character following a numerical literal.
240+
with self.assertRaisesRegex(SyntaxError, r"invalid character '⁄' \(U\+2044\)"):
241+
compile(f"{num}⁄7", "<testcase>", "eval")
242+
239243
with self.assertWarnsRegex(SyntaxWarning, r'invalid \w+ literal'):
240244
compile(f"{num}is x", "<testcase>", "eval")
241245
with warnings.catch_warnings():
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Improve syntax error for non-ASCII character that follows a numerical
2+
literal. It now points on the invalid non-ASCII character, not on the valid
3+
numerical literal.

Parser/tokenizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ verify_end_of_number(struct tok_state *tok, int c, const char *kind) {
16421642
tok_nextc(tok);
16431643
}
16441644
else /* In future releases, only error will remain. */
1645-
if (is_potential_identifier_char(c)) {
1645+
if (c < 128 && is_potential_identifier_char(c)) {
16461646
tok_backup(tok, c);
16471647
syntaxerror(tok, "invalid %s literal", kind);
16481648
return 0;

0 commit comments

Comments
 (0)