From b8a8c4d402161d494a4e5e3c8a9fdeff4f97a541 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 26 Feb 2015 13:57:54 +0100 Subject: [PATCH] Fix an array lookup issue. list.pop calls work now pretty well and return the right type. --- jedi/evaluate/__init__.py | 2 +- jedi/evaluate/iterable.py | 3 ++- jedi/evaluate/param.py | 13 ++++++++++++- test/completion/types.py | 11 +++++++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 8b672a1f..1fa72dbb 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -146,7 +146,7 @@ class Evaluator(object): @memoize_default(evaluator_is_first_arg=True) def eval_element(self, element): if isinstance(element, iterable.AlreadyEvaluated): - return element + return list(element) elif isinstance(element, iterable.MergedNodes): return iterable.unite(self.eval_element(e) for e in element) diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index 0fb8df82..b777c8d8 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -246,7 +246,8 @@ class Array(IterableWrapper): def names_dicts(self, search_global=False): # Always False. # `array.type` is a string with the type, e.g. 'list'. scope = self._evaluator.find_types(compiled.builtin, self.type)[0] - scope = self._evaluator.execute(scope)[0] # builtins only have one class + # builtins only have one class -> [0] + scope = self._evaluator.execute(scope, (AlreadyEvaluated((self,)),))[0] return scope.names_dicts(search_global) @common.safe_property diff --git a/jedi/evaluate/param.py b/jedi/evaluate/param.py index d3e5f774..44e6261f 100644 --- a/jedi/evaluate/param.py +++ b/jedi/evaluate/param.py @@ -44,7 +44,18 @@ class Arguments(pr.Base): yield 0, child def get_parent_until(self, *args, **kwargs): - return self.trailer.get_parent_until(*args, **kwargs) + if self.trailer is None: + try: + element = self.argument_node[0] + from jedi.evaluate.iterable import AlreadyEvaluated + if isinstance(element, AlreadyEvaluated): + element = self._evaluator.eval_element(element)[0] + except IndexError: + return None + else: + return element.get_parent_until(*args, **kwargs) + else: + return self.trailer.get_parent_until(*args, **kwargs) def as_tuple(self): for stars, argument in self._split(): diff --git a/test/completion/types.py b/test/completion/types.py index 04c17c95..8bca1942 100644 --- a/test/completion/types.py +++ b/test/completion/types.py @@ -47,6 +47,17 @@ arr2.app #? int() arr.count(1) +x = [] +#? +x.pop() +x = [3] +#? int() +x.pop() +x = [] +x.append(1.0) +#? float() +x.pop() + # ----------------- # dicts # -----------------