[Python-ideas] True and False are singletons

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Mar 18 17:12:09 EDT 2019

Richard Damon wrote:
> On 3/18/19 7:27 AM, Greg Ewing wrote:
>>    if settings[MY_KEY]:
>>        ...
> That means something VERY different.

Yes, but there needs to be justification for why the difference
matters and why this particular way is the best way to deal
with it.

Whenever you write 'x is True' or 'x == True', you are putting
a burden on all code that assigns to x to ensure that the
value is actually an instance of bool rather than just a
truthy or falsy value. That's an unusual requiremebt that
can lead to obscure bugs.

In the tri-state example, the way I would do it is to guard
uses of it with 'if x is not None' and then treat the other
values as truthy or falsy.


More information about the Python-ideas mailing list