]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-#20139)
authorqudongfang <qudongfang@users.noreply.github.com>
Mon, 18 May 2020 03:50:51 +0000 (04:50 +0100)
committerGitHub <noreply@github.com>
Mon, 18 May 2020 03:50:51 +0000 (20:50 -0700)
Doc/library/collections.rst

index c9533a3cb8f488562020bd3a32161392cacf0692..549ac1bccadf5de92349b7c46a180326a33ced69 100644 (file)
@@ -1161,6 +1161,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))