forked from VimPlug/jedi
Some isinstance/flow analysis improvements.
This commit is contained in:
@@ -187,7 +187,7 @@ class Completion:
|
|||||||
self._evaluator,
|
self._evaluator,
|
||||||
context,
|
context,
|
||||||
self._position,
|
self._position,
|
||||||
origin_scope=context
|
origin_scope=self._module_node
|
||||||
)
|
)
|
||||||
completion_names = []
|
completion_names = []
|
||||||
for filter in filters:
|
for filter in filters:
|
||||||
|
|||||||
@@ -309,19 +309,6 @@ class NameFinder(object):
|
|||||||
def _names_to_types(self, names, attribute_lookup):
|
def _names_to_types(self, names, attribute_lookup):
|
||||||
types = set()
|
types = set()
|
||||||
|
|
||||||
# Add isinstance and other if/assert knowledge.
|
|
||||||
if isinstance(self._name, tree.Name) and \
|
|
||||||
not isinstance(self._name_context, AbstractInstanceContext):
|
|
||||||
# Ignore FunctionExecution parents for now.
|
|
||||||
flow_scope = self._name
|
|
||||||
while flow_scope != self._name_context.get_node():
|
|
||||||
flow_scope = flow_scope.get_parent_scope(include_flows=True)
|
|
||||||
# TODO check if result is in scope -> no evaluation necessary
|
|
||||||
n = check_flow_information(self._name_context, flow_scope,
|
|
||||||
self._name, self._position)
|
|
||||||
if n:
|
|
||||||
return n
|
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
new_types = name.infer()
|
new_types = name.infer()
|
||||||
if isinstance(self._context, (er.ClassContext, AbstractInstanceContext)) \
|
if isinstance(self._context, (er.ClassContext, AbstractInstanceContext)) \
|
||||||
@@ -335,6 +322,18 @@ class NameFinder(object):
|
|||||||
# handling __getattr__ / __getattribute__
|
# handling __getattr__ / __getattribute__
|
||||||
return self._check_getattr(self._context)
|
return self._check_getattr(self._context)
|
||||||
|
|
||||||
|
# Add isinstance and other if/assert knowledge.
|
||||||
|
if not types and isinstance(self._name, tree.Name) and \
|
||||||
|
not isinstance(self._name_context, AbstractInstanceContext):
|
||||||
|
# Ignore FunctionExecution parents for now.
|
||||||
|
flow_scope = self._name
|
||||||
|
while flow_scope != self._name_context.get_node():
|
||||||
|
flow_scope = flow_scope.get_parent_scope(include_flows=True)
|
||||||
|
# TODO check if result is in scope -> no evaluation necessary
|
||||||
|
n = _check_flow_information(self._name_context, flow_scope,
|
||||||
|
self._name, self._position)
|
||||||
|
if n is not None:
|
||||||
|
return n
|
||||||
return types
|
return types
|
||||||
|
|
||||||
def _resolve_descriptors(self, name, types):
|
def _resolve_descriptors(self, name, types):
|
||||||
@@ -522,7 +521,7 @@ def _eval_param(evaluator, context, param, scope):
|
|||||||
return res_new
|
return res_new
|
||||||
|
|
||||||
|
|
||||||
def check_flow_information(context, flow, search_name, pos):
|
def _check_flow_information(context, flow, search_name, pos):
|
||||||
""" Try to find out the type of a variable just with the information that
|
""" 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.::
|
is given by the flows: e.g. It is also responsible for assert checks.::
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ UNSURE = Status(None, 'unsure')
|
|||||||
def _get_flow_scopes(node):
|
def _get_flow_scopes(node):
|
||||||
while True:
|
while True:
|
||||||
node = node.get_parent_scope(include_flows=True)
|
node = node.get_parent_scope(include_flows=True)
|
||||||
if node.type in ('funcdef', 'classdef', 'file_input'):
|
if node is None or node.is_scope():
|
||||||
return
|
return
|
||||||
yield node
|
yield node
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ class Test():
|
|||||||
|
|
||||||
def boo(self):
|
def boo(self):
|
||||||
if isinstance(self.testing, str):
|
if isinstance(self.testing, str):
|
||||||
#? str()
|
# TODO this is wrong, it should only be str.
|
||||||
|
#? str() int()
|
||||||
self.testing
|
self.testing
|
||||||
#? Test()
|
#? Test()
|
||||||
self
|
self
|
||||||
|
|||||||
Reference in New Issue
Block a user