Fix an error of get_definition_end_pos, see #1584

This commit is contained in:
Dave Halter
2020-05-18 01:44:27 +02:00
parent fa6194c0a9
commit 8fdf16b316
2 changed files with 6 additions and 3 deletions

View File

@@ -236,7 +236,7 @@ class BaseName(object):
The (row, column) of the start of the definition range. Rows start with
1, columns start with 0.
:rtype: Tuple[int, int]
:rtype: Optional[Tuple[int, int]]
"""
definition = self._name.tree_name.get_definition()
if definition is None:
@@ -248,11 +248,13 @@ class BaseName(object):
The (row, column) of the end of the definition range. Rows start with
1, columns start with 0.
:rtype: Tuple[int, int]
:rtype: Optional[Tuple[int, int]]
"""
definition = self._name.tree_name.get_definition()
if definition is None:
return self._name.end_pos
if self._name.tree_name is None:
return None
return self._name.tree_name.end_pos
if self.type in ("function", "class"):
last_leaf = definition.get_last_leaf()
if last_leaf.type == "newline":

View File

@@ -619,6 +619,7 @@ class AClass:
'code, pos, start, end', [
('def a_func():\n return "bar"\n', (1, 4), (1, 0), (2, 16)),
('var1 = 12', (1, 0), (1, 0), (1, 9)),
('var1 + 1', (1, 0), (1, 0), (1, 4)),
('class AClass: pass', (1, 6), (1, 0), (1, 18)),
('class AClass: pass\n', (1, 6), (1, 0), (1, 18)),
(cls_code, (1, 6), (1, 0), (6, 23)),