diff --git a/jedi/inference/base_value.py b/jedi/inference/base_value.py index 88fb0e4c..61b8c393 100644 --- a/jedi/inference/base_value.py +++ b/jedi/inference/base_value.py @@ -66,7 +66,10 @@ class HelperValueMixin(object): from jedi.inference import finder f = finder.NameFinder(self.infer_state, self, name_value, name_or_str, position, analysis_errors=analysis_errors) - filters = f.get_filters(search_global) + if search_global: + filters = f.get_global_filters() + else: + filters = f.get_value_filters() if is_goto: return f.filter_name(filters) return f.find(filters, attribute_lookup=not search_global) diff --git a/jedi/inference/finder.py b/jedi/inference/finder.py index f44f44e1..de876a92 100644 --- a/jedi/inference/finder.py +++ b/jedi/inference/finder.py @@ -92,33 +92,31 @@ class NameFinder(object): else: return None - def get_filters(self, search_global=False): + def get_global_filters(self): origin_scope = self._get_origin_scope() - if search_global: - position = self._position + position = self._position - # For functions and classes the defaults don't belong to the - # function and get inferred in the value before the function. So - # make sure to exclude the function/class name. - if origin_scope is not None: - ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef', 'lambdef') - lambdef = None - if ancestor == 'lambdef': - # For lambdas it's even more complicated since parts will - # be inferred later. - lambdef = ancestor - ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef') - if ancestor is not None: - colon = ancestor.children[-2] - if position is not None and position < colon.start_pos: - if lambdef is None or position < lambdef.children[-2].start_pos: - position = ancestor.start_pos + # For functions and classes the defaults don't belong to the + # function and get inferred in the value before the function. So + # make sure to exclude the function/class name. + if origin_scope is not None: + ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef', 'lambdef') + lambdef = None + if ancestor == 'lambdef': + # For lambdas it's even more complicated since parts will + # be inferred later. + lambdef = ancestor + ancestor = search_ancestor(origin_scope, 'funcdef', 'classdef') + if ancestor is not None: + colon = ancestor.children[-2] + if position is not None and position < colon.start_pos: + if lambdef is None or position < lambdef.children[-2].start_pos: + position = ancestor.start_pos - return get_global_filters(self._infer_state, self._value, position, origin_scope) - else: - return self._get_value_filters(origin_scope) + return get_global_filters(self._infer_state, self._value, position, origin_scope) - def _get_value_filters(self, origin_scope): + def get_value_filters(self): + origin_scope = self._get_origin_scope() for f in self._value.get_filters(False, self._position, origin_scope=origin_scope): yield f # This covers the case where a stub files are incomplete. diff --git a/jedi/inference/syntax_tree.py b/jedi/inference/syntax_tree.py index e94d6acc..f803da1c 100644 --- a/jedi/inference/syntax_tree.py +++ b/jedi/inference/syntax_tree.py @@ -572,7 +572,7 @@ def tree_name_to_values(infer_state, value, tree_name): if node.type == 'global_stmt': value = infer_state.create_value(value, tree_name) finder = NameFinder(infer_state, value, value, tree_name.value) - filters = finder.get_filters(search_global=True) + filters = finder.get_global_filters() # For global_stmt lookups, we only need the first possible scope, # which means the function itself. filters = [next(filters)]