[New-bugs-announce] [issue41751] Error copying an instance of a subclass of OrderedDict

Erez Zinman report at bugs.python.org
Wed Sep 9 06:09:46 EDT 2020


New submission from Erez Zinman <erezinman.programmer at gmail.com>:

This bug occurs when copying/pickling an ordered-dict subtype that has default items. The initialization function that's returned is **not** `object.__new__` so the default items are set when the copied/pickled item is created. The problem I encountered is that when deleting an initial item, it appears in the copy. See the MWE below:

```
from collections import OrderedDict
import copy


class A(OrderedDict):
    def __init__(self):
        self['123'] = 123

a = A()
del a['123']
copy.copy(a)


# --> A([('123', 123)])

```


This can cause other problems as well, because you don't assume that the class is re-initialized on deserialization/copy.

----------
components: Library (Lib)
messages: 376627
nosy: erezinman
priority: normal
severity: normal
status: open
title: Error copying an instance of a subclass of OrderedDict
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41751>
_______________________________________


More information about the New-bugs-announce mailing list