forked from VimPlug/jedi
Move the isinstance checks out of finder
This commit is contained in:
@@ -7,6 +7,7 @@ from parso.python.tree import Name
|
||||
from jedi.inference.filters import ParserTreeFilter, MergedFilter, \
|
||||
GlobalNameFilter
|
||||
from jedi.inference.base_value import NO_VALUES
|
||||
from jedi.parser_utils import get_parent_scope
|
||||
from jedi import debug
|
||||
from jedi import parser_utils
|
||||
|
||||
@@ -80,7 +81,29 @@ class AbstractContext(object):
|
||||
from jedi.inference import analysis
|
||||
message = ("NameError: name '%s' is not defined." % string_name)
|
||||
analysis.add(name_context, 'name-error', name_or_str, message)
|
||||
return values
|
||||
if values:
|
||||
return values
|
||||
return self._check_for_additional_knowledge(name_or_str, name_context, position)
|
||||
|
||||
def _check_for_additional_knowledge(self, name_or_str, name_context, position):
|
||||
name_context = name_context or self
|
||||
# Add isinstance and other if/assert knowledge.
|
||||
if isinstance(name_or_str, Name) and not name_context.is_instance():
|
||||
flow_scope = name_or_str
|
||||
base_nodes = [name_context.tree_node]
|
||||
|
||||
if any(b.type in ('comp_for', 'sync_comp_for') for b in base_nodes):
|
||||
return NO_VALUES
|
||||
from jedi.inference.finder import check_flow_information
|
||||
while True:
|
||||
flow_scope = get_parent_scope(flow_scope, include_flows=True)
|
||||
n = check_flow_information(name_context, flow_scope,
|
||||
name_or_str, position)
|
||||
if n is not None:
|
||||
return n
|
||||
if flow_scope in base_nodes:
|
||||
break
|
||||
return NO_VALUES
|
||||
|
||||
def get_root_context(self):
|
||||
parent_context = self.parent_context
|
||||
|
||||
@@ -23,7 +23,7 @@ from jedi.inference.arguments import TreeArguments
|
||||
from jedi.inference import helpers
|
||||
from jedi.inference.value import iterable
|
||||
from jedi.inference.base_value import ValueSet, NO_VALUES
|
||||
from jedi.parser_utils import is_scope, get_parent_scope
|
||||
from jedi.parser_utils import is_scope
|
||||
|
||||
|
||||
class NameFinder(object):
|
||||
@@ -47,9 +47,7 @@ class NameFinder(object):
|
||||
"""
|
||||
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()
|
||||
return values
|
||||
|
||||
def filter_name(self, filters):
|
||||
"""
|
||||
@@ -64,27 +62,8 @@ class NameFinder(object):
|
||||
|
||||
return list(names)
|
||||
|
||||
def _add_other_knowledge(self):
|
||||
# Add isinstance and other if/assert knowledge.
|
||||
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 NO_VALUES
|
||||
while True:
|
||||
flow_scope = get_parent_scope(flow_scope, include_flows=True)
|
||||
n = _check_flow_information(self._name_context, flow_scope,
|
||||
self._name, self._position)
|
||||
if n is not None:
|
||||
return n
|
||||
if flow_scope in base_nodes:
|
||||
break
|
||||
return NO_VALUES
|
||||
|
||||
|
||||
def _check_flow_information(value, flow, search_name, pos):
|
||||
def check_flow_information(value, flow, search_name, pos):
|
||||
""" Try to find out the type of a variable just with the information that
|
||||
is given by the flows: e.g. It is also responsible for assert checks.::
|
||||
|
||||
|
||||
Reference in New Issue
Block a user