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

SIM114 fix ignores operator precedence #12732

Closed
dscorbett opened this issue Aug 7, 2024 · 1 comment · Fixed by #12737
Closed

SIM114 fix ignores operator precedence #12732

dscorbett opened this issue Aug 7, 2024 · 1 comment · Fixed by #12737
Assignees
Labels
bug Something isn't working fixes Related to suggested fixes for violations

Comments

@dscorbett
Copy link

The fix for SIM114 has a bug: it does not take operator precedence into account when combining two expressions with or. It should sometimes add parentheses around one expression or the other.

$ ruff --version
ruff 0.5.6
$ cat sim114.py
if False if True else False:
    print(1)
elif True:
    print(1)
else:
    print(2)
$ python sim114.py
1
$ ruff check --isolated --select SIM114 sim114.py --fix
Found 1 error (1 fixed, 0 remaining).
$ cat sim114.py
if False if True else False or True:
    print(1)
else:
    print(2)
$ python sim114.py
2
@charliermarsh charliermarsh added bug Something isn't working fixes Related to suggested fixes for violations labels Aug 7, 2024
@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