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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


