forked from VimPlug/jedi
Fix some mostly iterable related stuff.
This commit is contained in:
@@ -148,7 +148,7 @@ class Evaluator(object):
|
|||||||
types = finder.check_tuple_assignments(self, types, seek_name)
|
types = finder.check_tuple_assignments(self, types, seek_name)
|
||||||
|
|
||||||
first_operation = stmt.first_operation()
|
first_operation = stmt.first_operation()
|
||||||
if first_operation not in ('=', None) and not isinstance(stmt, er.InstanceElement): # TODO don't check for this.
|
if first_operation not in ('=', None):
|
||||||
# `=` is always the last character in aug assignments -> -1
|
# `=` is always the last character in aug assignments -> -1
|
||||||
operator = copy.copy(first_operation)
|
operator = copy.copy(first_operation)
|
||||||
operator.value = operator.value[:-1]
|
operator.value = operator.value[:-1]
|
||||||
|
|||||||
@@ -339,12 +339,6 @@ class NameFinder(object):
|
|||||||
# Compiled names and other stuff should just be ignored when it
|
# Compiled names and other stuff should just be ignored when it
|
||||||
# comes to descriptors.
|
# comes to descriptors.
|
||||||
return types
|
return types
|
||||||
# The name must not be in the dictionary, but part of the class
|
|
||||||
# definition. __get__ is only called if the descriptor is defined in
|
|
||||||
# the class dictionary.
|
|
||||||
name_scope = name.tree_name.get_definition().get_parent_scope()
|
|
||||||
if not isinstance(name_scope, (er.Instance, tree.Class)):
|
|
||||||
return types
|
|
||||||
|
|
||||||
result = set()
|
result = set()
|
||||||
for r in types:
|
for r in types:
|
||||||
@@ -463,9 +457,6 @@ def _remove_statements(evaluator, context, stmt, name):
|
|||||||
#res_new.append(stmt)
|
#res_new.append(stmt)
|
||||||
|
|
||||||
check_instance = None
|
check_instance = None
|
||||||
if isinstance(stmt, er.InstanceElement) and stmt.is_class_var:
|
|
||||||
check_instance = stmt.instance
|
|
||||||
stmt = stmt.var
|
|
||||||
|
|
||||||
pep0484types = \
|
pep0484types = \
|
||||||
pep0484.find_type_from_comment_hint_assign(context, stmt, name)
|
pep0484.find_type_from_comment_hint_assign(context, stmt, name)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from jedi.evaluate import compiled
|
|||||||
from jedi.evaluate import filters
|
from jedi.evaluate import filters
|
||||||
from jedi.evaluate.context import Context, LazyKnownContext, LazyKnownContexts
|
from jedi.evaluate.context import Context, LazyKnownContext, LazyKnownContexts
|
||||||
from jedi.evaluate.cache import memoize_default
|
from jedi.evaluate.cache import memoize_default
|
||||||
|
from jedi.evaluate.param import ValuesArguments
|
||||||
from jedi.cache import memoize_method
|
from jedi.cache import memoize_method
|
||||||
from jedi.evaluate import representation as er
|
from jedi.evaluate import representation as er
|
||||||
from jedi.evaluate.dynamic import search_params
|
from jedi.evaluate.dynamic import search_params
|
||||||
@@ -115,7 +116,7 @@ class AbstractInstanceContext(Context):
|
|||||||
return set()
|
return set()
|
||||||
else:
|
else:
|
||||||
index_obj = compiled.create(self.evaluator, index)
|
index_obj = compiled.create(self.evaluator, index)
|
||||||
return unite(name.execute_evaluated(index_obj) for name in names)
|
return self.execute_function_slots(names, index_obj)
|
||||||
|
|
||||||
def py__iter__(self):
|
def py__iter__(self):
|
||||||
iter_slot_names = self.get_function_slot_names('__iter__')
|
iter_slot_names = self.get_function_slot_names('__iter__')
|
||||||
@@ -218,7 +219,10 @@ class CompiledInstanceName(compiled.CompiledName):
|
|||||||
def infer(self):
|
def infer(self):
|
||||||
for v in super(CompiledInstanceName, self).infer():
|
for v in super(CompiledInstanceName, self).infer():
|
||||||
if isinstance(v, er.FunctionContext):
|
if isinstance(v, er.FunctionContext):
|
||||||
yield BoundMethod(self._instance, self.parent_context, v)
|
yield BoundMethod(
|
||||||
|
v.evaluator, self._instance, self.parent_context,
|
||||||
|
v.parent_context, v.funcdef
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
yield v
|
yield v
|
||||||
|
|
||||||
@@ -238,30 +242,20 @@ class CompiledInstanceClassFilter(compiled.CompiledObjectFilter):
|
|||||||
return self.name_class(self._evaluator, self._instance, self._compiled_obj, name)
|
return self.name_class(self._evaluator, self._instance, self._compiled_obj, name)
|
||||||
|
|
||||||
|
|
||||||
class BoundMethod(object):
|
class BoundMethod(er.FunctionContext):
|
||||||
def __init__(self, instance, class_context, function):
|
def __init__(self, evaluator, instance, class_context, *args, **kwargs):
|
||||||
|
super(BoundMethod, self).__init__(evaluator, *args, **kwargs)
|
||||||
self._instance = instance
|
self._instance = instance
|
||||||
self._class_context = class_context
|
self._class_context = class_context
|
||||||
self._function = function
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
return getattr(self._function, name)
|
|
||||||
|
|
||||||
def get_function_execution(self, arguments):
|
def get_function_execution(self, arguments):
|
||||||
return InstanceFunctionExecution(
|
return InstanceFunctionExecution(
|
||||||
self._instance,
|
self._instance,
|
||||||
self.parent_context,
|
self.parent_context,
|
||||||
self._function.funcdef,
|
self.funcdef,
|
||||||
arguments
|
arguments
|
||||||
)
|
)
|
||||||
|
|
||||||
def py__call__(self, arguments):
|
|
||||||
function_execution = self.get_function_execution(arguments)
|
|
||||||
return self._function.infer_function_execution(function_execution)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return '<%s: %s>' % (self.__class__.__name__, self._function)
|
|
||||||
|
|
||||||
|
|
||||||
class InstanceNameDefinition(filters.TreeNameDefinition):
|
class InstanceNameDefinition(filters.TreeNameDefinition):
|
||||||
def infer(self):
|
def infer(self):
|
||||||
@@ -288,7 +282,10 @@ class LazyInstanceClassName(LazyInstanceName):
|
|||||||
def infer(self):
|
def infer(self):
|
||||||
for v in super(LazyInstanceClassName, self).infer():
|
for v in super(LazyInstanceClassName, self).infer():
|
||||||
if isinstance(v, er.FunctionContext):
|
if isinstance(v, er.FunctionContext):
|
||||||
yield BoundMethod(self._instance, self.class_context, v)
|
yield BoundMethod(
|
||||||
|
v.evaluator, self._instance, self.class_context,
|
||||||
|
v.parent_context, v.funcdef
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
yield v
|
yield v
|
||||||
|
|
||||||
|
|||||||
@@ -201,13 +201,7 @@ class Comprehension(AbstractSequence):
|
|||||||
"""
|
"""
|
||||||
comp_for = self._get_comp_for()
|
comp_for = self._get_comp_for()
|
||||||
# For nested comprehensions we need to search the last one.
|
# For nested comprehensions we need to search the last one.
|
||||||
from jedi.evaluate.representation import InstanceElement
|
|
||||||
node = self._get_comprehension().children[index]
|
node = self._get_comprehension().children[index]
|
||||||
if isinstance(node, InstanceElement):
|
|
||||||
# This seems to be a strange case that I haven't found a way to
|
|
||||||
# write tests against. However since it's my new goal to get rid of
|
|
||||||
# InstanceElement anyway, I don't care.
|
|
||||||
node = node.var
|
|
||||||
last_comp = list(comp_for.get_comp_fors())[-1]
|
last_comp = list(comp_for.get_comp_fors())[-1]
|
||||||
#TODO raise NotImplementedError('should not need to copy...')
|
#TODO raise NotImplementedError('should not need to copy...')
|
||||||
return helpers.deep_ast_copy(node, parent=last_comp)
|
return helpers.deep_ast_copy(node, parent=last_comp)
|
||||||
@@ -860,8 +854,12 @@ class _ArrayInstance(object):
|
|||||||
yield additions
|
yield additions
|
||||||
|
|
||||||
|
|
||||||
class Slice(object):
|
class Slice(context.Context):
|
||||||
def __init__(self, context, start, stop, step):
|
def __init__(self, context, start, stop, step):
|
||||||
|
super(Slice, self).__init__(
|
||||||
|
context.evaluator,
|
||||||
|
parent_context=context.evaluator.BUILTINS
|
||||||
|
)
|
||||||
self._context = context
|
self._context = context
|
||||||
# all of them are either a Precedence or None.
|
# all of them are either a Precedence or None.
|
||||||
self._start = start
|
self._start = start
|
||||||
|
|||||||
@@ -374,8 +374,8 @@ def _iterate_star_args(evaluator, array, input_node, func=None):
|
|||||||
|
|
||||||
|
|
||||||
def _star_star_dict(evaluator, array, input_node, func):
|
def _star_star_dict(evaluator, array, input_node, func):
|
||||||
from jedi.evaluate.representation import Instance
|
from jedi.evaluate.instance import CompiledInstance
|
||||||
if isinstance(array, Instance) and array.name.get_code() == 'dict':
|
if isinstance(array, CompiledInstance) and array.name.string_name == 'dict':
|
||||||
# For now ignore this case. In the future add proper iterators and just
|
# For now ignore this case. In the future add proper iterators and just
|
||||||
# make one call without crazy isinstance checks.
|
# make one call without crazy isinstance checks.
|
||||||
return {}
|
return {}
|
||||||
|
|||||||
@@ -253,7 +253,6 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrappe
|
|||||||
arguments
|
arguments
|
||||||
)
|
)
|
||||||
|
|
||||||
@Python3Method
|
|
||||||
def py__call__(self, arguments):
|
def py__call__(self, arguments):
|
||||||
function_execution = self.get_function_execution(arguments)
|
function_execution = self.get_function_execution(arguments)
|
||||||
return self.infer_function_execution(function_execution)
|
return self.infer_function_execution(function_execution)
|
||||||
|
|||||||
Reference in New Issue
Block a user