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

Antoine Pitrou solipsis at pitrou.net
Mon May 7 19:03:05 CEST 2012


On Mon, 7 May 2012 12:57:47 -0400
Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
> On Mon, May 7, 2012 at 12:33 PM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> >> I have a feeling that "readers" here are readers of documentation or
> >> tutorials rather than readers of actual code.
> >
> > I was talking about readers of code. If I read code where boolean
> > testing of a time object is done, I wouldn't assume the intent is to
> > test for midnight (unless there's a comment indicating so).
> 
> I understand your hypothetical, but does such code actually exist in
> the wild or are we debating the number of angels than can dance at
> midnight?

Well, people complained about it, so they did try to write such code
and got bitten, right? Whether or not such code still exists "in the
wild" probably depends on how fast people get bitten and fix it :-)
But regardless, it's still an annoyance for people who write new code.

On the other hand, nobody chimed in to say that they relied on boolean
testing to check for midnight.

> As a matter of coding stile, I recommend avoiding use of datetime.time
> objects.  More often than not, time values are meaningless when
> detached from the date value.

I tend to agree.

> Note that since date range starts at date(1,1,1) we don't have the
> same problem with the date or datetime objects.

That's fortunate.

Regards

Antoine.





More information about the Python-ideas mailing list