On Mon, Sep 14, 2020 at 12:16:54PM +1000, Chris Angelico wrote:
> (How often do people even use "x is True"?)
Alas, that is a common idiom. For example:
It's possibly less common than it used to be now that PEP 8 warns
and so linters flag it. But I've seen it used by beginners and
experienced programmers alike.
There is some justification for it in the case that you want to test
specifically for the True instance, being much shorter than:
arbitrary_object == 1 and type(arbitrary_object) is bool
but many people have a mental blindspot and write:
if flag is True:
even when they know full well that flag is guaranteed to be a bool.
I know that sometimes I catch myself doing the same. I recently
rediscovered some old Pascal code I write in the 1990s and sure enough,
I have "if flag == true" in that too.
Of course we all know that it should be written:
if flag is True is True:
except I never know when to stop:
if flag is True is True is True is True is True is True is ...
Python-ideas mailing list -- email@example.com
To unsubscribe send an email to firstname.lastname@example.org
Message archived at https://email@example.com/message/45KTF4Z6EMXLSLN5PFXKS4QGIM3QEKGR/
Code of Conduct: http://python.org/psf/codeofconduct/