Skip to content

Commit

Permalink
Add end coordinates for column and line number
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Sep 27, 2022
1 parent 04ecb0c commit 3583849
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pyflakes/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,9 +1270,13 @@ def getDocstring(self, node):
def handleNode(self, node, parent):
if node is None:
return
if self.offset and getattr(node, 'lineno', None) is not None:
node.lineno += self.offset[0]
node.col_offset += self.offset[1]
if self.offset:
if getattr(node, 'lineno', None) is not None:
node.lineno += self.offset[0]
node.col_offset += self.offset[1]
if getattr(node, 'end_lineno', None) is not None:
node.end_lineno += self.offset[0]
node.end_col_offset += self.offset[1]
if self.futuresAllowed and not (isinstance(node, ast.ImportFrom) or
self.isDocstring(node)):
self.futuresAllowed = False
Expand Down
2 changes: 2 additions & 0 deletions pyflakes/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ def __init__(self, filename, loc):
self.filename = filename
self.lineno = loc.lineno
self.col = loc.col_offset
self.end_col = getattr(loc, 'end_col_offset', None)
self.end_lineno = getattr(loc, 'end_lineno', None)

def __str__(self):
return '{}:{}:{}: {}'.format(self.filename, self.lineno, self.col+1,
Expand Down
5 changes: 5 additions & 0 deletions pyflakes/test/test_doctests.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ def doctest_stuff():
''', m.UndefinedName).messages[0]
self.assertEqual(exc.lineno, 5)
self.assertEqual(exc.col, 20)
# end_col_offset and end_lineno are new in Python 3.8
if sys.version_info >= (3, 8):
# check that offsets are also added to end_col and end_lineno
self.assertEqual(exc.end_lineno, 5)
self.assertEqual(exc.end_col, 21)

def test_offsetAfterDoctests(self):
exc = self.flakes('''
Expand Down

0 comments on commit 3583849

Please sign in to comment.