-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
Truthiness:from_expr has false negatives for certain expressions that are guaranteed to be truthy: generator expressions, lambda expressions, f-string interpolations containing byte strings (even if they are empty), and f-string interpolations containing debug text. This affects subprocess-popen-with-shell-equals-true (S602), call-with-shell-equals-true (S604), unix-command-wildcard-injection (S609), and expr-or-true (SIM222), at least. Example:
$ cat >truthiness_fn.py <<'# EOF'
import subprocess
subprocess.run("echo | xxd -p", shell=(x for x in ()))
print(bool(dict(shell=lambda: 0)["shell"]))
print(subprocess.check_output("echo chmod 777 truthiness_*.py", shell=f"{b""}"))
print(f"{""=}" or 0)
# EOF
$ python truthiness_fn.py
0a
True
b'chmod 777 truthiness_fn.py\n'
""=''
$ ruff --isolated check truthiness_fn.py --select S602,S604,S609,SIM222
All checks passed!Version
ruff 0.13.3 (188c0dc 2025-10-02)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working