[New-bugs-announce] [issue9616] copy.deepcopy() copying pointers from a dict/dict/list, should copy values

Neil Harkins report at bugs.python.org
Sun Aug 15 22:12:26 CEST 2010


New submission from Neil Harkins <nharkins at gmail.com>:

hi. after using deepcopy() on a nested dict/list structure, 
i noticed that modifications to the deepcopied structure were 
affecting the original. this looks to me like a serious bug:

>>> import copy
>>> foo = { 'a':[1,2,3], 'b':{'c':[4,5]} }
>>> bar = copy.deepcopy(foo)
>>> id(foo)
4297360512
>>> id(bar)
4297373104
>>> id(foo['a'])
4299410752
>>> id(bar['a'])
4299760200
>>> id(foo['b'])
4297371984
>>> id(bar['b'])
4297373920
>>> id(foo['b']['c'])
4299721040
>>> id(bar['b']['c'])
4299761496
>>> id(foo['b']['c'][0])
4297074656
>>> id(bar['b']['c'][0])
4297074656

----------
components: Extension Modules
messages: 114007
nosy: nharkins
priority: normal
severity: normal
status: open
title: copy.deepcopy() copying pointers from a dict/dict/list, should copy values
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9616>
_______________________________________


More information about the New-bugs-announce mailing list