-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violations
Description
The fix for yoda-conditions (SIM300) changes the program’s behavior in Ruff 0.8.1 when the two operands have side effects. The fix should be suppressed or marked unsafe when that happens.
This can happen when the first operand is a non-empty dictionary display, which is always marked as probably constant regardless of its contents.
$ cat sim300_1.py
{"": print(1)} == print(2)
$ python sim300_1.py
1
2
$ ruff check --isolated --select SIM300 sim300_1.py --fix
Found 1 error (1 fixed, 0 remaining).
$ cat sim300_1.py
print(2) == {"": print(1)}
$ python sim300_1.py
2
1It can also happen when the first operand is an all-caps attribute.
$ cat sim300_2.py
class C:
def __getattr__(self, name):
print(name)
return name
C().A == print('B')
$ python sim300_2.py
A
B
$ ruff check --isolated --select SIM300 sim300_2.py --fix
Found 1 error (1 fixed, 0 remaining).
$ cat sim300_2.py
class C:
def __getattr__(self, name):
print(name)
return name
print('B') == C().A
$ python sim300_2.py
B
AThere might be other cases.
thejoeejoee
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixesRelated to suggested fixes for violationsRelated to suggested fixes for violations