Opened 18 years ago
Closed 18 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)
Change History (4)
by , 18 years ago
| Attachment: | sorteddict-copy-7121.diff added |
|---|
comment:1 by , 18 years ago
comment:2 by , 18 years ago
| Triage Stage: | Unreviewed → Ready for checkin |
|---|
comment:3 by , 18 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
(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.
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.