wemake-python-styleguide
wemake-python-styleguide copied to clipboard
Detect leaking `for` loops in `ClassDef` and `Module`
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.