Serhiy Storchaka added the comment:
__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.
----------
components: +Extension Modules -Library (Lib)
keywords: +patch
stage: test needed -> patch review
type: behavior -> crash
versions: -Python 2.7, Python 3.4
Added file:
http://bugs.python.org/file40834/odict_repr_after_dict_setitem_delitem.patch
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue24726>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com