Skip to content

Detect leaking for loops in ClassDef and Module #2340

@sobolevn

Description

@sobolevn

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions