[3.12] gh-88943: Improve syntax error for non-ASCII character that follows a numerical literal (GH-109081) (#109090)

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.
(cherry picked from commit b2729e93e9)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-10-02 07:54:16 -07:00 committed by GitHub
parent a4f186ad49
commit 9207c870be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View file

@ -236,6 +236,10 @@ class TokenTests(unittest.TestCase):
check(f"[{num}for x in ()]")
check(f"{num}spam", error=True)
# gh-88943: Invalid non-ASCII character following a numerical literal.
with self.assertRaisesRegex(SyntaxError, r"invalid character '' \(U\+2044\)"):
compile(f"{num}7", "<testcase>", "eval")
with self.assertWarnsRegex(SyntaxWarning, r'invalid \w+ literal'):
compile(f"{num}is x", "<testcase>", "eval")
with warnings.catch_warnings():