Opened 17 years ago

Closed 17 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: dev
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

Description

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 17 years ago.

Download all attachments as: .zip

Change History (4)

by Jeremy Dunck, 17 years ago

Attachment: sorteddict-copy-7121.diff added

comment:1 by Jeremy Dunck, 17 years ago

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 by Simon Greenhill <dev@…>, 17 years ago

Triage Stage: UnreviewedReady for checkin

comment:3 by Malcolm Tredinnick, 17 years ago

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