Removed insert(), value_for_insert() SortedDict methods deprecated in Django 1.5.

This commit is contained in:
Ramiro Morales 2013-06-28 22:38:13 -03:00
parent 8eadbc5a03
commit 7379d9acea
3 changed files with 0 additions and 55 deletions

View File

@ -1,5 +1,4 @@
import copy import copy
import warnings
from django.utils import six from django.utils import six
@ -217,31 +216,6 @@ class SortedDict(dict):
self.keyOrder.append(key) self.keyOrder.append(key)
return super(SortedDict, self).setdefault(key, default) 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): def copy(self):
"""Returns a copy of this object.""" """Returns a copy of this object."""
# This way of initializing the copy means it works for subclasses, too. # This way of initializing the copy means it works for subclasses, too.

View File

@ -107,20 +107,6 @@ to distinguish caches by the ``Accept-language`` header.
The :class:`django.utils.datastructures.SortedDict` class is a dictionary The :class:`django.utils.datastructures.SortedDict` class is a dictionary
that keeps its keys in the order in which they're inserted. 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 Creating a new SortedDict
------------------------- -------------------------

View File

@ -4,7 +4,6 @@ Tests for stuff in django.utils.datastructures.
import copy import copy
import pickle import pickle
import warnings
from django.test import SimpleTestCase from django.test import SimpleTestCase
from django.utils.datastructures import (DictWrapper, ImmutableList, 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.d1)), [9, 1, 7])
self.assertEqual(list(reversed(self.d2)), [7, 0, 9, 1]) 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): class MergeDictTests(SimpleTestCase):