mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 20:31:57 +00:00
## Summary Part of #18972 This PR makes [for-loop-writes (FURB122)](https://docs.astral.sh/ruff/rules/for-loop-writes/#for-loop-writes-furb122)'s example error out-of-the-box. I also had to re-name the second case's variables to get both to raise at the same time, I suspect because of limitations in ruff's current semantic model. New names subject to bikeshedding, I just went with the least effort `_b` for binary suffix. [Old example](https://play.ruff.rs/19e8e47a-8058-4013-aef5-e9b5eab65962) ```py with Path("file").open("w") as f: for line in lines: f.write(line) with Path("file").open("wb") as f: for line in lines: f.write(line.encode()) ``` [New example](https://play.ruff.rs/e96b00e5-3c63-47c3-996d-dace420dd711) ```py from pathlib import Path with Path("file").open("w") as f: for line in lines: f.write(line) with Path("file").open("wb") as f_b: for line_b in lines_b: f_b.write(line_b.encode()) ``` The "Use instead" section was also modified similarly. ## Test Plan <!-- How was it tested? --> N/A, no functionality/tests affected |
||
|---|---|---|
| .. | ||
| resources | ||
| src | ||
| Cargo.toml | ||