wemake-python-styleguide icon indicating copy to clipboard operation
wemake-python-styleguide copied to clipboard

Detect leaking `for` loops in `ClassDef` and `Module`

Open sobolevn opened this issue 3 years ago • 0 comments

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 avatar Jan 28 '22 06:01 sobolevn