[Python-checkins] bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-#20139)

qudongfang webhook-mailer at python.org
Sun May 17 23:50:59 EDT 2020


https://github.com/python/cpython/commit/bb8635cc3bc3dd65996803849ee1a91cfbebae9c
commit: bb8635cc3bc3dd65996803849ee1a91cfbebae9c
branch: master
author: qudongfang <qudongfang at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-05-17T20:50:51-07:00
summary:

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

files:
M Doc/library/collections.rst

diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index c9533a3cb8f48..549ac1bccadf5 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -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))



More information about the Python-checkins mailing list