[Python-ideas] True and False are singletons

Tim Delaney timothy.c.delaney at gmail.com
Mon Mar 18 18:09:13 EDT 2019

On Tue, 19 Mar 2019 at 08:42, Greg Ewing <greg.ewing at canterbury.ac.nz>

> Oleg Broytman wrote:
> >    Three-way (tri state) checkbox. You have to distinguish False and
> > None if the possible valuse are None, False and True.
> In that case the conventional way to write it would be
>      if settings[MY_KEY] == True:
>          ...
> It's not a major issue, but I get nervous when I see code
> that assumes True and False are unique, because things
> weren't always that way.

I would argue the opposite - the use of "is" shows a clear knowledge that
True and False are each a singleton and the author explicitly intended to
use them that way. Use of == in the same context is more likely to indicate
a programmer who is unfamiliar with Python's truth rules.

Tim Delaney
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190319/9b28d852/attachment.html>

More information about the Python-ideas mailing list