diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index 2b19c06dfb1..cca30b462d9 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -99,6 +99,13 @@ class SortedDict(dict): obj.keyOrder = self.keyOrder return obj + def __repr__(self): + """ + Replaces the normal dict.__repr__ with a version that returns the keys + in their sorted order. + """ + return '{%s}' % ', '.join(['%r: %r' % (k, v) for k, v in self.items()]) + class MultiValueDictKeyError(KeyError): pass diff --git a/tests/regressiontests/datastructures/tests.py b/tests/regressiontests/datastructures/tests.py index e008c255f11..18eb4fcccd2 100644 --- a/tests/regressiontests/datastructures/tests.py +++ b/tests/regressiontests/datastructures/tests.py @@ -52,6 +52,8 @@ 'not one' >>> d.keys() == d.copy().keys() True +>>> print repr(d) +{'one': 'not one', 'two': 'two', 'three': 'three'} ### DotExpandedDict ############################################################