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

Alexander Belopolsky alexander.belopolsky at gmail.com
Mon May 7 17:57:34 CEST 2012


On Mon, May 7, 2012 at 11:32 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Well, less occasional puzzlement is an improvement in itself.
> Unintuitive behaviour is always a risk for software quality.

I don't find the current behavior unintuitive.  It is common to
represent time of day as an integer (number of minutes or seconds
since midnight) or as a float (fraction of the 24-hour day).  In these
cases one gets bool(midnight) -> False as an artifact of the
representation.  For someone who wants to switch from typeless time
variables to datetime module types, bool(midnight) -> True may present
an extra hurdle.  One can improve the quality of his software by
avoiding constructs that he finds unintuitive.  For example, I claim
that in most cases a test for bool(t) is really a lazy version of the
more appropriate test for t is None.

Note that if we make bool(midnight) -> True, it will not be trivial to
faithfully reproduce the old behavior.  I want the proponents of the
change to try it before I explain why it is not easy.



More information about the Python-ideas mailing list