Why this matters
Shadowing hides bugs and makes code hard to reason about.
Use distinct variable names across scopes; never reuse the outer loop variable in inner loops or comprehensions.
Shadowing hides bugs and makes code hard to reason about.
Side-by-side examples engineers can pattern-match during review.
for i in range(3):
for i in range(2):
pass # shadows outer ifor i in range(3):
for j in range(2):
pass[i for i in items for i in i.children][(p, c) for p in items for c in p.children]From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.