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

Chris Angelico rosuav at gmail.com
Tue Dec 22 03:49:13 EST 2015


On Tue, Dec 22, 2015 at 7:39 PM, Victor Stinner
<victor.stinner at gmail.com> wrote:
> Le lundi 21 décembre 2015, Guido van Rossum <gvanrossum at gmail.com> a écrit :
>>
>> I still think the repr change to use keywords has a good chance for 3.6.
>
> repr() with keywords is called a method, no? Like isoformat()
>

Not keyword arguments - the proposal is to change the repr from one
format to another. Currently, the repr indicates a constructor call
using positional arguments:

>>> datetime.timedelta(1)
datetime.timedelta(1)
>>> datetime.timedelta(1,2)
datetime.timedelta(1, 2)
>>> datetime.timedelta(1,2,3)
datetime.timedelta(1, 2, 3)
>>> datetime.timedelta(1,2,3,4)
datetime.timedelta(1, 2, 4003)

The proposal is to make it show keyword args instead:

>>> datetime.timedelta(days=1)
datetime.timedelta(days=1)
>>> datetime.timedelta(days=1,seconds=2)
datetime.timedelta(days=1, seconds=2)
>>> datetime.timedelta(days=1,seconds=2,microseconds=3)
datetime.timedelta(days=1, seconds=2, microseconds=3)
>>> datetime.timedelta(days=1,seconds=2,microseconds=3,milliseconds=4)
datetime.timedelta(days=1, seconds=2, microseconds=4003)

ChrisA


More information about the Python-Dev mailing list