[3.10] bpo-45848: Allow the parser to get error lines from encoded files (GH-29646) (GH-29661)

(cherry picked from commit fdcc46d955)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
This commit is contained in:
Łukasz Langa 2021-11-20 16:34:56 +01:00 committed by GitHub
parent bbe3c57c86
commit 904af3de2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 11 deletions

View file

@ -2352,6 +2352,19 @@ class SyntaxErrorTests(unittest.TestCase):
finally:
unlink(TESTFN)
# Check backwards tokenizer errors
source = '# -*- coding: ascii -*-\n\n(\n'
try:
with open(TESTFN, 'w', encoding='ascii') as testfile:
testfile.write(source)
rc, out, err = script_helper.assert_python_failure('-Wd', '-X', 'utf8', TESTFN)
err = err.decode('utf-8').splitlines()
self.assertEqual(err[-3], ' (')
self.assertEqual(err[-2], ' ^')
finally:
unlink(TESTFN)
def test_attributes_new_constructor(self):
args = ("bad.py", 1, 2, "abcdefg", 1, 100)
the_exception = SyntaxError("bad bad", args)