[New-bugs-announce] [issue31222] datetime.py implementation of .replace inconsistent with C implementation

Paul G report at bugs.python.org
Wed Aug 16 13:01:45 EDT 2017

New submission from Paul G:

In the .py implementation of datetime.replace (and date.replace and time.replace), the new datetime is created using the datetime type:


But in the C source, it is created from type(self):


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:


components: Interpreter Core
messages: 300377
nosy: p-ganssle
priority: normal
severity: normal
status: open
title: datetime.py implementation of .replace inconsistent with C implementation
versions: Python 3.5, Python 3.6, Python 3.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list