summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-04-07 14:54:35 +0000
committerAnthony Sottile <asottile@umich.edu>2019-04-07 14:54:35 +0000
commit98beabdcc50ee352a8a5eded1009b0914a3645b9 (patch)
tree0998b8b4629883be36285636d4de52b56f16c5c1
parent2b333fad1abe0bdb2e04132eabb0822e6ce63888 (diff)
parent38ab47702a1cfa451af2e74a95ed145a0f4b2d5a (diff)
downloadflake8-98beabdcc50ee352a8a5eded1009b0914a3645b9.tar.gz
Merge branch 'tokenize_error' into 'master'
Fix crash when file fails to tokenize but parses Closes #532 See merge request pycqa/flake8!314
-rw-r--r--src/flake8/checker.py3
-rw-r--r--tests/integration/test_main.py14
2 files changed, 15 insertions, 2 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index d3ce35e..4fb106e 100644
--- a/src/flake8/checker.py
+++ b/src/flake8/checker.py
@@ -597,6 +597,7 @@ class FileChecker(object):
"""Run checks against the file."""
try:
self.process_tokens()
+ self.run_ast_checks()
except exceptions.InvalidSyntax as exc:
self.report(
exc.error_code,
@@ -605,8 +606,6 @@ class FileChecker(object):
exc.error_message,
)
- self.run_ast_checks()
-
logical_lines = self.processor.statistics["logical lines"]
self.statistics["logical lines"] = logical_lines
return self.filename, self.results, self.statistics
diff --git a/tests/integration/test_main.py b/tests/integration/test_main.py
index ba4dd56..43cc168 100644
--- a/tests/integration/test_main.py
+++ b/tests/integration/test_main.py
@@ -85,3 +85,17 @@ Configured `per-file-ignores` setting:
incorrect/*
values/*
''' # 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 == ''