astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
31.48k stars 1.06k forks source link

Invalid fix for PLE1141 #13343

Open martinlehoux opened 2 weeks ago

martinlehoux commented 2 weeks ago

for n, c in d: print(n, c)


autofixed to 

```py
d: dict[tuple[int, str], bool] = {}
d[1, "a"] = True

for n, c in d.items():
    print(n, c)
MichaReiser commented 2 weeks ago

To summarize the issue:

It's questionable if PLE1141 should be raised for your example because the code only iterates over the keys. Pylint had a similar issue a long time ago https://github.com/pylint-dev/pylint/issues/3283

martinlehoux commented 2 weeks ago

Yes exactly. But as I understand it, ruff doesn't use type checking, so it would be difficult to say that the key is a tuple.