Differentiate in finder between get_value_filters and get_global_filters

This commit is contained in:
Dave Halter
2019-08-15 09:29:08 +02:00
parent 9986d8c9aa
commit 21a18c698e
3 changed files with 26 additions and 25 deletions

View File

@@ -66,7 +66,10 @@ class HelperValueMixin(object):
from jedi.inference import finder from jedi.inference import finder
f = finder.NameFinder(self.infer_state, self, name_value, name_or_str, f = finder.NameFinder(self.infer_state, self, name_value, name_or_str,
position, analysis_errors=analysis_errors) 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: if is_goto:
return f.filter_name(filters) return f.filter_name(filters)
return f.find(filters, attribute_lookup=not search_global) return f.find(filters, attribute_lookup=not search_global)

View File

@@ -92,9 +92,8 @@ class NameFinder(object):
else: else:
return None return None
def get_filters(self, search_global=False): def get_global_filters(self):
origin_scope = self._get_origin_scope() 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 # For functions and classes the defaults don't belong to the
@@ -115,10 +114,9 @@ class NameFinder(object):
position = ancestor.start_pos position = ancestor.start_pos
return get_global_filters(self._infer_state, self._value, position, origin_scope) return get_global_filters(self._infer_state, self._value, position, origin_scope)
else:
return self._get_value_filters(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): for f in self._value.get_filters(False, self._position, origin_scope=origin_scope):
yield f yield f
# This covers the case where a stub files are incomplete. # This covers the case where a stub files are incomplete.

View File

@@ -572,7 +572,7 @@ def tree_name_to_values(infer_state, value, tree_name):
if node.type == 'global_stmt': if node.type == 'global_stmt':
value = infer_state.create_value(value, tree_name) value = infer_state.create_value(value, tree_name)
finder = NameFinder(infer_state, value, value, tree_name.value) 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, # For global_stmt lookups, we only need the first possible scope,
# which means the function itself. # which means the function itself.
filters = [next(filters)] filters = [next(filters)]