fix issue with list comprehensions in function calls

This commit is contained in:
Dave Halter
2014-06-20 16:28:31 +02:00
parent 8c924afdb8
commit 2fc404f99d
2 changed files with 20 additions and 12 deletions

View File

@@ -1008,18 +1008,19 @@ isinstance(c, (tokenize.Token, Operator)) else unicode(c)
if isinstance(tok, Base): if isinstance(tok, Base):
# the token is a Name, which has already been parsed # the token is a Name, which has already been parsed
if isinstance(tok, ListComprehension): if not level:
# it's not possible to set it earlier if isinstance(tok, ListComprehension):
tok.parent = self # it's not possible to set it earlier
elif tok == 'lambda': tok.parent = self
lambd, tok = parse_lambda(token_iterator) elif tok == 'lambda':
if lambd is not None: lambd, tok = parse_lambda(token_iterator)
token_list.append(lambd) if lambd is not None:
elif tok == 'for': token_list.append(lambd)
list_comp, tok = parse_list_comp(token_iterator, token_list, elif tok == 'for':
start_pos, tok.end_pos) list_comp, tok = parse_list_comp(token_iterator, token_list,
if list_comp is not None: start_pos, tok.end_pos)
token_list = [list_comp] if list_comp is not None:
token_list = [list_comp]
if tok in closing_brackets: if tok in closing_brackets:
level -= 1 level -= 1

View File

@@ -144,6 +144,13 @@ left
##? str() ##? str()
{a-1:b for a,b in {1:'a', 3:1.0}.items()}[0] {a-1:b for a,b in {1:'a', 3:1.0}.items()}[0]
# list comprehensions should also work in combination with functions
def listen(arg):
for x in arg:
#? str()
x
listen(['' for x in [1]])
# ----------------- # -----------------
# nested list comprehensions # nested list comprehensions
# ----------------- # -----------------