[New-bugs-announce] [issue9169] Deprecate use of more than 3 positional arguments in timedelta constructor

Alexander Belopolsky report at bugs.python.org
Mon Jul 5 19:07:30 CEST 2010


New submission from Alexander Belopolsky <belopolsky at users.sourceforge.net>:

Prior to r82454, python implementation of timedelta had the following comment:

class timedelta:
     def __new__(cls, days=0, seconds=0, microseconds=0,
                 # XXX The following should only be used as keyword args:	 
                 milliseconds=0, minutes=0, hours=0, weeks=0):


This suggests that these arguments were intended to be keyword only, but at the time there was no language support for that.

In 3.x, the above can be rewritten as

class timedelta:
     def __new__(cls, days=0, seconds=0, microseconds=0, *,
                 milliseconds=0, minutes=0, hours=0, weeks=0):

to require that milliseconds, minutes, etc, be used only positionally.

This would be a backward incompatible change, so it would need to go through a deprecation process, but I think someone writing

HOUR = timedelta(0, 0, 0, 0, 0, 1)

or

WEEK = timedelta(0, 0, 0, 0, 0, 0, 1)

deserves a deprecation warning.

----------
assignee: belopolsky
messages: 109339
nosy: belopolsky, mark.dickinson, pitrou, tim_one
priority: normal
severity: normal
stage: unit test needed
status: open
title: Deprecate use of more than 3 positional arguments in timedelta constructor
type: feature request
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9169>
_______________________________________


More information about the New-bugs-announce mailing list