Message376636
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`. |
|
Date |
User |
Action |
Args |
2020-09-09 14:04:59 | erezinman | set | recipients:
+ erezinman, rhettinger, serhiy.storchaka |
2020-09-09 14:04:59 | erezinman | set | messageid: <1599660299.53.0.603196488048.issue41751@roundup.psfhosted.org> |
2020-09-09 14:04:59 | erezinman | link | issue41751 messages |
2020-09-09 14:04:59 | erezinman | create | |
|