mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24: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))
|
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)
|
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]
|
if_stmt_test = if_stmt.children[1]
|
||||||
name_dicts = [{}]
|
name_dicts = [{}]
|
||||||
# If we already did a check, we don't want to do it again -> If
|
# 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):
|
except (IndexError, AttributeError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if comp_for.type == 'comp_for' \
|
if comp_for == ':':
|
||||||
or comp_for == ':' and c[1].children[3].type == 'comp_for': # dict
|
# 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.Comprehension.from_atom(self, atom)])
|
||||||
return set([iterable.Array(self, atom)])
|
return set([iterable.Array(self, atom)])
|
||||||
|
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ class list():
|
|||||||
return self.__iterable[y]
|
return self.__iterable[y]
|
||||||
|
|
||||||
def pop(self):
|
def pop(self):
|
||||||
return self.__iterable[-1]
|
return self.__iterable[int()]
|
||||||
|
|
||||||
|
|
||||||
class tuple():
|
class tuple():
|
||||||
|
|||||||
@@ -201,6 +201,13 @@ class SetComprehension(Comprehension, ArrayMixin):
|
|||||||
type = 'set'
|
type = 'set'
|
||||||
|
|
||||||
|
|
||||||
|
class DictComprehension(Comprehension, ArrayMixin):
|
||||||
|
type = 'dict'
|
||||||
|
|
||||||
|
def _get_comp_for(self):
|
||||||
|
return self._get_comprehension().children[3]
|
||||||
|
|
||||||
|
|
||||||
class GeneratorComprehension(Comprehension, GeneratorMixin):
|
class GeneratorComprehension(Comprehension, GeneratorMixin):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -126,10 +126,12 @@ right
|
|||||||
# dict comprehensions
|
# dict comprehensions
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|
||||||
##? str()
|
d = {a - 1: b for a, b in {1: 'a', 3: 1.0}.items()}
|
||||||
{a - 1: b for a, b in {1: 'a', 3: 1.0}.items()}[0]
|
#? str()
|
||||||
|
list()[0]
|
||||||
|
|
||||||
#? int()
|
#? int()
|
||||||
{a - 1: 3 for a in [1]}[0]
|
list({a - 1: 3 for a in [1]})[0]
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# set comprehensions
|
# set comprehensions
|
||||||
@@ -146,9 +148,11 @@ right
|
|||||||
|
|
||||||
#? int()
|
#? int()
|
||||||
{a for a in range(10)}.pop()
|
{a for a in range(10)}.pop()
|
||||||
|
#? float() str()
|
||||||
|
{b for a in [[3.0], ['']] for b in a}.pop()
|
||||||
|
|
||||||
#? int()
|
#? int()
|
||||||
iter({a for a in range(10)}).next()
|
next(iter({a for a in range(10)}))
|
||||||
|
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user