Browse files

Deprecate two methods (which I seriously doubt anyone ever used, but …

…they were documented so...) because they cannot be implemented efficiently on top of collections.SortedDict in Python 2.7 and up.
  • Loading branch information...
1 parent 9877d25 commit 8b3c2f2c51183bde47bd1e98057b77866f35dd6e @alex alex committed Jul 14, 2012
Showing with 13 additions and 0 deletions.
  1. +9 −0 django/utils/
  2. +4 −0 docs/ref/utils.txt
9 django/utils/
@@ -1,6 +1,8 @@
import copy
+import warning
mariocesar added a line comment Jul 15, 2012

This change is breaking django, using Python 2.7.2+

ImportError: No module named warning

Call me crazy, but I think the correct module name is warnings

Django member
alex added a line comment Jul 15, 2012

Well, that's emberassing. Fixed in the next commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
from types import GeneratorType
class MergeDict(object):
A simple class for creating new "virtual" dictionaries that actually look
@@ -191,10 +193,17 @@ def setdefault(self, 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
+ warning.warn(PendingDeprecationWarning,
+ "SortedDict.value_for_index is deprecated", 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."""
+ warning.warn(PendingDeprecationWarning,
+ "SortedDict.insert is deprecated", stacklevel=2)
if key in self.keyOrder:
n = self.keyOrder.index(key)
del self.keyOrder[n]
4 docs/ref/utils.txt
@@ -112,10 +112,14 @@ to distinguish caches by the ``Accept-language`` header.
.. 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

1 comment on commit 8b3c2f2


I am one of the few people who was apparently using SortedDict.insert() - to dynamically add form fields at a particular position in a forms.ModelForm.__init__().

The argument order to warnings.warn() is incorrect. It should be warnings.warn(message[, category[, stacklevel]]) ( As it stands, instead of throwing a warning, it throws an exception:

TypeError: issubclass() arg 1 must be a class

Please sign in to comment.