summaryrefslogtreecommitdiff
path: root/django/utils/datastructures.py
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-04-30 17:12:38 +0300
committerAnssi Kääriäinen <akaariai@gmail.com>2012-04-30 17:19:55 +0300
commit4b11762f7d7aed2f4f36c4158326c0a4332038f9 (patch)
tree360d399427cd79f4bd918e3d5226e4eef7c2dcc5 /django/utils/datastructures.py
parentaa1aa1ad410c640ff22260b9c6bf3c36be98ff8e (diff)
Fixed SortedDict.__copy__()
Fixed #18175 -- Calling SortedDict.__copy__() resulted in changes to the original dictionary. The reason was likely related to subclassing dict. Thanks to linovia for report and patch.
Diffstat (limited to 'django/utils/datastructures.py')
-rw-r--r--django/utils/datastructures.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py
index 09d37518e0..f7042f7061 100644
--- a/django/utils/datastructures.py
+++ b/django/utils/datastructures.py
@@ -128,6 +128,12 @@ class SortedDict(dict):
return self.__class__([(key, copy.deepcopy(value, memo))
for key, value in self.iteritems()])
+ def __copy__(self):
+ # The Python's default copy implementation will alter the state
+ # of self. The reason for this seems complex but is likely related to
+ # subclassing dict.
+ return self.copy()
+
def __setitem__(self, key, value):
if key not in self:
self.keyOrder.append(key)
@@ -200,9 +206,7 @@ class SortedDict(dict):
def copy(self):
"""Returns a copy of this object."""
# This way of initializing the copy means it works for subclasses, too.
- obj = self.__class__(self)
- obj.keyOrder = self.keyOrder[:]
- return obj
+ return self.__class__(self)
def __repr__(self):
"""