-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violationshelp wantedContributions especially welcomeContributions especially welcome
Description
Description
Fixing for-loop-writes (FURB122) fails in Ruff 0.9.4 when the iterable expression is an unparenthesized tuple.
If the argument to write is the loop target, the modified code raises an error at runtime.
$ cat >furb122_1.py <<'# EOF'
with open("furb122.txt", "w") as f:
for char in "a", "b":
f.write(char)
# EOF
$ ruff --isolated check --preview --select FURB122 furb122_1.py --unsafe-fixes --fix
Found 1 error (1 fixed, 0 remaining).
$ cat furb122_1.py
with open("furb122.txt", "w") as f:
f.writelines("a", "b")
$ python furb122_1.py
Traceback (most recent call last):
File "furb122_1.py", line 2, in <module>
f.writelines("a", "b")
TypeError: _IOBase.writelines() takes exactly one argument (2 given)Otherwise, the fix introduces a syntax error.
$ cat >furb122_2.py <<'# EOF'
with open("furb122.txt", "w") as f:
for char in "a", "b":
f.write(f"{char}")
# EOF
$ ruff --isolated check --preview --select FURB122 furb122_2.py --unsafe-fixes --diff
error: Fix introduced a syntax error. Reverting all changes.
This indicates a bug in Ruff. If you could open an issue at:
https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D
...quoting the contents of `furb122_2.py`, the rule codes FURB122, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violationshelp wantedContributions especially welcomeContributions especially welcome