]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-GH-20139) (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 21 May 2020 04:21:02 +0000 (21:21 -0700)
committerGitHub <noreply@github.com>
Thu, 21 May 2020 04:21:02 +0000 (21:21 -0700)
Doc/library/collections.rst

index 8dcf9451d72bfe48e469e2df31d7887945b8f980..d4297166597b643180b39757e2f1958fe501c4af 100644 (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))