In the .py implementation of datetime.replace (and date.replace and time.replace), the new datetime is created using the datetime type:
https://github.com/python/cpython/blob/master/Lib/datetime.py#L1578
But in the C source, it is created from type(self):
https://github.com/python/cpython/blob/master/Modules/_datetimemodule.c#L5046
I think the second should be the preferred behavior, so the datetime.py source should be updated to reflect that it's calling self.__class__(...) rather than datetime(...). I can prepare a PR if this would be desirable.
(That said, I'm not 100% clear under what circumstances the code in datetime.py is actually *used*, so I'm not sure how to write tests for it - is datetime.py essentially documentation, or is there a way to explicitly fall back to it?)
Per this issue on the pypy3 tracker:
https://bitbucket.org/pypy/pypy/issues/2635/datetimereplace-always-returns |