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 <1445455113.08.0.0636653904961.issue24726@psf.upfronthosting.co.za>
In-reply-to
Content
__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)))
print(repr(od))

Proposed patch fixes both issues.
History
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: <1445455113.08.0.0636653904961.issue24726@psf.upfronthosting.co.za>
2015-10-21 19:18:32serhiy.storchakalinkissue24726 messages
2015-10-21 19:18:32serhiy.storchakacreate