[issue9169] Deprecate use of more than 3 positional arguments in timedelta constructor
report at bugs.python.org
Tue Jul 6 16:29:01 CEST 2010
Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:
> As a matter of good style, though, I'd still like to see all uses of
> timedelta in the standard library and documentation use the keywords
> explicitly ...
It is a bit of a shame, but there are exactly 3 places using timedelta in stdlib:
Lib/_strptime.py:492: tzdelta = datetime_timedelta(seconds=gmtoff)
Lib/calendar.py:160: date -= datetime.timedelta(days=days)
Lib/calendar.py:161: oneday = datetime.timedelta(days=1)
The later two uses of keywords I don't necessarily approve, particularly timedelta(days=days). I find timedelta(n) meaning n days fairly easy to remember. Two arguments, timedelta(days, secs) is borderline. I would approve it if the meaning is clear from context as in
MINUTE = timedelta(0, 60)
or from the the argument name as in timedelta(0, seconds).
I would certainly reject the abominations like
FIVE_MINUTES = datetime.timedelta(0, 0, 0, 0, 5)
in any code review.
I checked datetime.rst and it looks like it only uses positional arguments for timedelta(0), which is pretty uncontroversial and in output displays.
status: pending -> open
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list