1
0
forked from VimPlug/jedi

Move some finder stuff around

This commit is contained in:
Dave Halter
2019-08-24 02:28:58 +02:00
parent 3828532065
commit e148d5120f
4 changed files with 13 additions and 16 deletions

View File

@@ -96,7 +96,7 @@ class HelperValueMixin(object):
if name_context is None:
name_context = self
from jedi.inference import finder
f = finder.NameFinder(self.inference_state, self, name_context, name_or_str,
f = finder.NameFinder(self, name_context, name_or_str,
analysis_errors=analysis_errors)
filters = self._get_value_filters(name_or_str)
names = f.filter_name(filters)

View File

@@ -25,7 +25,7 @@ class AbstractContext(object):
def _goto(self, name_or_str, position):
from jedi.inference import finder
f = finder.NameFinder(self.inference_state, self, self, name_or_str, position)
f = finder.NameFinder(self, self, name_or_str, position)
filters = _get_global_filters_for_name(
self, name_or_str if isinstance(name_or_str, Name) else None, position,
)

View File

@@ -19,21 +19,17 @@ from parso.python import tree
from parso.tree import search_ancestor
from jedi import debug
from jedi import settings
from jedi.inference import compiled
from jedi.inference import analysis
from jedi.inference import flow_analysis
from jedi.inference.arguments import TreeArguments
from jedi.inference import helpers
from jedi.inference.value import iterable
from jedi.inference.names import TreeNameDefinition
from jedi.inference.base_value import ValueSet, NO_VALUES
from jedi.parser_utils import is_scope, get_parent_scope
class NameFinder(object):
def __init__(self, inference_state, context, name_value, name_or_str,
def __init__(self, context, name_value, name_or_str,
position=None, analysis_errors=True):
self._inference_state = inference_state
# Make sure that it's not just a syntax tree node.
self._context = context
self._name_context = name_value
@@ -77,7 +73,11 @@ class NameFinder(object):
return NO_VALUES
return found_predefined_types
return self._names_to_types(names)
values = ValueSet.from_sets(name.infer() for name in names)
debug.dbg('finder._names_to_types: %s -> %s', names, values)
if values:
return values
return self._add_other_knowledge()
def filter_name(self, filters):
"""
@@ -92,18 +92,15 @@ class NameFinder(object):
return list(names)
def _names_to_types(self, names):
values = ValueSet.from_sets(name.infer() for name in names)
debug.dbg('finder._names_to_types: %s -> %s', names, values)
def _add_other_knowledge(self):
# Add isinstance and other if/assert knowledge.
if not values and isinstance(self._name, tree.Name) and \
if isinstance(self._name, tree.Name) and \
not self._name_context.is_instance() and not self._context.is_compiled():
flow_scope = self._name
base_nodes = [self._name_context.tree_node]
if any(b.type in ('comp_for', 'sync_comp_for') for b in base_nodes):
return values
return NO_VALUES
while True:
flow_scope = get_parent_scope(flow_scope, include_flows=True)
n = _check_flow_information(self._name_context, flow_scope,
@@ -112,7 +109,7 @@ class NameFinder(object):
return n
if flow_scope in base_nodes:
break
return values
return NO_VALUES
def _check_flow_information(value, flow, search_name, pos):

View File

@@ -571,7 +571,7 @@ def tree_name_to_values(inference_state, context, tree_name):
node = tree_name.parent
if node.type == 'global_stmt':
c = context.create_context(tree_name)
finder = NameFinder(inference_state, c, c, tree_name.value)
finder = NameFinder(c, c, tree_name.value)
# For global_stmt lookups, we only need the first possible scope,
# which means the function itself.
filters = [next(c.get_filters())]