Skip to content
Myr

LRUCache.copy initializes queue methods

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Ryan Siemens · committed by David Lord · parent 8182509 · Browse files · 3 files+15 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+15 added−1 removed

  • tests:+12 added−1 removed
  • other:+3 added−0 removed

3 files+15 added−1 removed

modified:jinja2/utils.py+1 added
339 unmodified lines
340 """Return a shallow copy of the instance."""341 rv = self.__class__(self.capacity)342 rv._mapping.update(self._mapping)343 rv._queue = deque(self._queue)344 rv._postinit()345 return rv346347 def get(self, key, default=None):348 """Return an item from the cache dict or `default`"""
322 unmodified lines
modified:tests/test_utils.py+12 added-1 removed
8 unmodified lines
9 :license: BSD, see LICENSE for more details.10"""1112from collections import deque13import gc13from copy import copy as shallow_copy14import pickle15import random1617import pytest
49 unmodified lines
67 assert copy.capacity == cache.capacity68 assert copy._mapping == cache._mapping69 assert copy._queue == cache._queue7071 @pytest.mark.parametrize("copy_func", [LRUCache.copy, shallow_copy])72 def test_copy(self, copy_func):73 cache = LRUCache(2)74 cache['a'] = 175 cache['b'] = 276 copy = copy_func(cache)77 assert copy._queue == cache._queue78 copy['c'] = 379 assert copy._queue != cache._queue80 assert 'a' not in copy and 'b' in copy and 'c' in copy8182 def test_clear(self):83 d = LRUCache(3)84 d["a"] = 185 d["b"] = 2
124 unmodified lines
modified:CHANGES.rst+2 added
53 unmodified lines
54 :issue:`870`55- :class:`~nativetypes.NativeTemplate` correctly handles quotes56 between expressions. ``"'{{ a }}', '{{ b }}'"`` renders as the tuple57 ``('1', '2')`` rather than the string ``'1, 2'``. :issue:`1020`58- ``LRUCache.copy()`` correctly re-initializes the queue methods59 after copying. :issue:`843`606162Version 2.10.363--------------
629 unmodified lines