This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author erezinman
Recipients erezinman, rhettinger, serhiy.storchaka
Date 2020-09-09.14:04:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1599660299.53.0.603196488048.issue41751@roundup.psfhosted.org>
In-reply-to
Content
Looking at the implementation of `__init__` (https://github.com/python/cpython/blob/76553e5d2eae3e8a47406a6de4f354fe33ff370b/Lib/collections/__init__.py#L109), it seems that you can fix this bug while retaining backward compatibility if you would use `__new__` in the `__reduce__` function, followed by an `OrderedDict.__init__`. The difference is that you don't call `__class__.__init__`, but rather `OrderedDict.__init__`. Some thing like the following:


    def __reduce__(self):
        'Return state information for pickling'
        inst_dict = vars(self).copy()
        for k in vars(OrderedDict()):
            inst_dict.pop(k, None)
        
        def initializer():
            inst = __class__.__new__(__class__)
            OrderedDict.__init__(inst)

        return initializer, (), inst_dict or None, None, iter(self.items())


The items will "restored" later using the `odict_iter`.
History
Date User Action Args
2020-09-09 14:04:59erezinmansetrecipients: + erezinman, rhettinger, serhiy.storchaka
2020-09-09 14:04:59erezinmansetmessageid: <1599660299.53.0.603196488048.issue41751@roundup.psfhosted.org>
2020-09-09 14:04:59erezinmanlinkissue41751 messages
2020-09-09 14:04:59erezinmancreate