Description
Current problem
I was wondering about the singleton-comparison
checker I worked on a bit a while ago.
it suggests you to compare singleton using is
instead of ==
which is fine, for example for none
.
But why should we use it with True
and False
? since comparison returns a Boolean anyway.
Desired solution
For the following code:
if expr == True
or if expr is True
The checker should suggest to modify it to if expr
.
for false, both if expr == False
and if expr is False
should be modified to if not expr
.
Additional context
There is some controversy about this matter as can be seen in this thread:
https://stackoverflow.com/questions/27276610/boolean-identity-true-vs-is-true
Since it assumes an object has its __bool__
implemented although I believe that this is most probably the case in any class, since it comes with a default method that returns True
.
See this thread for some (maybe engineered) corner cases:
https://stackoverflow.com/questions/64913140/is-there-a-way-to-remove-bool-method-from-a-class