Skip to content

Commit

Permalink
Fixed #3964 -- Added a custom SortedDict.__repr__ so that the keys ar…
Browse files Browse the repository at this point in the history
…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
malcolmt committed Apr 25, 2007
1 parent 535535a commit aca5698
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions django/utils/datastructures.py
Expand Up @@ -99,6 +99,13 @@ def copy(self):
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

Expand Down
2 changes: 2 additions & 0 deletions tests/regressiontests/datastructures/tests.py
Expand Up @@ -52,6 +52,8 @@
'not one'
>>> d.keys() == d.copy().keys()
True
>>> print repr(d)
{'one': 'not one', 'two': 'two', 'three': 'three'}
### DotExpandedDict ############################################################
Expand Down

0 comments on commit aca5698

Please sign in to comment.