[pypy-issue] Issue #2635: datetime.replace always returns datetime.datetime in pypy3 (pypy/pypy)
Paul G
issues-reply at bitbucket.org
Wed Aug 16 12:36:03 EDT 2017
New issue 2635: datetime.replace always returns datetime.datetime in pypy3
https://bitbucket.org/pypy/pypy/issues/2635/datetimereplace-always-returns
Paul G:
MWE:
`demo_datetime_replace.py`:
```
#!python
from datetime import datetime
class SuperDatetime(datetime):
pass
if __name__ == "__main__":
sdt0 = SuperDatetime(2017, 8, 1)
sdt1 = sdt0.replace(2016, 8, 1)
print(repr(sdt0))
print(repr(sdt1))
```
```
#! bash
$ python2 demo_datetime_replace.py
SuperDatetime(2017, 8, 1, 0, 0)
SuperDatetime(2016, 8, 1, 0, 0)
$ python3 demo_datetime_replace.py
SuperDatetime(2017, 8, 1, 0, 0)
SuperDatetime(2016, 8, 1, 0, 0)
$ pypy demo_datetime_replace.py
SuperDatetime(2017, 8, 1, 0, 0)
SuperDatetime(2016, 8, 1, 0, 0)
$ pypy3 demo_datetime_replace.py
__main__.SuperDatetime(2017, 8, 1, 0, 0)
datetime.datetime(2016, 8, 1, 0, 0)
```
It seems that `pypy3` is *also* the odd man out with respect to how `repr` is treated, but that's a separate and less important issue.
It's not clear to me how much "`datetime.replace` returns the same class of object" is part of the Python spec, but it seems reasonable and it's definitely a shift in behavior. There's [something about subclasses of builtin types here](http://doc.pypy.org/en/latest/cpython_differences.html#subclasses-of-built-in-types), but it doesn't seem relevant to me, if I'm understanding it right.
More information about the pypy-issue
mailing list