From 90595070ae0c8da489faf24f153b918d2879e759 Mon Sep 17 00:00:00 2001 From: gokcegrbl Date: Fri, 31 May 2019 12:28:44 +0000 Subject: [PATCH] Added new method itervalues() to LRUCache and deprecated itervalue() (Fixes pallets/jinja#999) --- jinja2/utils.py | 9 +++++++++ tests/test_utils.py | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/jinja2/utils.py b/jinja2/utils.py index 538b7745..d13a81b2 100644 --- a/jinja2/utils.py +++ b/jinja2/utils.py @@ -11,6 +11,7 @@ import re import json import errno +import warnings from collections import deque from threading import Lock from jinja2._compat import text_type, string_types, implements_iterator, \ @@ -456,6 +457,14 @@ class LRUCache(object): return [x[1] for x in self.items()] def itervalue(self): + """Iterate over all values.""" + warnings.warn(DeprecationWarning( + '"itervalue()" is deprecated and will be removed in version 2.12.' + + ' Use "itervalues()" instead.' + ), stacklevel=2) + return self.itervalues() + + def itervalues(self): """Iterate over all values.""" return iter(self.values()) diff --git a/tests/test_utils.py b/tests/test_utils.py index f71c608e..91defc90 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -32,6 +32,27 @@ class TestLRUCache(object): assert len(d) == 3 assert 'a' in d and 'c' in d and 'd' in d and 'b' not in d + def test_itervalue_deprecated(self): + cache = LRUCache(3) + cache["a"] = 1 + cache["b"] = 2 + with pytest.deprecated_call(): + cache.itervalue() + + def test_itervalues(self): + cache = LRUCache(3) + cache["b"] = 1 + cache["a"] = 2 + values = [v for v in cache.itervalues()] + assert len(values) == 2 + assert 1 in values + assert 2 in values + + def test_itervalues_empty(self): + cache = LRUCache(2) + values = [v for v in cache.itervalues()] + assert len(values) == 0 + def test_pickleable(self): cache = LRUCache(2) cache["foo"] = 42 -- 2.47.2