Skip to content

Commit

Permalink
Fix a follow_imports (goto) issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhalter committed Sep 11, 2017
1 parent 619acbd commit 4a544c2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 7 additions & 8 deletions jedi/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,22 @@ def goto_assignments(self, follow_imports=False):
:rtype: list of :class:`classes.Definition`
"""
def filter_follow_imports(names, follow_classes):
def filter_follow_imports(names, check):
for name in names:
if isinstance(name, follow_classes):
if check(name):
for context in name.infer():
yield context.name
else:
yield name

names = self._goto()
if follow_imports:
# TODO really, sure? TreeNameDefinition? Should probably not follow
# that.
follow_classes = (imports.ImportName, TreeNameDefinition)
names = filter_follow_imports(names, lambda name: name.api_type == 'module')
else:
follow_classes = (imports.SubModuleName,)

names = filter_follow_imports(names, follow_classes)
names = filter_follow_imports(
names,
lambda name: isinstance(name, imports.SubModuleName)
)

defs = [classes.Definition(self._evaluator, d) for d in set(names)]
return helpers.sorted_definitions(defs)
Expand Down
3 changes: 3 additions & 0 deletions test/test_api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ def test_goto_assignments_follow_imports():
definition, = script.goto_assignments()
assert (definition.line, definition.column) == start_pos

d, = api.Script('a = 1\na').goto_assignments(follow_imports=True)
assert d.name == 'a'


def test_goto_module():
def check(line, expected):
Expand Down

0 comments on commit 4a544c2

Please sign in to comment.