[Python-ideas] Programming recommendations (PEP 8) and boolean values

Bruce Leban bruce at leapyear.org
Wed Aug 8 19:27:19 CEST 2012

On Wed, Aug 8, 2012 at 9:59 AM, Oleg Broytman <phd at phdru.name> wrote:

> On Thu, Aug 09, 2012 at 02:18:53AM +1000, Ben Finney <
> ben+python at benfinney.id.au> wrote:
> > What is a compelling use case for checking precisely for True or False?
>    To distinguish False and None for a tri-state variable that can have
> 3 values - "yes", "no" and "unspecified" - True, False and None in
> Python-speak.

I'd probably write that this way:

    if t is None:
        # not specified
    elif t:
        # true
        # false

on the other hand, if I had a variable that could be either a number or
True/False, I would probably write:

    if t is True:
    elif t is False:
        # use t as a number

just as I would for any other singleton value. Why does the PEP say that ==
True is preferred to is True?

--- Bruce
Follow me: http://www.twitter.com/Vroo http://www.vroospeak.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120808/fe21fe8c/attachment.html>

More information about the Python-ideas mailing list