Amaury Forgeot d'Arc <amaur...@gmail.com> added the comment:

The call to self.__class__() can break subclasses of OrderedDict for two 
reasons:
- The subclass constructor may have a different signature
- Attributes set by the subclass.__init__ are removed from the pickle::

import collections, pickle

class Mydict(collections.OrderedDict):
    def __init__(self, *args, name=None, **kwargs):
        super().__init__(*args, **kwargs)
        self.name = name

a = Mydict(name='foo')
b = pickle.loads(pickle.dumps(a))
print(a.name, b.name)

Previously, the 'name' would be correctly copied, now it is reset to None.

----------
nosy: +amaury.forgeotdarc
status: closed -> open

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11875>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to