ValueOrderedDict throws IndexError when given equal non-identical keys #2899

Open
opened 2017-08-10 01:37:54 +00:00 by warner · 0 comments
warner commented 2017-08-10 01:37:54 +00:00
Owner
from allmydata.util.dictutil import [ValueOrderedDict](wiki/ValueOrderedDict)
a = (1,2)
b = (1,2)
d = [ValueOrderedDict](wiki/ValueOrderedDict)()
da = 1
db = 1
db = 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.

``` from allmydata.util.dictutil import [ValueOrderedDict](wiki/ValueOrderedDict) a = (1,2) b = (1,2) d = [ValueOrderedDict](wiki/ValueOrderedDict)() da = 1 db = 1 db = 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.
tahoe-lafs added the
code
minor
defect
1.12.1
labels 2017-08-10 01:37:54 +00:00
tahoe-lafs added this to the undecided milestone 2017-08-10 01:37:54 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: tahoe-lafs/trac-2024-07-25#2899
No description provided.