This code snippet
def func(foo):
for _ in bar(foo for foo in [1]):
pass
triggers PLR1704 with ruff 0.5.2
$ ruff --version
ruff 0.5.2
$ ruff check --select PLR1704 test.py
test.py:2:26: PLR1704 Redefining argument with the local name `foo`
|
1 | def func(foo):
2 | for _ in bar(foo for foo in [1]):
| ^^^ PLR1704
3 | pass
|
Found 1 error.
which is wrong. From the python3 docs:
However, aside from the iterable expression in the leftmost for clause, the comprehension is executed in a separate implicitly nested scope. This ensures that names assigned to in the target list don’t “leak” into the enclosing scope.
This code snippet
triggers PLR1704 with ruff 0.5.2
which is wrong. From the python3 docs: