Skip to content
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

Detect leaking for loops in ClassDef and Module #2340

Open
sobolevn opened this issue Jan 28, 2022 · 0 comments
Open

Detect leaking for loops in ClassDef and Module #2340

sobolevn opened this issue Jan 28, 2022 · 0 comments
Labels
rule request Adding a new rule

Comments

@sobolevn
Copy link
Member

Right now we can have two problems:

class Some(object):
   for x in [1, 2]:
       print(x)

print(Some.x)  # oups, will show you `2`

and with modules:

# some.py
for x in [1, 2]:
    print(x)

# __main__
import some
print(some.x)  # 2

This is not users want in 99.9% of cases. There are other - functional - solutions which don't leave extra vars in the scope.

Moreover, for is already forbidden in class bodies.

@sobolevn sobolevn added the rule request Adding a new rule label Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule request Adding a new rule
Projects
None yet
Development

No branches or pull requests

1 participant