]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
LRUCache.copy initializes queue methods
authorRyan Siemens <ryanjsiemens@gmail.com>
Mon, 23 Apr 2018 07:26:22 +0000 (00:26 -0700)
committerDavid Lord <davidism@gmail.com>
Thu, 24 Oct 2019 14:47:20 +0000 (07:47 -0700)
CHANGES.rst
jinja2/utils.py
tests/test_utils.py

index d53a4db29514f62279bce137bba095294a6e3bfd..6a35fd857b9934a0385ecaaf70e990fb183999e2 100644 (file)
@@ -55,6 +55,8 @@ Unreleased
 -   :class:`~nativetypes.NativeTemplate` correctly handles quotes
     between expressions. ``"'{{ a }}', '{{ b }}'"`` renders as the tuple
     ``('1', '2')`` rather than the string ``'1, 2'``. :issue:`1020`
+-   ``LRUCache.copy()`` correctly re-initializes the queue methods
+    after copying. :issue:`843`
 
 
 Version 2.10.3
index 5518793797d775c552c6119ea2231f369bf66a6c..220edcf1d5d2ac4770d1d148efe10ed4ef8277ad 100644 (file)
@@ -341,6 +341,7 @@ class LRUCache(object):
         rv = self.__class__(self.capacity)
         rv._mapping.update(self._mapping)
         rv._queue = deque(self._queue)
+        rv._postinit()
         return rv
 
     def get(self, key, default=None):
index 64c2b3a6e76c904049ddf34df2a98ba5101826b0..56ca5dcdc3b460bd4a4a19ae426248b3514315cc 100644 (file)
@@ -10,7 +10,7 @@
 """
 
 from collections import deque
-import gc
+from copy import copy as shallow_copy
 import pickle
 import random
 
@@ -68,6 +68,17 @@ class TestLRUCache(object):
             assert copy._mapping == cache._mapping
             assert copy._queue == cache._queue
 
+    @pytest.mark.parametrize("copy_func", [LRUCache.copy, shallow_copy])
+    def test_copy(self, copy_func):
+        cache = LRUCache(2)
+        cache['a'] = 1
+        cache['b'] = 2
+        copy = copy_func(cache)
+        assert copy._queue == cache._queue
+        copy['c'] = 3
+        assert copy._queue != cache._queue
+        assert 'a' not in copy and 'b' in copy and 'c' in copy
+
     def test_clear(self):
         d = LRUCache(3)
         d["a"] = 1