pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.33k stars 1.14k forks source link

W0640 cell-var-from-loop false positive in Generator Comprehension of functions #10055

Open nhdsd opened 3 weeks ago

nhdsd commented 3 weeks ago

Bug description

test = (lambda : print(i) for i in range(10))
for call in test:
    call()

Command used

pylint -sn --disable=C0114 test.py

Pylint output

test.py:1:23: W0640: Cell variable i defined in loop (cell-var-from-loop)

Expected behavior

No W0640, since the generator do generate functions as expected instead of generating print(9) for 10 times.

Pylint version

pylint 3.3.1
astroid 3.3.5
Python 3.12.6 (tags/v3.12.6:a4a2d2b, Sep  6 2024, 20:11:23) [MSC v.1940 64 bit (AMD64)]