diff --git a/jedi/inference/names.py b/jedi/inference/names.py index bc6d494f..6a75504a 100644 --- a/jedi/inference/names.py +++ b/jedi/inference/names.py @@ -166,6 +166,8 @@ class AbstractTreeName(AbstractNameDefinition): node_type = par.type if node_type == 'argument' and par.children[1] == '=' and par.children[0] == name: # Named param goto. + if not all_scopes: + return [self] trailer = par.parent if trailer.type == 'arglist': trailer = trailer.parent @@ -200,6 +202,8 @@ class AbstractTreeName(AbstractNameDefinition): ) if node_type == 'trailer' and par.children[0] == '.': + if not all_scopes: + return [self] values = infer_call_of_leaf(context, name, cut_own_trailer=True) return values.goto(name, name_context=context) else: diff --git a/jedi/inference/references.py b/jedi/inference/references.py index 19a843f9..ff52cb56 100644 --- a/jedi/inference/references.py +++ b/jedi/inference/references.py @@ -144,6 +144,11 @@ def find_references(module_context, tree_name, all_scopes=True): search_name, ) + gotos = set() + if not all_scopes: + for name in found_names_dct.values(): + gotos |= set(name.goto()) + non_matching_reference_maps = {} for module_context in potential_modules: for name_leaf in module_context.tree_node.get_used_names().get(search_name, []): @@ -162,6 +167,18 @@ def find_references(module_context, tree_name, all_scopes=True): else: for name in new: non_matching_reference_maps.setdefault(name, []).append(new) + + if not all_scopes: + def in_gotos(g): + for g_ in gotos: + if g.start_pos == g_.start_pos and g.get_root_context() == g_.get_root_context(): + return True + + for dct_list in non_matching_reference_maps.values(): + for dct in dct_list: + for k, v in dct.items(): + if any(in_gotos(g) for g in v.goto()): + found_names_dct[k] = v return found_names_dct.values()