Skip to content

SIM114 fix ignores operator precedence #12732

@dscorbett

Description

@dscorbett

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixesRelated to suggested fixes for violations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions