diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index db4b3461..ae08ca14 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -148,7 +148,7 @@ class Evaluator(object): types = finder.check_tuple_assignments(self, types, seek_name) 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 operator = copy.copy(first_operation) operator.value = operator.value[:-1] diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index 25721f3e..761d058c 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -339,12 +339,6 @@ class NameFinder(object): # Compiled names and other stuff should just be ignored when it # comes to descriptors. 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() for r in types: @@ -463,9 +457,6 @@ def _remove_statements(evaluator, context, stmt, name): #res_new.append(stmt) check_instance = None - if isinstance(stmt, er.InstanceElement) and stmt.is_class_var: - check_instance = stmt.instance - stmt = stmt.var pep0484types = \ pep0484.find_type_from_comment_hint_assign(context, stmt, name) diff --git a/jedi/evaluate/instance.py b/jedi/evaluate/instance.py index 62ecf31e..cfd6fb8d 100644 --- a/jedi/evaluate/instance.py +++ b/jedi/evaluate/instance.py @@ -7,6 +7,7 @@ from jedi.evaluate import compiled from jedi.evaluate import filters from jedi.evaluate.context import Context, LazyKnownContext, LazyKnownContexts from jedi.evaluate.cache import memoize_default +from jedi.evaluate.param import ValuesArguments from jedi.cache import memoize_method from jedi.evaluate import representation as er from jedi.evaluate.dynamic import search_params @@ -115,7 +116,7 @@ class AbstractInstanceContext(Context): return set() else: 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): iter_slot_names = self.get_function_slot_names('__iter__') @@ -218,7 +219,10 @@ class CompiledInstanceName(compiled.CompiledName): def infer(self): for v in super(CompiledInstanceName, self).infer(): 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: yield v @@ -238,30 +242,20 @@ class CompiledInstanceClassFilter(compiled.CompiledObjectFilter): return self.name_class(self._evaluator, self._instance, self._compiled_obj, name) -class BoundMethod(object): - def __init__(self, instance, class_context, function): +class BoundMethod(er.FunctionContext): + def __init__(self, evaluator, instance, class_context, *args, **kwargs): + super(BoundMethod, self).__init__(evaluator, *args, **kwargs) self._instance = instance self._class_context = class_context - self._function = function - - def __getattr__(self, name): - return getattr(self._function, name) def get_function_execution(self, arguments): return InstanceFunctionExecution( self._instance, self.parent_context, - self._function.funcdef, + self.funcdef, 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): def infer(self): @@ -288,7 +282,10 @@ class LazyInstanceClassName(LazyInstanceName): def infer(self): for v in super(LazyInstanceClassName, self).infer(): 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: yield v diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index 8e4b19dc..c5439287 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -201,13 +201,7 @@ class Comprehension(AbstractSequence): """ comp_for = self._get_comp_for() # For nested comprehensions we need to search the last one. - from jedi.evaluate.representation import InstanceElement 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] #TODO raise NotImplementedError('should not need to copy...') return helpers.deep_ast_copy(node, parent=last_comp) @@ -860,8 +854,12 @@ class _ArrayInstance(object): yield additions -class Slice(object): +class Slice(context.Context): def __init__(self, context, start, stop, step): + super(Slice, self).__init__( + context.evaluator, + parent_context=context.evaluator.BUILTINS + ) self._context = context # all of them are either a Precedence or None. self._start = start diff --git a/jedi/evaluate/param.py b/jedi/evaluate/param.py index eed74a81..9c1f98fb 100644 --- a/jedi/evaluate/param.py +++ b/jedi/evaluate/param.py @@ -374,8 +374,8 @@ def _iterate_star_args(evaluator, array, input_node, func=None): def _star_star_dict(evaluator, array, input_node, func): - from jedi.evaluate.representation import Instance - if isinstance(array, Instance) and array.name.get_code() == 'dict': + from jedi.evaluate.instance import CompiledInstance + if isinstance(array, CompiledInstance) and array.name.string_name == 'dict': # For now ignore this case. In the future add proper iterators and just # make one call without crazy isinstance checks. return {} diff --git a/jedi/evaluate/representation.py b/jedi/evaluate/representation.py index 17a68972..8a8f6dd5 100644 --- a/jedi/evaluate/representation.py +++ b/jedi/evaluate/representation.py @@ -253,7 +253,6 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext, Wrappe arguments ) - @Python3Method def py__call__(self, arguments): function_execution = self.get_function_execution(arguments) return self.infer_function_execution(function_execution)