[Python-ideas] bool(datetime.time(0, 0))

Ethan Furman ethan at stoneleaf.us
Tue May 8 04:57:20 CEST 2012


Alexander Belopolsky wrote:
> On Mon, May 7, 2012 at 12:06 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
>> Does midnight warrant any special shortcut for testing?
> 
> I never needed it, but apparently it is common enough for users to
> notice an complain.  That's why I asked my original question: if
> you've seen a time variable been tested for truth, was it a bug that
> can be fixed by a change in time.__bool__ or a deliberate test for the
> midnight value?

Complain or rewrite to something reasonable, which is what I did.  Much 
better to have the built-in time behave properly than have users either 
work around it or constantly create new classes.

>> Especially one that is confusing to many readers.
> 
> I have a feeling that "readers" here are readers of documentation or
> tutorials rather than readers of actual code.  If this is the case, we
> can discuss how to improve the documentation and not change the
> behavior.

The behavior is broken.  Midnight is not False.

~Ethan~



More information about the Python-ideas mailing list