Closed
Description
Feature
Using a method as a property is a common bug that can be detected by a type checker:
if my_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.
(happy to wordsmith this more, only trying to illustrate that I want it to be friendlier and more actionable)
- 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?)
- The feature could be a separate error-code (thus splitting "callable evaluated in boolean context" from
truthy-bool
), or perhaps a way to configuretruthy-bool
to have a reduced scope? (Is there a common idiom for that?)