YADTR (Yet Another DateTime Rant)

Roy Smith roy at panix.com
Thu Mar 27 20:29:17 EDT 2014


In article <5334b747$0$29994$c3e8da3$5496439d at news.astraweb.com>,
 Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> On Thu, 27 Mar 2014 08:52:24 -0400, Roy Smith wrote:
> 
> > In article <mailman.8613.1395917059.18130.python-list at python.org>,
> >  Chris Angelico <rosuav at gmail.com> wrote:
> >> It's not "equally braindead", it follows a simple and logical rule:
> >> Only the day portion is negative.
> > 
> > Simple and logical, yes.  But also entirely braindead.
> 
> Do you think it is "braindead" for __str__ to return something which 
> follows the internal representation of the object?

Yes.  The whole idea of OOD is to decouple internal representation from 
external behavior.

> > Give ma a real-life situation where you would want such behavior.
> 
> Easy -- I'm debugging timedelta routines, and I want to easily see that 
> the timedeltas calculated match what I expect them to be when I print 
> them. The quickest, easiest and simplest way is for str(timedelta) to 
> follow the internal representation.

That's what __repr__() is for.
 
> Oh look, that's exactly what the docs say:
> 
> "String representations of timedelta objects are normalized similarly to 
> their internal representation. This leads to somewhat unusual results for 
> negative timedeltas."

Yes, I know that's what the docs say.  That's why it's not an 
implementation bug.  It's a design bug :-)



More information about the Python-list mailing list