diff options
| author | Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | 2021-08-13 09:55:15 -0500 |
|---|---|---|
| committer | Anthony Sottile <asottile@umich.edu> | 2021-08-15 18:26:27 -0400 |
| commit | 85c2be3b5291a73a2e737219c040019c14cf3eee (patch) | |
| tree | 820912a9f771d1aa1fe92fc0a56351dee7b78161 /src | |
| parent | d25cc10e382bcbd59cea47e0172f1e35cd3ee90d (diff) | |
| download | flake8-85c2be3b5291a73a2e737219c040019c14cf3eee.tar.gz | |
Handle new SyntaxError tuple on 3.10
Closes #1372
Diffstat (limited to 'src')
| -rw-r--r-- | src/flake8/checker.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py index 7130df3..8507495 100644 --- a/src/flake8/checker.py +++ b/src/flake8/checker.py @@ -443,14 +443,26 @@ class FileChecker: token = () row, column = (1, 0) - if column > 0 and token and isinstance(exception, SyntaxError): + if ( + column > 0 + and token + and isinstance(exception, SyntaxError) + and len(token) == 4 # Python 3.9 or earlier + ): # NOTE(sigmavirus24): SyntaxErrors report 1-indexed column # numbers. We need to decrement the column number by 1 at # least. column_offset = 1 row_offset = 0 - # See also: https://github.com/pycqa/flake8/issues/169 - physical_line = token[-1] + # See also: https://github.com/pycqa/flake8/issues/169, + # https://github.com/PyCQA/flake8/issues/1372 + # On Python 3.9 and earlier, token will be a 4-item tuple with the + # last item being the string. Starting with 3.10, they added to + # the tuple so now instead of it ending with the code that failed + # to parse, it ends with the end of the section of code that + # failed to parse. Luckily the absolute position in the tuple is + # stable across versions so we can use that here + physical_line = token[3] # NOTE(sigmavirus24): Not all "tokens" have a string as the last # argument. In this event, let's skip trying to find the correct |
