diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index 4e8d1e7a..48103bfb 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -199,7 +199,7 @@ class Evaluator(object): if_stmt = element.get_parent_until((tree.IfStmt, tree.ForStmt, tree.IsScope)) predefined_if_name_dict = self.predefined_if_name_dict_dict.get(if_stmt) - if not predefined_if_name_dict and isinstance(if_stmt, tree.IfStmt): + if predefined_if_name_dict is None and isinstance(if_stmt, tree.IfStmt): if_stmt_test = if_stmt.children[1] name_dicts = [{}] # If we already did a check, we don't want to do it again -> If @@ -358,8 +358,14 @@ class Evaluator(object): except (IndexError, AttributeError): pass else: - if comp_for.type == 'comp_for' \ - or comp_for == ':' and c[1].children[3].type == 'comp_for': # dict + if comp_for == ':': + # Dict comprehensions have it at the 3rd index. + try: + comp_for = c[1].children[3] + except IndexError: + pass + + if comp_for.type == 'comp_for': return set([iterable.Comprehension.from_atom(self, atom)]) return set([iterable.Array(self, atom)]) diff --git a/jedi/evaluate/compiled/fake/builtins.pym b/jedi/evaluate/compiled/fake/builtins.pym index 1ed9b0b2..44f33f7c 100644 --- a/jedi/evaluate/compiled/fake/builtins.pym +++ b/jedi/evaluate/compiled/fake/builtins.pym @@ -124,7 +124,7 @@ class list(): return self.__iterable[y] def pop(self): - return self.__iterable[-1] + return self.__iterable[int()] class tuple(): diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index 035c0805..afc129b6 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -201,6 +201,13 @@ class SetComprehension(Comprehension, ArrayMixin): type = 'set' +class DictComprehension(Comprehension, ArrayMixin): + type = 'dict' + + def _get_comp_for(self): + return self._get_comprehension().children[3] + + class GeneratorComprehension(Comprehension, GeneratorMixin): pass diff --git a/test/completion/comprehensions.py b/test/completion/comprehensions.py index 5aeb7107..b1e0caf2 100644 --- a/test/completion/comprehensions.py +++ b/test/completion/comprehensions.py @@ -126,10 +126,12 @@ right # dict comprehensions # ----------------- -##? str() -{a - 1: b for a, b in {1: 'a', 3: 1.0}.items()}[0] +d = {a - 1: b for a, b in {1: 'a', 3: 1.0}.items()} +#? str() +list()[0] + #? int() -{a - 1: 3 for a in [1]}[0] +list({a - 1: 3 for a in [1]})[0] # ----------------- # set comprehensions @@ -146,9 +148,11 @@ right #? int() {a for a in range(10)}.pop() +#? float() str() +{b for a in [[3.0], ['']] for b in a}.pop() #? int() -iter({a for a in range(10)}).next() +next(iter({a for a in range(10)})) # -----------------