mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 14:24:17 +00:00
Merge branch 'tokenize_error' into 'master'
Fix crash when file fails to tokenize but parses Closes #532 See merge request pycqa/flake8!314
This commit is contained in:
commit
98beabdcc5
2 changed files with 15 additions and 2 deletions
|
|
@ -597,6 +597,7 @@ class FileChecker(object):
|
||||||
"""Run checks against the file."""
|
"""Run checks against the file."""
|
||||||
try:
|
try:
|
||||||
self.process_tokens()
|
self.process_tokens()
|
||||||
|
self.run_ast_checks()
|
||||||
except exceptions.InvalidSyntax as exc:
|
except exceptions.InvalidSyntax as exc:
|
||||||
self.report(
|
self.report(
|
||||||
exc.error_code,
|
exc.error_code,
|
||||||
|
|
@ -605,8 +606,6 @@ class FileChecker(object):
|
||||||
exc.error_message,
|
exc.error_message,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.run_ast_checks()
|
|
||||||
|
|
||||||
logical_lines = self.processor.statistics["logical lines"]
|
logical_lines = self.processor.statistics["logical lines"]
|
||||||
self.statistics["logical lines"] = logical_lines
|
self.statistics["logical lines"] = logical_lines
|
||||||
return self.filename, self.results, self.statistics
|
return self.filename, self.results, self.statistics
|
||||||
|
|
|
||||||
|
|
@ -85,3 +85,17 @@ Configured `per-file-ignores` setting:
|
||||||
incorrect/*
|
incorrect/*
|
||||||
values/*
|
values/*
|
||||||
''' # noqa: E501
|
''' # noqa: E501
|
||||||
|
|
||||||
|
|
||||||
|
def test_tokenization_error_but_not_syntax_error(tmpdir, capsys):
|
||||||
|
"""Test that flake8 does not crash on tokenization errors."""
|
||||||
|
with tmpdir.as_cwd():
|
||||||
|
# this is a crash in the tokenizer, but not in the ast
|
||||||
|
tmpdir.join('t.py').write("b'foo' \\\n")
|
||||||
|
|
||||||
|
app = application.Application()
|
||||||
|
app.run(['t.py'])
|
||||||
|
|
||||||
|
out, err = capsys.readouterr()
|
||||||
|
assert out == 't.py:1:1: E902 TokenError: EOF in multi-line statement\n'
|
||||||
|
assert err == ''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue