[Python-ideas] True and False are singletons

Stephan Hoyer shoyer at gmail.com
Mon Mar 18 18:52:33 EDT 2019


On Mon, Mar 18, 2019 at 3:42 PM Greg Ewing <greg.ewing at canterbury.ac.nz>
wrote:

> Tim Delaney wrote:
> > 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.
>
> I don't think you can infer that. It could equally well be someone who's
> *not* familiar with Python truth rules and really just meant "if x".
> Or someone who's unfamiliar with booleans in general and thinks that
> every "if" statement has to have a comparison in it.
>

Regardless of whether it's idiomatic Python code or not, this pattern ("is
True:") can be found all over Python code in the wild.

If CPython ever broke this guarantee, quite a few popular libraries on pypi
would be broken, including pandas, sqlalchemy, attrs and even Python's own
standard library:
https://github.com/python/cpython/blob/c183444f7e2640b054956474d71aae6e8d31a543/Lib/textwrap.py#L175
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190318/23527c7c/attachment.html>


More information about the Python-ideas mailing list