Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dae62d4

Browse files
[3.11] gh-88943: Improve syntax error for non-ASCII character that follows a numerical literal (GH-109081) (GH-109091)
It now points on the invalid non-ASCII character, not on the valid numerical literal. (cherry picked from commit b2729e9)
1 parent d9d64a4 commit dae62d4

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
@@ -238,6 +238,10 @@ def check(test, error=False):
238238
check(f"[{num}for x in ()]")
239239
check(f"{num}spam", error=True)
240240

241+
# gh-88943: Invalid non-ASCII character following a numerical literal.
242+
with self.assertRaisesRegex(SyntaxError, r"invalid character '⁄' \(U\+2044\)"):
243+
compile(f"{num}⁄7", "<testcase>", "eval")
244+
241245
with warnings.catch_warnings():
242246
warnings.filterwarnings('ignore', '"is" with a literal',
243247
SyntaxWarning)
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
@@ -1303,7 +1303,7 @@ verify_end_of_number(struct tok_state *tok, int c, const char *kind)
13031303
tok_nextc(tok);
13041304
}
13051305
else /* In future releases, only error will remain. */
1306-
if (is_potential_identifier_char(c)) {
1306+
if (c < 128 && is_potential_identifier_char(c)) {
13071307
tok_backup(tok, c);
13081308
syntaxerror(tok, "invalid %s literal", kind);
13091309
return 0;

0 commit comments

Comments
 (0)