[issue30302] Improve .__repr__ implementation for datetime.datetime.timedelta

2017-05-07 Thread Utkarsh Upadhyay

Utkarsh Upadhyay added the comment:

> The drawback is that this change increases the length of the repr.

I would argue that it is a reasonable trade-off given the increase in ease of 
understanding. 

I know that this is a weak argument, but, keywords are not without precedent. 
Consider the comically more verbose example:

import time
time.gmtime(1121871596)
# time.struct_time(tm_year=2005, tm_mon=7, tm_mday=20, tm_hour=14, tm_min=59, 
tm_sec=56, tm_wday=2, tm_yday=201, tm_isdst=0)


> datetime.datetime has more arguments, and its repr doesn't use keywords.

I think that guessing the meaning of values is much harder when it comes to 
timedelta.


> Users of datetime.timedelta know what arguments mean. If they don't know they 
> always can look in the documentation or builtin help.

I created the issue after ... a friend ... spent an embarrassing amount of time 
debugging because he thought that the third argument represented milliseconds 
and not microseconds. <_<

I could, of course, tell him:

> In the face of ambiguity, resist the temptation to guess.

But he could retort:

> Explicit is better than implicit.

and 

> Readability counts.

I think he has a point.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30302] Improve .__repr__ implementation for datetime.datetime.timedelta

2017-05-07 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The drawback is that this change increases the length of the repr. If you 
output few values in a row (for example output the repr of a list of 
timedeltas), this makes the output less readable.

Users of datetime.timedelta know what arguments mean. If they don't know they 
always can look in the documentation or builtin help.

datetime.datetime has more arguments, and its repr doesn't use keywords.

--
nosy: +belopolsky, serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30302] Improve .__repr__ implementation for datetime.datetime.timedelta

2017-05-07 Thread Utkarsh Upadhyay

Changes by Utkarsh Upadhyay :


--
pull_requests: +1595

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30302] Improve .__repr__ implementation for datetime.datetime.timedelta

2017-05-07 Thread Utkarsh Upadhyay

New submission from Utkarsh Upadhyay:

Currently, the default implementation of datetime.datetime.__repr__ (the 
default output string produced at the console/IPython) gives a rather cryptic 
output:

from datetime import datetime as D
D.fromtimestamp(1390953543.1) - D.fromtimestamp(1121871596)
# datetime.timedelta(3114, 28747, 10)

For the uninitiated, it is not obvious that the numeric values here are `days`, 
`seconds` and `microsecond` respectively.

Would there be any pushback against changing this to:

# datetime.timedelta(days=3114, seconds=28747, microseconds=10)

?

--
components: Library (Lib)
messages: 293212
nosy: musically_ut
priority: normal
severity: normal
status: open
title: Improve .__repr__ implementation for datetime.datetime.timedelta
type: enhancement
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com