Opened 11 years ago

Closed 11 years ago

#6611 closed (fixed)

SortedDict.copy breaks original dict if keys are added to copy

Reported by: Jeremy Dunck Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Original problem:

>>> orig = SortedDict(data={"blah": 1, "huh": 2})
>>> orig
{'blah': 1, 'huh': 2}
>>> copy = orig.copy()
>>> copy["new_key"] = 3
>>> orig
<type 'exceptions.KeyError'>: 'new_key'

Attachments (1)

sorteddict-copy-7121.diff (980 bytes) - added by Jeremy Dunck 11 years ago.

Download all attachments as: .zip

Change History (4)

Changed 11 years ago by Jeremy Dunck

Attachment: sorteddict-copy-7121.diff added

comment:1 Changed 11 years ago by Jeremy Dunck

The basic problem is that keyOrder is shared between the two dictionaries and adding keys to the copied dictionary make iteration of the original dictionary fail because keyOrder is extended without a corresponding entry being made in the original dictionary.

comment:2 Changed 11 years ago by Simon Greenhill <dev@…>

Triage Stage: UnreviewedReady for checkin

comment:3 Changed 11 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [7129]) Fixed #6611 -- When copying a SortedDict, make a new copy of the keys list.
Thanks, Jeremy Dunck.

Note: See TracTickets for help on using tickets.
Back to Top