[New-bugs-announce] [issue2529] list/generator comprehension parser doesn't match spec
Nick Guenther
report at bugs.python.org
Tue Apr 1 21:19:09 CEST 2008
New submission from Nick Guenther <kousu at users.sourceforge.net>:
I think I've found a bug in python's list comprehension parser. Observe:
>>> [e for i in j in ['a','b','c']]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'j' is not defined
Now, according to the grammar at http://docs.python.org/ref/lists.html,
a list comprehension is (condensed for clarity):
list_comprehension ::= expression list_for
list_for ::= "for" target_list "in" old_expression_list [list_for]
So a list comprehension should always be
[.... for ... in .... for ... in ... for ... in ...]
(that is, alternating 'for's and 'in's) but here I have a test case that
python happily tries to run that looks like
[... for ... in ... in ....]
----------
components: Interpreter Core
messages: 64818
nosy: kousu
severity: normal
status: open
title: list/generator comprehension parser doesn't match spec
type: behavior
versions: Python 2.5
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2529>
__________________________________
More information about the New-bugs-announce
mailing list