- :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
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):
"""
from collections import deque
-import gc
+from copy import copy as shallow_copy
import pickle
import random
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