Replies: 1 comment 5 replies
-
This pattern has legitimate uses and is quite common in Python, so it's not a rule that could be enabled by default, even in strict mode. In general, I don't like adding rules that cannot be enabled by default in strict mode because they are difficult for pyright users to discover and therefore are rarely used. This situation is also not a type violation, which means that it's not obvious that it's a rule a type checker should be enforcing. There is a precedent for pyright supporting rules that are not type violations but do require type analysis (and are therefore difficult for linters to implement). These rules all involve cases where 1) there's a relatively low chance of a false positive and 2) a reasonably high likelihood of an actual bug. The This particular check doesn't seem to meet this bar. 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. For comparison, the typescript compiler (which is effectively a static type checker) does not provide an option like the one you're proposing, but eslint (which is more akin to a ruff) does. |
Beta Was this translation helpful? Give feedback.
-
I've started a discussion on this on Ruff's GitHub, but I'm also curious if this is something that Pyright might consider implementing.
I'd like to ban implicit truthy/falsy checks in our codebase, to avoid common bugs like this:
More details and broader rationale in this discussion: astral-sh/ruff#8757
@erictraut – what's you view on this? Does this feel like a rule Pyright might implement? (I would imagine it would be optional even in strict mode.)
On one hand it feels opinionated enough to be a linter rule, on the other hand I have a hunch it might be easier and more robust to implement in a type checker (feels a bit similar to e.g.
reportUnnecessaryComparison
).Beta Was this translation helpful? Give feedback.
All reactions