bpo-40593: Improve syntax errors for invalid characters in source code. (GH-20033)
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index ac5aa9a..e0bb5b5 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -583,7 +583,7 @@
])
# Different error message is raised for other whitespace characters.
- self.assertAllRaise(SyntaxError, 'invalid character in identifier',
+ self.assertAllRaise(SyntaxError, r"invalid non-printable character U\+00A0",
["f'''{\xa0}'''",
"\xa0",
])
diff --git a/Lib/test/test_source_encoding.py b/Lib/test/test_source_encoding.py
index a0bd741..5ca4346 100644
--- a/Lib/test/test_source_encoding.py
+++ b/Lib/test/test_source_encoding.py
@@ -57,6 +57,9 @@
# one byte in common with the UTF-16-LE BOM
self.assertRaises(SyntaxError, eval, b'\xff\x20')
+ # one byte in common with the UTF-8 BOM
+ self.assertRaises(SyntaxError, eval, b'\xef\x20')
+
# two bytes in common with the UTF-8 BOM
self.assertRaises(SyntaxError, eval, b'\xef\xbb\x20')
diff --git a/Lib/test/test_unicode_identifiers.py b/Lib/test/test_unicode_identifiers.py
index 07332c4..5b9ced5 100644
--- a/Lib/test/test_unicode_identifiers.py
+++ b/Lib/test/test_unicode_identifiers.py
@@ -20,9 +20,11 @@
def test_invalid(self):
try:
from test import badsyntax_3131
- except SyntaxError as s:
- self.assertEqual(str(s),
- "invalid character in identifier (badsyntax_3131.py, line 2)")
+ except SyntaxError as err:
+ self.assertEqual(str(err),
+ "invalid character '€' (U+20AC) (badsyntax_3131.py, line 2)")
+ self.assertEqual(err.lineno, 2)
+ self.assertEqual(err.offset, 1)
else:
self.fail("expected exception didn't occur")