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
Using a method as a property is a common bug that can be detected by a type checker:
ifmy_obj.my_method:
...
I'd like to introduce a way to enable a check like truthy-bool (#10666) but limited to callable types.
Pitch
Users users might be hesitant to enable truthy-bool due to false positives. For callable types, there's a much higher degree of confidence that evaluating a callable as a boolean is unintentional.
The error message should be specific, e.g.
- error: Member "my_method" has type "function" which does not implement __bool__ or __len__ so it could always be true in boolean context + error: Member "my_method" is a method (are you trying to use it as a property?)
(happy to wordsmith this more, only trying to illustrate that I want it to be friendlier and more actionable)
The feature could be a separate error-code (thus splitting "callable evaluated in boolean context" from truthy-bool), or perhaps a way to configure truthy-bool to have a reduced scope? (Is there a common idiom for that?)
The text was updated successfully, but these errors were encountered:
FWIW, I recently added this check to pyright, and it was well received. This is a common programming error, and it can be detected with a negligible false positive rate. It would be great if mypy could detect and report this error.
Feature
Using a method as a property is a common bug that can be detected by a type checker:
I'd like to introduce a way to enable a check like
truthy-bool
(#10666) but limited to callable types.Pitch
Users users might be hesitant to enable
truthy-bool
due to false positives. For callable types, there's a much higher degree of confidence that evaluating a callable as a boolean is unintentional.truthy-bool
), or perhaps a way to configuretruthy-bool
to have a reduced scope? (Is there a common idiom for that?)The text was updated successfully, but these errors were encountered: