#2899 new defect

ValueOrderedDict throws IndexError when given equal non-identical keys

Reported by: warner Owned by:
Priority: minor Milestone: undecided
Component: code Version: 1.12.1
Keywords: Cc:
Launchpad Bug:

Description

from allmydata.util.dictutil import ValueOrderedDict
a = (1,2)
b = (1,2)
d = ValueOrderedDict()
d[a] = 1
d[b] = 1
d[b] = 2

gives:

  File ".../src/allmydata/util/dictutil.py", line 509, in __setitem__
    while (self.l[i][0] is not oldval) or (self.l[i][1] is not key):
IndexError: list index out of range

I found this while trying to improve the test coverage, to exercise the i += 1 statement inside that while loop. I think the only way to reach it is to have keys which are equal but not identical. Python doesn't (currently? always?) consolidate equivalent tuples (although I think it'd be allowed to), which is one way to hit this case.

Change History (0)

Note: See TracTickets for help on using tickets.