mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 15:24:18 +00:00
Merge branch 'bug/205' into 'master'
Handle SyntaxErrors when tokenizing a file *Description of changes* This handles the SyntaxErrors raised by tokenize.generate_tokens. *Related to:* #205 See merge request !114
This commit is contained in:
commit
a8029ba2d5
2 changed files with 5 additions and 8 deletions
|
|
@ -38,7 +38,10 @@ class InvalidSyntax(Flake8Exception):
|
||||||
"""Initialize our InvalidSyntax exception."""
|
"""Initialize our InvalidSyntax exception."""
|
||||||
exception = kwargs.pop('exception', None)
|
exception = kwargs.pop('exception', None)
|
||||||
self.original_exception = exception
|
self.original_exception = exception
|
||||||
self.error_message = str(exception)
|
self.error_message = '{0}: {1}'.format(
|
||||||
|
exception.__class__.__name__,
|
||||||
|
exception.args[0],
|
||||||
|
)
|
||||||
self.error_code = 'E902'
|
self.error_code = 'E902'
|
||||||
self.line_number = 1
|
self.line_number = 1
|
||||||
self.column_number = 0
|
self.column_number = 0
|
||||||
|
|
|
||||||
|
|
@ -240,13 +240,7 @@ class FileProcessor(object):
|
||||||
break
|
break
|
||||||
self.tokens.append(token)
|
self.tokens.append(token)
|
||||||
yield token
|
yield token
|
||||||
# NOTE(sigmavirus24): pycodestyle was catching both a SyntaxError
|
except (tokenize.TokenError, SyntaxError) as exc:
|
||||||
# and a tokenize.TokenError. In looking a the source on Python 2 and
|
|
||||||
# Python 3, the SyntaxError should never arise from generate_tokens.
|
|
||||||
# If we were using tokenize.tokenize, we would have to catch that. Of
|
|
||||||
# course, I'm going to be unsurprised to be proven wrong at a later
|
|
||||||
# date.
|
|
||||||
except tokenize.TokenError as exc:
|
|
||||||
raise exceptions.InvalidSyntax(exception=exc)
|
raise exceptions.InvalidSyntax(exception=exc)
|
||||||
|
|
||||||
def line_for(self, line_number):
|
def line_for(self, line_number):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue