Skip to content

Commit

Permalink
Fix api.usages so it finds cross-module usages
Browse files Browse the repository at this point in the history
  • Loading branch information
andylee-ncc authored and davidhalter committed Apr 1, 2017
1 parent 3e36238 commit 1624f69
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion jedi/api/usages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
from jedi.evaluate.representation import ModuleContext


def compare_contexts(c1, c2):
return c1 == c2 or (c1[1] == c2[1] and c1[0].tree_node == c2[0].tree_node)


def usages(evaluator, definition_names, mods):
"""
:param definitions: list of Name
Expand Down Expand Up @@ -40,7 +44,9 @@ def compare_array(definition_names):
for name_node in m.tree_node.used_names.get(search_name, []):
context = evaluator.create_context(m, name_node)
result = evaluator.goto(context, name_node)
if [c for c in compare_array(result) if c in compare_definitions]:
if any(compare_contexts(c1, c2)
for c1 in compare_array(result)
for c2 in compare_definitions):
name = TreeNameDefinition(context, name_node)
definition_names.add(name)
# Previous definitions might be imports, so include them
Expand Down

0 comments on commit 1624f69

Please sign in to comment.