You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm thinking of writing a new lint rule for Ruff, to disallow implicit-cast-to-bool.
That is, to disallow statements like foo = None; if foo:. Our team finds that these are a common source of bugs. For example if foo: Optional[int] then was the intention for if foo: to not trigger on just foo = None, or did the author want it to not trigger on foo = 0 as well?
As per the contributing guidelines I'm opening an issue to see if this is a rule that is in-scope for Ruff?
In terms of technical feasibility of implementing this -- to what extent do the ruff internals track the types of each variable?
The text was updated successfully, but these errors were encountered:
Hy. I haven't checked if Ruff already has a similar rule and I'm not familiar enough with Python to know if that's a rule that Ruff should support (@AlexWaygood knows more) but I think this isn't a rule that we can add until #1774 is done because it's not a rule that we want to enable by default and many users are using --select ALL
Big ➕1️⃣ to a rule like this! FWIW, I created a discussion about it here: #8757 (comment)
Alternative option: Typechecker
As a sidenote, if you want to, you could also support this discussion where I pitched this rule in Pyright: microsoft/pyright#6488 (comment)
I think implementing this in the typechecker would be much more reliable.
Pyright is known to implement opinionated rules like this (e.g. unnecessary comparison), but the maintainer is currently not convinced about this one:
I'm not convinced that it represents a sufficiently common source of bugs to merit adding such a rule, but I could perhaps be persuaded with some additional evidence.
I'm thinking of writing a new lint rule for Ruff, to disallow implicit-cast-to-bool.
That is, to disallow statements like
foo = None; if foo:
. Our team finds that these are a common source of bugs. For example iffoo: Optional[int]
then was the intention forif foo:
to not trigger on justfoo = None
, or did the author want it to not trigger onfoo = 0
as well?As per the contributing guidelines I'm opening an issue to see if this is a rule that is in-scope for Ruff?
In terms of technical feasibility of implementing this -- to what extent do the ruff internals track the types of each variable?
The text was updated successfully, but these errors were encountered: