Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added more readable __str__ and __repr__ methods to MergeDict.

Thanks, john@calixto.net. Fixed #3508.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13721 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 255147c97e4d71cae7ec6255720b4d265269deb2 1 parent dee7ef8
Malcolm Tredinnick authored September 10, 2010
1  AUTHORS
@@ -238,6 +238,7 @@ answer newbie questions, and generally made Django that much better:
238 238
     jcrasta@gmail.com
239 239
     jdetaeye
240 240
     jhenry <jhenry@theonion.com>
  241
+    john@calixto.net
241 242
     Zak Johnson <zakj@nox.cx>
242 243
     Nis Jørgensen <nis@superlativ.dk>
243 244
     Michael Josephson <http://www.sdjournal.com/>
21  django/utils/datastructures.py
@@ -77,6 +77,27 @@ def copy(self):
77 77
         """Returns a copy of this object."""
78 78
         return self.__copy__()
79 79
 
  80
+    def __str__(self):
  81
+        '''
  82
+        Returns something like
  83
+
  84
+            "{'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}"
  85
+
  86
+        instead of the generic "<object meta-data>" inherited from object.
  87
+        '''
  88
+        return str(dict(self.items()))
  89
+
  90
+    def __repr__(self):
  91
+        '''
  92
+        Returns something like
  93
+
  94
+            MergeDict({'key1': 'val1', 'key2': 'val2'}, {'key3': 'val3'})
  95
+
  96
+        instead of generic "<object meta-data>" inherited from object.
  97
+        '''
  98
+        dictreprs = ', '.join(repr(d) for d in self.dicts)
  99
+        return '%s(%s)' % (self.__class__.__name__, dictreprs)
  100
+
80 101
 class SortedDict(dict):
81 102
     """
82 103
     A dictionary that keeps its keys in the order in which they're inserted.

0 notes on commit 255147c

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