From 54546f23f09a989ee3c1c3e629eac98706b6262e Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Thu, 21 Feb 2008 21:27:44 +0000 Subject: [PATCH] Fixed #6627 -- Made dict.clear() work for SortedDicts. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7140 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/datastructures.py | 4 ++++ tests/regressiontests/datastructures/tests.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index a2b78a31c5..4c278c0d8e 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -155,6 +155,10 @@ class SortedDict(dict): """ return '{%s}' % ', '.join(['%r: %r' % (k, v) for k, v in self.items()]) + def clear(self): + super(SortedDict, self).clear() + self.keyOrder = [] + class MultiValueDictKeyError(KeyError): pass diff --git a/tests/regressiontests/datastructures/tests.py b/tests/regressiontests/datastructures/tests.py index 172057f080..b51b4b1233 100644 --- a/tests/regressiontests/datastructures/tests.py +++ b/tests/regressiontests/datastructures/tests.py @@ -101,6 +101,12 @@ Init from sequence of tuples >>> print repr(d) {1: 'one', 0: 'zero', 2: 'two'} +>>> d.clear() +>>> d +{} +>>> d.keyOrder +[] + ### DotExpandedDict ############################################################ >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], 'person.1.lastname': ['Willison'], 'person.2.firstname': ['Adrian'], 'person.2.lastname': ['Holovaty']})