.. _cell-var-from-loop:

cell-var-from-loop / W0640
==========================

**Message emitted:**

Cell variable %s defined in loop

**Description:**

*A variable used in a closure is defined in a loop. This will result in all closures using the same value for the closed-over variable.*

**Problematic code:**

.. literalinclude:: /data/messages/c/cell-var-from-loop/bad.py
   :language: python

**Correct code:**

.. literalinclude:: /data/messages/c/cell-var-from-loop/good.py
   :language: python


**Related links:**

- `Stackoverflow discussion <https://stackoverflow.com/questions/25314547/cell-var-from-loop-warning-from-pylint>`_

Created by the `variables <https://github.com/PyCQA/pylint/blob/main/pylint/checkers/variables.py>`__ checker.