[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
Sun Dec 20 22:39:59 EST 2015
On Sun, Dec 20, 2015 at 7:25 PM, Alexander Belopolsky <
alexander.belopolsky at gmail.com> wrote:
>
> On Sun, Dec 20, 2015 at 9:00 PM, Guido van Rossum <guido at 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.
>
Then please just trust me. If the repr() shows different numbers than the
attributes things are worse than now. People will casually look at the
repr() and assume they've seen what the attributes will return, and spend
hours debugging code that relies on that incorrect assumption.
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20151220/5dda2533/attachment.html>
More information about the Python-Dev
mailing list