[issue2267] datetime.datetime operator methods are not subclass-friendly
Alexander Belopolsky
report at bugs.python.org
Tue Mar 11 01:29:25 CET 2008
Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:
Invoking a subclass's constructor is only an issue when subclass adds
data members. In this case, arithmetic methods need to be overridden.
Note that my patch does not make __add__ and friends invoke subclass'
constructor, only subclass' tp_alloc.
Existing code already does this in some cases. For example,
>>> class d(datetime): pass
...
>>> d.strptime('20080310', '%Y%m%d')
d(2008, 3, 10, 0, 0)
>>> d.now()
d(2008, 3, 10, 20, 27, 6, 303147)
I think date/datetime present a particularly compelling case for
departing from the general rule. These classes are minimal by design
and need to be extended in many applications.
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2267>
__________________________________
More information about the Python-bugs-list
mailing list