[issue20371] datetime.datetime.replace bypasses a subclass's __new__
Eugene Toder
report at bugs.python.org
Sun May 15 12:23:25 EDT 2016
Eugene Toder added the comment:
Yes, this is similar to my second approach. (You need to copy via __reduce__, because __copy__ my have been overriden to return self.)
The general problem with it, is that if a subclass is designed to be immutable (probably a common case here), it may not handle changing of its attributes well. Attributes will be readonly, so you can't support replace(derived_attr=newval). And while you can change base class' attributes under the covers, doing so may break subclass invariants. E.g. it may have cached hashcode or another property derived from other attributes.
There's also a smaller problem of figuring attribute names for positional arguments of replace() to support derived attributes.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20371>
_______________________________________
More information about the Python-bugs-list
mailing list