Loading django/utils/datastructures.py +8 −4 Original line number Diff line number Diff line Loading @@ -196,14 +196,18 @@ class SortedDict(dict): # This, and insert() are deprecated because they cannot be implemented # using collections.OrderedDict (Python 2.7 and up), which we'll # eventually switch to warnings.warn(PendingDeprecationWarning, "SortedDict.value_for_index is deprecated", stacklevel=2) warnings.warn( "SortedDict.value_for_index is deprecated", PendingDeprecationWarning, stacklevel=2 ) return self[self.keyOrder[index]] def insert(self, index, key, value): """Inserts the key, value pair before the item with the given index.""" warnings.warn(PendingDeprecationWarning, "SortedDict.insert is deprecated", stacklevel=2) warnings.warn( "SortedDict.insert is deprecated", PendingDeprecationWarning, stacklevel=2 ) if key in self.keyOrder: n = self.keyOrder.index(key) del self.keyOrder[n] Loading tests/regressiontests/utils/datastructures.py +16 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ Tests for stuff in django.utils.datastructures. import copy import pickle import warnings from django.test import SimpleTestCase from django.utils.datastructures import (DictWrapper, ImmutableList, Loading Loading @@ -122,6 +123,21 @@ class SortedDictTests(SimpleTestCase): self.assertEqual(self.d1, {}) self.assertEqual(self.d1.keyOrder, []) def test_insert(self): d = SortedDict() with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") d.insert(0, "hello", "world") assert w[0].category is PendingDeprecationWarning def test_value_for_index(self): d = SortedDict({"a": 3}) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") self.assertEqual(d.value_for_index(0), 3) assert w[0].category is PendingDeprecationWarning class MergeDictTests(SimpleTestCase): def test_simple_mergedict(self): Loading Loading
django/utils/datastructures.py +8 −4 Original line number Diff line number Diff line Loading @@ -196,14 +196,18 @@ class SortedDict(dict): # This, and insert() are deprecated because they cannot be implemented # using collections.OrderedDict (Python 2.7 and up), which we'll # eventually switch to warnings.warn(PendingDeprecationWarning, "SortedDict.value_for_index is deprecated", stacklevel=2) warnings.warn( "SortedDict.value_for_index is deprecated", PendingDeprecationWarning, stacklevel=2 ) return self[self.keyOrder[index]] def insert(self, index, key, value): """Inserts the key, value pair before the item with the given index.""" warnings.warn(PendingDeprecationWarning, "SortedDict.insert is deprecated", stacklevel=2) warnings.warn( "SortedDict.insert is deprecated", PendingDeprecationWarning, stacklevel=2 ) if key in self.keyOrder: n = self.keyOrder.index(key) del self.keyOrder[n] Loading
tests/regressiontests/utils/datastructures.py +16 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ Tests for stuff in django.utils.datastructures. import copy import pickle import warnings from django.test import SimpleTestCase from django.utils.datastructures import (DictWrapper, ImmutableList, Loading Loading @@ -122,6 +123,21 @@ class SortedDictTests(SimpleTestCase): self.assertEqual(self.d1, {}) self.assertEqual(self.d1.keyOrder, []) def test_insert(self): d = SortedDict() with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") d.insert(0, "hello", "world") assert w[0].category is PendingDeprecationWarning def test_value_for_index(self): d = SortedDict({"a": 3}) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") self.assertEqual(d.value_for_index(0), 3) assert w[0].category is PendingDeprecationWarning class MergeDictTests(SimpleTestCase): def test_simple_mergedict(self): Loading