[issue28752] datetime object fails to restore from reduction

Serhiy Storchaka report at bugs.python.org
Sun Nov 20 11:10:56 EST 2016


Serhiy Storchaka added the comment:

Now pickling of the datetime.datetime objects is implemented with __reduce_ex__. __reduce__ is not defined in datetime.datetime and is inherited from datetime.date.

>>> datetime.datetime.__reduce_ex__
<method '__reduce_ex__' of 'datetime.datetime' objects>
>>> datetime.datetime.__reduce__
<method '__reduce__' of 'datetime.date' objects>

__reduce_ex__ has higher priority and is called instead of __reduce__. It is weird that __reduce_ex__ and __reduce__ are not consistent. __reduce__ should be defined as

    def __reduce__(self):
        return self.__reduce_ex__(2)

or just

    __reduce__ = object.__reduce__

Other way is to define __reduce_ex__ instead of __reduce__ in datetime.date.

----------
components: +Extension Modules
nosy: +belopolsky, serhiy.storchaka
type:  -> behavior

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28752>
_______________________________________


More information about the Python-bugs-list mailing list