summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2017-01-27 15:22:49 -0600
committerIan Cordasco <graffatcolmingov@gmail.com>2017-01-27 15:22:49 -0600
commit7ca05a9ca188c9487b0b3067ca100ea105dca205 (patch)
tree8a076d8a7a90bea2f0deecb054c75a96aa950097 /src
parent9145674cf27b145eb5b708d506b03fb385b1d239 (diff)
downloadflake8-7ca05a9ca188c9487b0b3067ca100ea105dca205.tar.gz
Avoid calling rstrip on None
When we receive a SyntaxError, it is not guaranteed to have a token that includes the physical line causing the issue. If it does not, we now will avoid trying to determine the number of rows and columns that are actually there and default to what the error tells us. Closes #279
Diffstat (limited to 'src')
-rw-r--r--src/flake8/checker.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index 32d438c..a9d7cad 100644
--- a/src/flake8/checker.py
+++ b/src/flake8/checker.py
@@ -443,19 +443,24 @@ class FileChecker(object):
# numbers. We need to decrement the column number by 1 at
# least.
column_offset = 1
+ row_offset = 0
# See also: https://gitlab.com/pycqa/flake8/issues/237
physical_line = token[-1]
- # NOTE(sigmavirus24): SyntaxErrors also don't exactly have a
- # "physical" line so much as what was accumulated by the point
- # tokenizing failed.
- # See also: https://gitlab.com/pycqa/flake8/issues/237
- lines = physical_line.rstrip('\n').split('\n')
- row_offset = len(lines) - 1
- logical_line = lines[0]
- logical_line_length = len(logical_line)
- if column > logical_line_length:
- column = logical_line_length
+ # NOTE(sigmavirus24): Not all "tokens" have a string as the last
+ # argument. In this event, let's skip trying to find the correct
+ # column and row values.
+ if physical_line is not None:
+ # NOTE(sigmavirus24): SyntaxErrors also don't exactly have a
+ # "physical" line so much as what was accumulated by the point
+ # tokenizing failed.
+ # See also: https://gitlab.com/pycqa/flake8/issues/237
+ lines = physical_line.rstrip('\n').split('\n')
+ row_offset = len(lines) - 1
+ logical_line = lines[0]
+ logical_line_length = len(logical_line)
+ if column > logical_line_length:
+ column = logical_line_length
row -= row_offset
column -= column_offset
return row, column