Is there a rule to prefer explicit boolean checks ? #7941
Replies: 1 comment
|
Ruff does not currently have a direct equivalent of TypeScript ESLint's Python deliberately defines truth-value testing for many types, so a blanket rule requiring For the specific “optional value accidentally treated as false” class, a type checker is the better enforcement point. Enable strict optional checking in mypy or Pyright and use explicit |
Uh oh!
There was an error while loading. Please reload this page.
I have a rule in eslint which checks in Typescript when I am using truthy/falsey values - and forces me to provide a better condition.
This encourages people to be more explicit in their condition:
val = 0; if(val)should be changed to:val = 0; if(val !== null)I was wondering if there is something similar in
ruff?I am one of those people who prefers
if val is None:instead ofif not val::)The closest rule I have seen when I searched around was: https://docs.astral.sh/ruff/rules/compare-to-empty-string/
All reactions