Usages fix for more complex situations

This commit is contained in:
Dave Halter
2017-10-09 21:09:04 +02:00
parent 06004ad2f5
commit 2b138b3150
2 changed files with 26 additions and 4 deletions

View File

@@ -41,11 +41,22 @@ def usages(module_context, tree_name):
modules = set(d.get_root_context() for d in found_names.values())
modules = set(m for m in modules if isinstance(m, ModuleContext))
non_matching_usage_maps = {}
for m in imports.get_modules_containing_name(module_context.evaluator, modules, search_name):
for name_leaf in m.tree_node.get_used_names().get(search_name, []):
new = _find_names(m, name_leaf)
for tree_name in new:
if tree_name in found_names:
found_names.update(new)
break
if any(tree_name in found_names for tree_name in new):
found_names.update(new)
for tree_name in new:
for dct in non_matching_usage_maps.get(tree_name, []):
# A usage that was previously searched for matches with
# a now found name. Merge.
found_names.update(dct)
try:
del non_matching_usage_maps[tree_name]
except KeyError:
pass
else:
for name in new:
non_matching_usage_maps.setdefault(name, []).append(new)
return found_names.values()

View File

@@ -302,3 +302,14 @@ x = 3
{x:1 for x in something}
#< 10 (0,1), (0,10)
{x:1 for x in something}
def x():
zzz = 3
if UNDEFINED:
zzz = 5
if UNDEFINED2:
zzz
else:
#< (0, 8), (1, 4), (-3, 12), (-5, 8), (-7, 4)
zzz
zzz