diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index aba6149e..7037903e 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -513,7 +513,9 @@ def _check_array_additions(evaluator, compare_array, module, is_list): # Is an Instance with an # Arguments([AlreadyEvaluated([ArrayInstance])]) inside # Yeah... I know... It's complicated ;-) - node = list(element.var_args.argument_node[0])[0].var_args + node = list(element.var_args.argument_node[0])[0].var_args.trailer + if isinstance(node, er.InstanceElement): + return node return node.get_parent_until(er.FunctionExecution) temp_param_add, settings.dynamic_params_for_other_modules = \ @@ -543,11 +545,6 @@ def _check_array_additions(evaluator, compare_array, module, is_list): # improves Jedi's speed for array lookups, since we # don't have to check the whole source tree anymore. continue - # InstanceElements are special, because they don't get copied, - # but have this wrapper around them. - if isinstance(comp_arr_parent, er.InstanceElement): - stmt = er.get_instance_el(comp_arr_parent.instance, stmt) - trailer = name.parent power = trailer.parent trailer_pos = power.children.index(trailer) @@ -561,6 +558,11 @@ def _check_array_additions(evaluator, compare_array, module, is_list): or execution_trailer.children[1] == ')': continue power = helpers.call_of_name(name, cut_own_trailer=True) + # InstanceElements are special, because they don't get copied, + # but have this wrapper around them. + if isinstance(comp_arr_parent, er.InstanceElement): + power = er.get_instance_el(evaluator, comp_arr_parent.instance, power) + if evaluator.recursion_detector.push_stmt(power): # Check for recursion. Possible by using 'extend' in # combination with function calls. diff --git a/jedi/evaluate/param.py b/jedi/evaluate/param.py index d42b763d..dda803ea 100644 --- a/jedi/evaluate/param.py +++ b/jedi/evaluate/param.py @@ -23,7 +23,7 @@ class Arguments(pr.Base): """ self.argument_node = argument_node self._evaluator = evaluator - self._trailer = trailer # Can be None, e.g. in a class definition. + self.trailer = trailer # Can be None, e.g. in a class definition. def _split(self): if isinstance(self.argument_node, (tuple, list)): @@ -44,7 +44,7 @@ class Arguments(pr.Base): yield 0, child def get_parent_until(self, *args, **kwargs): - return self._trailer.get_parent_until(*args, **kwargs) + return self.trailer.get_parent_until(*args, **kwargs) def as_tuple(self): for stars, argument in self._split(): @@ -126,7 +126,7 @@ class Arguments(pr.Base): def scope(self): # Returns the scope in which the arguments are used. - return (self._trailer or self.argument_node).get_parent_until(pr.IsScope) + return (self.trailer or self.argument_node).get_parent_until(pr.IsScope) def eval_args(self): # TODO this method doesn't work with named args and a lot of other diff --git a/test/completion/dynamic_arrays.py b/test/completion/dynamic_arrays.py index eb7781b8..19cb920f 100644 --- a/test/completion/dynamic_arrays.py +++ b/test/completion/dynamic_arrays.py @@ -242,13 +242,20 @@ class C(): a[0] return a - def class_arr(self, el): + def literal_arr(self, el): self.a = [] self.a.append(el) #? int() self.a[0] return self.a + def list_arr(self, el): + self.b = list([]) + self.b.append(el) + #? float() + self.b[0] + return self.b + #? int() C().blub(1)[0] #? float() @@ -257,7 +264,12 @@ C().blub2(1)[0] #? int() C().a[0] #? int() -C().class_arr(1)[0] +C().literal_arr(1)[0] + +#? float() +C().b[0] +#? float() +C().list_arr(1.0)[0] # ----------------- # array recursions