bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-GH-20139) (GH-20167)

This commit is contained in:
Miss Islington (bot) 2020-05-20 21:21:02 -07:00 committed by GitHub
parent a59fc9160d
commit d88f0aa8e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -1150,6 +1150,8 @@ variants of :func:`functools.lru_cache`::
return value
def __setitem__(self, key, value):
if key in self:
self.move_to_end(key)
super().__setitem__(key, value)
if len(self) > self.maxsize:
oldest = next(iter(self))