-
-
Notifications
You must be signed in to change notification settings - Fork 388
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
Check that generator expressions are safe #1951
Comments
Hey 👋 , I'm new to the project and I'd like to contribute. |
Thanks, @GibranHL0! |
Great. I'll make the proposal as soon as possible. |
Hey @sobolevn, I got my approach to the issue. 👋 >>> a = 1
>>> b = (a * i for i in range(5))
>>> print(list(b))
[0, 1, 2, 3, 4]
>>> a = 2 The code works fine! So, my solution would be:
>>> ( a * i for i in range(5))
>>> var_before_for = ["a", "i"]
>>> ( a * i for i in range(5))
>>> var_for_in = ["i"]
>>> var_affect = ["a"]
I'd use a tokenize visitor and violation to implement it. What do you think? 🤔 |
Looks great! But, I think that |
Sure, I was checking, and I think is a better idea to use the I'll upload the PR as soon as possible. ✌️ |
Rule request
Thesis
We can create generator expression that produce a different result from what we expect.
Link: https://twitter.com/asmeurer/status/1371952741728194561
Reasoning
Comprehensions like this should be safe. We should not be able to reassign values that comprehensions rely on.
The text was updated successfully, but these errors were encountered: