Skip to content

False positive for PLR1706 #9007

@UnknownPlatypus

Description

@UnknownPlatypus

Here is a minimal example for the issue I had with PLR1706 and the autofix using ruff v0.1.7.

-print(True and False or 2) # This print '2'
+print(False if True else 2) # This print 'False'

I used this command:

echo "print(True and False or 2)" > t.py
ruff check --select PLR1706 --isolated --preview --fix --unsafe-fixes t.py

Generally speaking, A and B or C is transformed into B if A else C but this is not equivalent when A is truphy and B is falsy because the first one returns C and the second returns B.

Let me know if I'm missing something.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions