-
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 violationspreviewRelated to preview mode featuresRelated to preview mode features
Description
The fix for unnecessary-round (RUF057) in Ruff 0.9.2 can introduce a syntax error or change behavior when the argument to round contains a newline.
Here is a crash:
$ cat ruf057_1.py
round(-
1)
$ ruff --isolated check --fix --preview --select RUF057 ruf057_1.py
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 `ruf057_1.py`, the rule codes RUF057, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!
ruf057_1.py:1:1: RUF057 Value being rounded is already an integer
|
1 | / round(-
2 | | 1)
| |__^ RUF057
|
= help: Remove unnecessary `round` call
Found 1 error.
[*] 1 fixable with the `--fix` option.Here is a syntax error:
$ cat ruf057_2.py
round(1
* 1)
$ ruff --isolated check --fix --preview --select RUF057 ruf057_2.py
Found 1 error (1 fixed, 0 remaining).
$ cat ruf057_2.py
1
* 1
$ python ruf057_2.py
File "ruf057_2.py", line 2
* 1
^^^
SyntaxError: can't use starred expression hereHere is a runtime behavior change:
$ cat ruf057_3.py
x = round(1
+ 1)
print(x)
$ python ruf057_3.py
2
$ ruff --isolated check --fix --preview --select RUF057 ruf057_3.py
Found 1 error (1 fixed, 0 remaining).
$ cat ruf057_3.py
x = 1
+ 1
print(x)
$ python ruf057_3.py
1Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violationspreviewRelated to preview mode featuresRelated to preview mode features