[Python-Dev] Change the repr for datetime.timedelta (was Re: Asynchronous context manager in a typical network server)

Guido van Rossum guido at python.org
Mon Dec 21 10:47:03 EST 2015


We're now thoroughly in python-ideas land.

On Mon, Dec 21, 2015 at 7:39 AM, Random832 <random832 at fastmail.com> wrote:

> Guido van Rossum <guido at python.org> writes:
> > 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 -- 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
>
> I don't really see it as murky:
>
> 0 <= abs(microseconds) < 1000000
> 0 <= abs(seconds) < 60
> (days <= 0) == (seconds <= 0) == (microseconds <= 0)
> (days >= 0) == (seconds >= 0) == (microseconds >= 0)
>
> The latter are more easily phrased in english as "all nonzero
> attributes have the same sign".  I think the current behavior is
> rather as if -1.1 were represented as "-2+.9".  The attributes
> probably can't be fixed without breaking backwards
> compatibility, though.  How about "-timedelta(0, 60)"?
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/guido%40python.org
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20151221/2e75f815/attachment.html>


More information about the Python-Dev mailing list