Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed insert(), value_for_insert() SortedDict methods deprecated in…

… Django 1.5.
  • Loading branch information...
commit 7379d9aceab01e007966b5fe1f47ba7590deb887 1 parent 8eadbc5
@ramiro ramiro authored
View
26 django/utils/datastructures.py
@@ -1,5 +1,4 @@
import copy
-import warnings
from django.utils import six
@@ -217,31 +216,6 @@ def setdefault(self, key, default):
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.
View
14 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
-------------------------
View
15 tests/utils_tests/test_datastructures.py
@@ -4,7 +4,6 @@
import copy
import pickle
-import warnings
from django.test import SimpleTestCase
from django.utils.datastructures import (DictWrapper, ImmutableList,
@@ -134,20 +133,6 @@ def test_reversed(self):
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):
Please sign in to comment.
Something went wrong with that request. Please try again.