mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
[3.12] gh-111380: Show SyntaxWarnings only once when parsing if invalid syntax is encouintered (GH-111381) (#111382)
gh-111380: Show SyntaxWarnings only once when parsing if invalid syntax is encouintered (GH-111381)
(cherry picked from commit 3d2f1f0b83
)
Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
parent
a70b2cd2d2
commit
307ca78d7f
3 changed files with 19 additions and 0 deletions
|
@ -131,6 +131,18 @@ class TestLiterals(unittest.TestCase):
|
|||
self.assertEqual(exc.lineno, 1)
|
||||
self.assertEqual(exc.offset, 1)
|
||||
|
||||
# Check that the warning is raised ony once if there are syntax errors
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter('always', category=SyntaxWarning)
|
||||
with self.assertRaises(SyntaxError) as cm:
|
||||
eval("'\\e' $")
|
||||
exc = cm.exception
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertEqual(w[0].category, SyntaxWarning)
|
||||
self.assertRegex(str(w[0].message), 'invalid escape sequence')
|
||||
self.assertEqual(w[0].filename, '<string>')
|
||||
|
||||
def test_eval_str_invalid_octal_escape(self):
|
||||
for i in range(0o400, 0o1000):
|
||||
with self.assertWarns(SyntaxWarning):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue