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

Donald Stufft donald at stufft.io
Thu Mar 6 00:28:12 CET 2014


On Mar 5, 2014, at 6:23 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:

> Paul Moore wrote:
>> Agreed that the odd behaviour of time in a
>> boolean context is why this whole class of bugs exists, but it's only
>> a subclass if the wider problem that people shouldn't truth-test
>> values without thinking
> 
> But this bites you even if you *do* think, because there
> is no reason to suspect that any time value should be
> regarded as false, especially since the docs make no
> mention of this.
> 
> Note that "fix the docs" is *not* the right response to
> this, IMO -- that would just be enshrining a bad design
> decision. Better to fix the design while we have the
> chance.
> 
> -- 
> Greg
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

The docs do mention it:

> in Boolean contexts, a time object is considered to be true if and only
> if, after converting it to minutes and subtracting utcoffset() (or 0 if that’s
> None), the result is non-zero.

-----------------
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/20140305/937e362f/attachment.sig>


More information about the Python-ideas mailing list