mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Dict comprehensions are working partially.
This commit is contained in:
@@ -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)])
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ class list():
|
||||
return self.__iterable[y]
|
||||
|
||||
def pop(self):
|
||||
return self.__iterable[-1]
|
||||
return self.__iterable[int()]
|
||||
|
||||
|
||||
class tuple():
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)}))
|
||||
|
||||
|
||||
# -----------------
|
||||
|
||||
Reference in New Issue
Block a user