mirror of
https://github.com/davidhalter/jedi.git
synced 2026-03-02 06:46:51 +08:00
tests for list comprehensions with included dict literals
This commit is contained in:
@@ -844,8 +844,6 @@ class Statement(Simple, DocstringMixin):
|
|||||||
def __init__(self, module, token_list, start_pos, end_pos, parent=None,
|
def __init__(self, module, token_list, start_pos, end_pos, parent=None,
|
||||||
as_names=(), names_are_set_vars=False, set_name_parents=True):
|
as_names=(), names_are_set_vars=False, set_name_parents=True):
|
||||||
super(Statement, self).__init__(module, start_pos, end_pos)
|
super(Statement, self).__init__(module, start_pos, end_pos)
|
||||||
if isinstance(start_pos, list):
|
|
||||||
raise NotImplementedError()
|
|
||||||
self._token_list = token_list
|
self._token_list = token_list
|
||||||
self._names_are_set_vars = names_are_set_vars
|
self._names_are_set_vars = names_are_set_vars
|
||||||
if set_name_parents:
|
if set_name_parents:
|
||||||
@@ -985,7 +983,7 @@ isinstance(c, (tokenize.Token, Operator)) else unicode(c)
|
|||||||
def parse_stmt(token_iterator, maybe_dict=False, added_breaks=(),
|
def parse_stmt(token_iterator, maybe_dict=False, added_breaks=(),
|
||||||
break_on_assignment=False, stmt_class=Statement):
|
break_on_assignment=False, stmt_class=Statement):
|
||||||
token_list = []
|
token_list = []
|
||||||
level = 1
|
level = 0
|
||||||
first = True
|
first = True
|
||||||
end_pos = None, None
|
end_pos = None, None
|
||||||
tok = None
|
tok = None
|
||||||
@@ -1015,9 +1013,9 @@ isinstance(c, (tokenize.Token, Operator)) else unicode(c)
|
|||||||
elif tok in brackets.keys():
|
elif tok in brackets.keys():
|
||||||
level += 1
|
level += 1
|
||||||
|
|
||||||
if level == 0 and tok in closing_brackets \
|
if level == -1 and tok in closing_brackets \
|
||||||
or tok in added_breaks \
|
or tok in added_breaks \
|
||||||
or level == 1 and (
|
or level == 0 and (
|
||||||
tok == ','
|
tok == ','
|
||||||
or maybe_dict and tok == ':'
|
or maybe_dict and tok == ':'
|
||||||
or is_assignment(tok)
|
or is_assignment(tok)
|
||||||
@@ -1081,7 +1079,7 @@ isinstance(c, (tokenize.Token, Operator)) else unicode(c)
|
|||||||
stmt = Statement(self._sub_module, token_list,
|
stmt = Statement(self._sub_module, token_list,
|
||||||
start_pos, arr.end_pos)
|
start_pos, arr.end_pos)
|
||||||
arr.parent = stmt
|
arr.parent = stmt
|
||||||
stmt._token_list = stmt._expression_list = [arr]
|
stmt._expression_list = [arr]
|
||||||
else:
|
else:
|
||||||
for t in stmt._token_list:
|
for t in stmt._token_list:
|
||||||
if isinstance(t, Name):
|
if isinstance(t, Name):
|
||||||
|
|||||||
@@ -131,6 +131,13 @@ a = [a if 1.0 else '' for a in [1] if [1.0]]
|
|||||||
#? int() str()
|
#? int() str()
|
||||||
a[0]
|
a[0]
|
||||||
|
|
||||||
|
# with a dict in between
|
||||||
|
#? int()
|
||||||
|
[a for a,b in {1:2}.items()][0]
|
||||||
|
|
||||||
|
#? str()
|
||||||
|
{a:b for a,b in {1:'a', 3:1.0}.items()}[1]
|
||||||
|
|
||||||
# -----------------
|
# -----------------
|
||||||
# nested list comprehensions
|
# nested list comprehensions
|
||||||
# -----------------
|
# -----------------
|
||||||
|
|||||||
Reference in New Issue
Block a user