From 7379d9aceab01e007966b5fe1f47ba7590deb887 Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Fri, 28 Jun 2013 22:38:13 -0300 Subject: [PATCH] Removed insert(), value_for_insert() SortedDict methods deprecated in Django 1.5. --- django/utils/datastructures.py | 26 ------------------------ docs/ref/utils.txt | 14 ------------- tests/utils_tests/test_datastructures.py | 15 -------------- 3 files changed, 55 deletions(-) diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index a211323320..3b1638392c 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -1,5 +1,4 @@ import copy -import warnings from django.utils import six @@ -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. diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt index 8d722829fb..6fa829ef22 100644 --- a/docs/ref/utils.txt +++ b/docs/ref/utils.txt @@ -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 ------------------------- diff --git a/tests/utils_tests/test_datastructures.py b/tests/utils_tests/test_datastructures.py index 5829e7c2d7..5563a0fc4f 100644 --- a/tests/utils_tests/test_datastructures.py +++ b/tests/utils_tests/test_datastructures.py @@ -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, @@ -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):