Fix wrong location reported for syntax errors

See #740
This commit is contained in:
Klaas van Schelven 2021-04-08 15:55:51 +02:00
parent 9815f49cc4
commit 255122c2a6
2 changed files with 9 additions and 3 deletions

View file

@ -580,8 +580,8 @@ class FileChecker:
"""Run checks against the file."""
assert self.processor is not None
try:
self.process_tokens()
self.run_ast_checks()
self.process_tokens()
except exceptions.InvalidSyntax as exc:
self.report(
exc.error_code,

View file

@ -183,7 +183,10 @@ def test_tokenization_error_but_not_syntax_error(tmpdir, capsys):
_call_main(['t.py'], retv=1)
out, err = capsys.readouterr()
assert out == 't.py:1:1: E902 TokenError: EOF in multi-line statement\n'
assert out == '''\
t.py:1:1: E902 TokenError: EOF in multi-line statement
t.py:1:8: E999 SyntaxError: unexpected EOF while parsing
'''
assert err == ''
@ -194,7 +197,10 @@ def test_tokenization_error_is_a_syntax_error(tmpdir, capsys):
_call_main(['t.py'], retv=1)
out, err = capsys.readouterr()
assert out == 't.py:1:1: E902 IndentationError: unindent does not match any outer indentation level\n' # noqa: E501
assert out == '''\
t.py:1:1: E902 IndentationError: unindent does not match any outer indentation level
t.py:3:5: E999 IndentationError: unindent does not match any outer indentation level
''' # noqa: E501
assert err == ''