New submission from Erez Zinman <erezinman.program...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue41751>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to