Message235773
| Author |
eddygeek |
| Recipients |
Andrew.Lutomirski, belopolsky, eddygeek, r.david.murray, yselivanov |
| Date |
2015年02月11日.22:19:30 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1423693171.23.0.425798587808.issue20371@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Here is a workaround for subclasses (2&3-compatible):
--- start code ---
class MyDate(datetime):
@classmethod
def fromDT(cls, d):
""" :type d: datetime """
return cls(d.year, d.month, d.day, d.hour, d.minute, d.second, d.microsecond, d.tzinfo)
def replace(self, *args, **kw):
""" :type other: datetime.timedelta
:rtype: MyDate """
return self.fromDT(super(MyDate, self).replace(*args, **kw))
--- end code ---
This is really a bug and not a misuse as datetime was specifically adapted to be subclassing-friendly. From a look at the (python) source, this seems to be the only bit that was forgotten.
The real fix is as per yselivanov comment [and no, this has nothing to do with pickle or copy AFAIK] |
|