Skip to content

Commit 8b3c2f2

Browse files
committed
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.
1 parent 9877d25 commit 8b3c2f2

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

django/utils/datastructures.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import copy
2+
import warning
23
from types import GeneratorType
34

5+
46
class MergeDict(object):
57
"""
68
A simple class for creating new "virtual" dictionaries that actually look
@@ -191,10 +193,17 @@ def setdefault(self, key, default):
191193

192194
def value_for_index(self, index):
193195
"""Returns the value of the item at the given zero-based index."""
196+
# This, and insert() are deprecated because they cannot be implemented
197+
# using collections.OrderedDict (Python 2.7 and up), which we'll
198+
# eventually switch to
199+
warning.warn(PendingDeprecationWarning,
200+
"SortedDict.value_for_index is deprecated", stacklevel=2)
194201
return self[self.keyOrder[index]]
195202

196203
def insert(self, index, key, value):
197204
"""Inserts the key, value pair before the item with the given index."""
205+
warning.warn(PendingDeprecationWarning,
206+
"SortedDict.insert is deprecated", stacklevel=2)
198207
if key in self.keyOrder:
199208
n = self.keyOrder.index(key)
200209
del self.keyOrder[n]

docs/ref/utils.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,14 @@ to distinguish caches by the ``Accept-language`` header.
112112

113113
.. method:: insert(index, key, value)
114114

115+
.. deprecated:: 1.5
116+
115117
Inserts the key, value pair before the item with the given index.
116118

117119
.. method:: value_for_index(index)
118120

121+
.. deprecated:: 1.5
122+
119123
Returns the value of the item at the given zero-based index.
120124

121125
Creating a new SortedDict

0 commit comments

Comments
 (0)