Josh Rosenberg added the comment:
Note: This class doesn't actually work on 3.4 in other ways (because
__getitem__ is not idempotent, while OrderedDict assumes it is):
>>> s = SimpleLRUCache(2)
>>> s['t1'] = 1
>>> s
SimpleLRUCache([('t1', 1)])
>>> s['t2'] = 2
>>> s
SimpleLRUCache([('t1', 1)])
Changes by Zachary Ware :
--
resolution: -> duplicate
stage: -> resolved
status: open -> closed
superseder: -> KeyError thrown by optimised collections.OrderedDict.popitem()
___
Python tracker
Xiang Zhang added the comment:
Please see issue27275. Someone has already complained about this. And I think
the cause is the gap between Pure Python implementation and C implementation
when it comes to subclasses.
--
nosy: +xiang.zhang
___
Python
New submission from Zachary Ware:
I'm not certain that the implementation of this subclass of OrderedDict is
actually sane, but it works in 3.4 and fails in 3.5+.
The buggy implementation:
class SimpleLRUCache(OrderedDict):
def __init__(self, size):
super().__init__()