[issue27275] KeyError thrown by optimised collections.OrderedDict.popitem()

Xiang Zhang report at bugs.python.org
Fri Jun 10 14:31:55 EDT 2016


Xiang Zhang added the comment:

Raymond, In single threaded case popitem may still fail.

I want to correct my last message that popitem does not fail in this case because it calls __getitem__ but instead it calls __contains__[1]. In __contains__ it deletes the item since it expires, and finally emit a KeyError[2]. Even if it passes __contains__, it will call __getitem__[3].

[1] https://hg.python.org/cpython/file/tip/Objects/odictobject.c#l1115
[2] https://hg.python.org/cpython/file/tip/Objects/odictobject.c#l1135
[3] https://hg.python.org/cpython/file/tip/Objects/odictobject.c#l1119

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27275>
_______________________________________


More information about the Python-bugs-list mailing list