gh-99891: Fix infinite recursion in the tokenizer when showing warnings (GH-99893)

Automerge-Triggered-By: GH:pablogsal
This commit is contained in:
Pablo Galindo Salgado 2022-11-30 11:36:06 +00:00 committed by GitHub
parent 19c38801ba
commit 417206a05c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 0 deletions

View file

@ -160,6 +160,18 @@ class MiscSourceEncodingTest(unittest.TestCase):
finally:
os.unlink(TESTFN)
def test_tokenizer_fstring_warning_in_first_line(self):
source = "0b1and 2"
with open(TESTFN, "w") as fd:
fd.write("{}".format(source))
try:
retcode, stdout, stderr = script_helper.assert_python_ok(TESTFN)
self.assertIn(b"SyntaxWarning: invalid binary litera", stderr)
self.assertEqual(stderr.count(source.encode()), 1)
finally:
os.unlink(TESTFN)
class AbstractSourceEncodingTest:
def test_default_coding(self):