---
source: crates/ruff_linter/src/rules/pylint/mod.rs
---
PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target
 --> redefined_loop_name.py:6:9
  |
4 | # For -> for, variable reused
5 | for i in []:
6 |     for i in []:  # error
  |         ^
7 |         pass
  |

PLW2901 `with` statement variable `i` overwritten by `for` loop target
  --> redefined_loop_name.py:11:9
   |
 9 | # With -> for, variable reused
10 | with None as i:
11 |     for i in []:  # error
   |         ^
12 |         pass
   |

PLW2901 `for` loop variable `i` overwritten by `with` statement target
  --> redefined_loop_name.py:16:18
   |
14 | # For -> with, variable reused
15 | for i in []:
16 |     with None as i:  # error
   |                  ^
17 |         pass
   |

PLW2901 Outer `with` statement variable `i` overwritten by inner `with` statement target
  --> redefined_loop_name.py:21:18
   |
19 | # With -> with, variable reused
20 | with None as i:
21 |     with None as i:  # error
   |                  ^
22 |         pass
   |

PLW2901 Outer `with` statement variable `i` overwritten by inner `with` statement target
  --> redefined_loop_name.py:36:18
   |
34 | # Async with -> with, variable reused
35 | async with None as i:
36 |     with None as i:  # error
   |                  ^
37 |         pass
   |

PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target
  --> redefined_loop_name.py:46:9
   |
44 | # Async for -> for, variable reused
45 | async for i in []:
46 |     for i in []:  # error
   |         ^
47 |         pass
   |

PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target
  --> redefined_loop_name.py:52:13
   |
50 | for i in []:
51 |     for j in []:
52 |         for i in []:  # error
   |             ^
53 |             pass
   |

PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target
  --> redefined_loop_name.py:58:13
   |
56 | for i in []:
57 |     for j in []:
58 |         for i in []:  # error
   |             ^
59 |             for j in []:  # error
60 |                 pass
   |

PLW2901 Outer `for` loop variable `j` overwritten by inner `for` loop target
  --> redefined_loop_name.py:59:17
   |
57 |     for j in []:
58 |         for i in []:  # error
59 |             for j in []:  # error
   |                 ^
60 |                 pass
   |

PLW2901 `for` loop variable `i` overwritten by assignment target
  --> redefined_loop_name.py:67:5
   |
65 |     i = cast(int, i)
66 |     i = typing.cast(int, i)
67 |     i = 5  # error
   |     ^
68 |
69 | # For -> augmented assignment
   |

PLW2901 `for` loop variable `i` overwritten by assignment target
  --> redefined_loop_name.py:71:5
   |
69 | # For -> augmented assignment
70 | for i in []:
71 |     i += 5  # error
   |     ^
72 |
73 | # For -> annotated assignment
   |

PLW2901 `for` loop variable `i` overwritten by assignment target
  --> redefined_loop_name.py:75:5
   |
73 | # For -> annotated assignment
74 | for i in []:
75 |     i: int = 5  # error
   |     ^
76 |
77 | # For -> annotated assignment without value
   |

PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target
  --> redefined_loop_name.py:83:9
   |
81 | # Async for -> for, variable reused
82 | async for i in []:
83 |     for i in []:  # error
   |         ^
84 |         pass
   |

PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target
  --> redefined_loop_name.py:88:15
   |
86 | # For -> async for, variable reused
87 | for i in []:
88 |     async for i in []:  # error
   |               ^
89 |         pass
   |

PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target
  --> redefined_loop_name.py:93:9
   |
91 | # For -> for, outer loop unpacks tuple
92 | for i, j in enumerate([]):
93 |     for i in []:  # error
   |         ^
94 |         pass
   |

PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target
  --> redefined_loop_name.py:98:9
   |
96 | # For -> for, inner loop unpacks tuple
97 | for i in []:
98 |     for i, j in enumerate([]):  # error
   |         ^
99 |         pass
   |

PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target
   --> redefined_loop_name.py:103:9
    |
101 | # For -> for, both loops unpack tuple
102 | for (i, (j, k)) in []:
103 |     for i, j in enumerate([]):  # two errors
    |         ^
104 |         pass
    |

PLW2901 Outer `for` loop variable `j` overwritten by inner `for` loop target
   --> redefined_loop_name.py:103:12
    |
101 | # For -> for, both loops unpack tuple
102 | for (i, (j, k)) in []:
103 |     for i, j in enumerate([]):  # two errors
    |            ^
104 |         pass
    |

PLW2901 Outer `for` loop variable `j` overwritten by inner `for` loop target
   --> redefined_loop_name.py:120:9
    |
118 | # For -> for, outer loop unpacks with asterisk
119 | for i, *j in []:
120 |     for j in []:  # error
    |         ^
121 |         pass
    |

PLW2901 `for` loop variable `i` overwritten by assignment target
   --> redefined_loop_name.py:137:13
    |
135 |     def f():
136 |         for i in []:  # no error
137 |             i = 2  # error
    |             ^
138 |
139 | # For -> class definition -> for -> for
    |

PLW2901 Outer `for` loop variable `i` overwritten by inner `for` loop target
   --> redefined_loop_name.py:143:17
    |
141 |     class A:
142 |         for i in []:  # no error
143 |             for i in []:  # error
    |                 ^
144 |                 pass
    |

PLW2901 `for` loop variable `a[0]` overwritten by assignment target
   --> redefined_loop_name.py:158:5
    |
156 | # For target with subscript -> assignment
157 | for a[0] in []:
158 |     a[0] = 2  # error
    |     ^^^^
159 |     a[1] = 2  # no error
    |

PLW2901 `for` loop variable `a['i']` overwritten by assignment target
   --> redefined_loop_name.py:163:5
    |
161 | # For target with subscript -> assignment
162 | for a['i'] in []:
163 |     a['i'] = 2  # error
    |     ^^^^^^
164 |     a['j'] = 2  # no error
    |

PLW2901 `for` loop variable `a.i` overwritten by assignment target
   --> redefined_loop_name.py:168:5
    |
166 | # For target with attribute -> assignment
167 | for a.i in []:
168 |     a.i = 2  # error
    |     ^^^
169 |     a.j = 2  # no error
    |

PLW2901 `for` loop variable `a.i.j` overwritten by assignment target
   --> redefined_loop_name.py:173:5
    |
171 | # For target with double nested attribute -> assignment
172 | for a.i.j in []:
173 |     a.i.j = 2  # error
    |     ^^^^^
174 |     a.j.i = 2  # no error
    |

PLW2901 `for` loop variable `a.i` overwritten by assignment target
   --> redefined_loop_name.py:178:5
    |
176 | # For target with attribute -> assignment with different spacing
177 | for a.i in []:
178 |     a. i = 2  # error
    |     ^^^^
179 | for a. i in []:
180 |     a.i = 2  # error
    |

PLW2901 `for` loop variable `a.i` overwritten by assignment target
   --> redefined_loop_name.py:180:5
    |
178 |     a. i = 2  # error
179 | for a. i in []:
180 |     a.i = 2  # error
    |     ^^^
    |
