[issue44782] LRU class given as example in OrderedDict docs not work on pop

Raymond Hettinger report at bugs.python.org
Sat Jul 31 00:33:09 EDT 2021


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

I'm thinking that the current LRU() recipe should be changed to lru_cache() API using an OrderedDict internally rather than inheriting from it.   The current recipe was intended to be a sketch rather than a complete class; otherwise, methods like get() would also need to have been provided.

Also, the resolution of issue 27275 doesn't look correct.  The pop() method should not depend on the subclasses' __getitem__ method.   In this regard, the pure python code for OrderedDict is correct and matches what regular dictionary's do (overriding __getitem__ has no effect on other methods).  This leaves to the class "open for extension but closed for modification".  Most of our container classes follow this pattern unless specifically documented to the contrary (i.e. a framework pattern).

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44782>
_______________________________________


More information about the Python-bugs-list mailing list