[Python-ideas] Please reconsider the Boolean evaluation of midnight

Donald Stufft donald at stufft.io
Thu Mar 6 09:50:46 CET 2014


On Mar 6, 2014, at 3:46 AM, Donald Stufft <donald at stufft.io> wrote:

> So to be specific, I think using ``if time_or_something_that_may_be_none:``
> is always wrong, but I think the like hood for user confusion and hard to
> reproduce bugs are far greater when a more or less arbitrary time (especially
> in the sense of aware times) evaluates as false when a user omits the
> ``is None`` than when someone expects ``if time:`` to be false at midnight.

I realized this was ambiguous, I always consider directly checking the boolean
value of a time object as wrong, as I don’t believe time has any True/False implications
in it. This includes both using ``if thing:`` to detect None and using ``if thing:`` to
detect midnight. I just think the ``if thing:`` to detect None case is more common
and also more difficult to detect when you have a bug because of it and more
surprising behavior than the other case.

-----------------
Donald Stufft
PGP: 0x6E3CBCE93372DCFA // 7C6B 7C5D 5E2B 6356 A926 F04F 6E3C BCE9 3372 DCFA

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140306/4b6b5934/attachment-0001.sig>


More information about the Python-ideas mailing list