Author serhiy.storchaka
Recipients Mark.Shannon, eric.snow, mpaolini, rhettinger, serhiy.storchaka, terry.reedy
Date 2015-10-21.19:18:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
__repr__() allocates a list with the size len(od) and fills it iterating linked list. If the size of linked list is less then the size of the dict, the rest of the list is not initialized.

Even worse things happened when the size of linked list is greater then the size of the dict. Following example causes a crash:

from collections import OrderedDict
od = OrderedDict()
class K(str):
    def __hash__(self):
        return 1

od[K('a')] = 1
od[K('b')] = 2
print(len(od), len(list(od)))
K.__eq__ = lambda self, other: True
dict.__delitem__(od, K('a'))
print(len(od), len(list(od)))

Proposed patch fixes both issues.
Date User Action Args
2015-10-21 19:18:33serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, terry.reedy, Mark.Shannon, eric.snow, mpaolini
2015-10-21 19:18:33serhiy.storchakasetmessageid: <>
2015-10-21 19:18:32serhiy.storchakalinkissue24726 messages
2015-10-21 19:18:32serhiy.storchakacreate