-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Description
Summary
Truthiness::from_expr assumes that all values are iterable and that truthy is the same as non-empty, causing false positives in expr-or-true (SIM222) and expr-and-false (SIM223). Examples:
$ cat >sim22.py <<'# EOF'
print(tuple(t"") or True)
print(tuple(t"") and False)
try:
print(tuple(0) or True)
except TypeError as e:
print(e)
try:
print(tuple(1) and False)
except TypeError as e:
print(e)
# EOF
$ python3.14 sim22.py
True
()
'int' object is not iterable
'int' object is not iterable
$ ruff --isolated check sim22.py --select SIM222,SIM223 --unsafe-fixes --fix
Found 4 errors (4 fixed, 0 remaining).
$ cat sim22.py
print(tuple(t""))
print(False)
try:
print(True)
except TypeError as e:
print(e)
try:
print(False)
except TypeError as e:
print(e)
$ python3.14 sim22.py
()
False
True
FalseVersion
ruff 0.14.5 (87dafb8 2025-11-13)
Metadata
Metadata
Assignees
Labels
No labels