Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3964 -- Added a custom SortedDict.__repr__ so that the keys ar…

…e printed

in sorted order. Based on a patch from Forest Bond.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5069 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit aca569804e661725ed38d2bc0a2ccfd165e4bad0 1 parent 535535a
Malcolm Tredinnick authored April 25, 2007
7  django/utils/datastructures.py
@@ -99,6 +99,13 @@ def copy(self):
99 99
         obj.keyOrder = self.keyOrder
100 100
         return obj
101 101
 
  102
+    def __repr__(self):
  103
+        """
  104
+        Replaces the normal dict.__repr__ with a version that returns the keys
  105
+        in their sorted order.
  106
+        """
  107
+        return '{%s}' % ', '.join(['%r: %r' % (k, v) for k, v in self.items()])
  108
+
102 109
 class MultiValueDictKeyError(KeyError):
103 110
     pass
104 111
 
2  tests/regressiontests/datastructures/tests.py
@@ -52,6 +52,8 @@
52 52
 'not one'
53 53
 >>> d.keys() == d.copy().keys()
54 54
 True
  55
+>>> print repr(d)
  56
+{'one': 'not one', 'two': 'two', 'three': 'three'}
55 57
 
56 58
 ### DotExpandedDict ############################################################
57 59
 

0 notes on commit aca5698

Please sign in to comment.
Something went wrong with that request. Please try again.