Loading django/utils/datastructures.py +0 −26 Original line number Diff line number Diff line import copy import warnings from django.utils import six Loading Loading @@ -217,31 +216,6 @@ class SortedDict(dict): self.keyOrder.append(key) return super(SortedDict, self).setdefault(key, default) def value_for_index(self, index): """Returns the value of the item at the given zero-based index.""" # 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( "SortedDict.value_for_index is deprecated", DeprecationWarning, 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( "SortedDict.insert is deprecated", DeprecationWarning, stacklevel=2 ) if key in self.keyOrder: n = self.keyOrder.index(key) del self.keyOrder[n] if n < index: index -= 1 self.keyOrder.insert(index, key) super(SortedDict, self).__setitem__(key, value) def copy(self): """Returns a copy of this object.""" # This way of initializing the copy means it works for subclasses, too. Loading docs/ref/utils.txt +0 −14 Original line number Diff line number Diff line Loading @@ -107,20 +107,6 @@ to distinguish caches by the ``Accept-language`` header. The :class:`django.utils.datastructures.SortedDict` class is a dictionary that keeps its keys in the order in which they're inserted. ``SortedDict`` adds two additional methods to the standard Python ``dict`` class: .. method:: insert(index, key, value) .. deprecated:: 1.5 Inserts the key, value pair before the item with the given index. .. method:: value_for_index(index) .. deprecated:: 1.5 Returns the value of the item at the given zero-based index. Creating a new SortedDict ------------------------- Loading tests/utils_tests/test_datastructures.py +0 −15 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ 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 @@ -134,20 +133,6 @@ class SortedDictTests(SimpleTestCase): self.assertEqual(list(reversed(self.d1)), [9, 1, 7]) self.assertEqual(list(reversed(self.d2)), [7, 0, 9, 1]) 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 DeprecationWarning 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 DeprecationWarning class MergeDictTests(SimpleTestCase): Loading Loading
django/utils/datastructures.py +0 −26 Original line number Diff line number Diff line import copy import warnings from django.utils import six Loading Loading @@ -217,31 +216,6 @@ class SortedDict(dict): self.keyOrder.append(key) return super(SortedDict, self).setdefault(key, default) def value_for_index(self, index): """Returns the value of the item at the given zero-based index.""" # 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( "SortedDict.value_for_index is deprecated", DeprecationWarning, 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( "SortedDict.insert is deprecated", DeprecationWarning, stacklevel=2 ) if key in self.keyOrder: n = self.keyOrder.index(key) del self.keyOrder[n] if n < index: index -= 1 self.keyOrder.insert(index, key) super(SortedDict, self).__setitem__(key, value) def copy(self): """Returns a copy of this object.""" # This way of initializing the copy means it works for subclasses, too. Loading
docs/ref/utils.txt +0 −14 Original line number Diff line number Diff line Loading @@ -107,20 +107,6 @@ to distinguish caches by the ``Accept-language`` header. The :class:`django.utils.datastructures.SortedDict` class is a dictionary that keeps its keys in the order in which they're inserted. ``SortedDict`` adds two additional methods to the standard Python ``dict`` class: .. method:: insert(index, key, value) .. deprecated:: 1.5 Inserts the key, value pair before the item with the given index. .. method:: value_for_index(index) .. deprecated:: 1.5 Returns the value of the item at the given zero-based index. Creating a new SortedDict ------------------------- Loading
tests/utils_tests/test_datastructures.py +0 −15 Original line number Diff line number Diff line Loading @@ -4,7 +4,6 @@ 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 @@ -134,20 +133,6 @@ class SortedDictTests(SimpleTestCase): self.assertEqual(list(reversed(self.d1)), [9, 1, 7]) self.assertEqual(list(reversed(self.d2)), [7, 0, 9, 1]) 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 DeprecationWarning 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 DeprecationWarning class MergeDictTests(SimpleTestCase): Loading