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

Alex Gaynor alex.gaynor at gmail.com
Wed Mar 5 22:10:12 CET 2014


Shai Berger <shai at ...> writes:

> 
> Hi all,
> 
> This is my first post here, following a recommendation from Alexander 
> Belopolsky to use this list, to try to convince the Python developers to 
> reopen a ticket. I am a long-time Python user, and a Django committer.
> 
> http://bugs.python.org/issue13936 is a complaint about the fact that midnight 


I strongly support fixing this issue. This behavior is so fundamentally
nonsensical that resolving it is worth the potential compatibility issues.

First, I'd like to dispense with the notion that ``if foo`` is somehow a bad
practice. This is an EXTREMELY common practice as a shorthand for checking for
None, a great many people consider it more idiomatic, this really isn't a place
to bikeshed that particlar idiom.

Now I'd like to address whether this is correct behavior: midnight is not a
special time. It does not differ from other times in magnitutde (as with a
container), it is not equivilant to the False value (as with 0). It is simply,
sometimes, represented as 00:00:00 (or 12:00:00!). The fact that it's
representation is composed of zeros no more makes it false than the point in
3-space at (0, 0, 0) is false. It's still a completely normal time, which in
no way distinguishes itself from any other.

I don't have a strong perspective on what the exact deprecation or breakage
cycle should like, but it's very clear to me that this behavior is nonsensical.
Out of a sample of half-a-dozen python programmers I've told about this, the
*universal* response was confusion and revulsion. I strongly suspect that the
majority of people writing ``if time_object`` have a bug in their code.

Alex



More information about the Python-ideas mailing list