New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
list/generator comprehension parser doesn't match spec #46781
Comments
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, So a list comprehension should always be |
Your example is parsed as [e for i in (j in ['a','b','c'])] and since Grammatically, this is the following (just the important parts, again): So your basic misconception is that both |
Indeed; your sample is equivalent to: temp = (j in ['a','b','c']) # the "contains" operator
[e for i in temp] # basic list comprehension Even if not meaningful, this code is syntactically correct. |
Oh, okay. That's really confusing because I expect "in" to always return |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: