Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUF046 fix introduces a syntax error when the cast expression contains a newline #15226

Closed
dscorbett opened this issue Jan 2, 2025 · 1 comment · Fixed by #15230
Closed
Assignees
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@dscorbett
Copy link

The fix for unnecessary-cast-to-int (RUF046) can crash Ruff in version 0.8.5 or change behavior when the cast expression contains a newline.

Here is a crash:

$ cat ruf046_1.py
int(1
& 1)

$ ruff check --isolated --preview --select RUF046 ruf046_1.py --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 `ruf046_1.py`, the rule codes RUF046, along with the `pyproject.toml` settings and executed command, we'd be very appreciative!

Here is a syntax error:

$ cat ruf046_2.py
int(1
* 1)

$ ruff check --isolated --preview --select RUF046 ruf046_2.py --fix
Found 1 error (1 fixed, 0 remaining).

$ cat ruf046_2.py
1
* 1

$ python ruf046_2.py
  File "ruf046_2.py", line 2
    * 1
    ^^^
SyntaxError: can't use starred expression here

Here is a runtime behavior change:

$ cat ruf046_3.py
x = int(1
+ 1)
print(x)

$ python ruf046_3.py
2

$ ruff check --isolated --preview --select RUF046 ruf046_3.py --fix
Found 1 error (1 fixed, 0 remaining).

$ cat ruf046_3.py
x = 1
+ 1
print(x)

$ python ruf046_3.py
1
@charliermarsh charliermarsh added the bug Something isn't working label Jan 2, 2025
@charliermarsh
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixes Related to suggested fixes for violations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants