On Sun, Dec 20, 2015 at 9:00 PM, Guido van Rossum <gu...@python.org> wrote:
> but I would really like to see a change in the repr of negative timedeltas: >> >> >>> timedelta(minutes=-1) >> datetime.timedelta(-1, 86340) >> >> And str() is not much better: >> >> >>> print(timedelta(minutes=-1)) >> -1 day, 23:59:00 >> >> The above does not qualify as a human readable representation IMO. >> > > I'm sure that one often catches people by surprise. However, I don't think > we can fix that one without also fixing the values of the attributes > I don't see why we have to change td.days for say td = timedelta(minutes=-1) if we change its repr to "timedelta(minutes=-1)". For me an important invariant is td == eval(repr(td)) which will be preserved. > -- in that example days is -1 and seconds is 86340 (which will *also* > catch people by surprise). And changing that would be much, much harder for > backwards compatibility reasons-- we'd have to set days to 0 and seconds to > -60, and suddenly we have a much murkier invariant, instead of the crisp > > 0 <= microseconds < 1000000 > 0 <= seconds < 60 > > (There is no such invariant for days -- they hold the sign bit.) > > In essence, you'd have to look at all three attributes to figure out on > which side of 0 is was (or think of the right way to do it, which is to > compare to timedelta(0)). I might still go for it, if it wasn't too late by > over a decade (as Tim says). >
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com