Enhancing MergeDict

7 views
Skip to first unread message

John Calixto

unread,
Feb 13, 2007, 8:15:39 PM2/13/07
to django-d...@googlegroups.com
Hi All,

I have an almost trivial (although it was helpful to me) enhancement for
django.utils.datastructures.MergeDict. It basically adds __str__ and
__repr__ methods so that you can see more meaningful output than just
the standard "<custom python object>" string.

Here's my diff:

=== django/utils/datastructures.py
==================================================================
--- django/utils/datastructures.py (revision 15931)
+++ django/utils/datastructures.py (local)
@@ -43,6 +43,13 @@
return True
return False

+ def __str__(self):
+ return str(dict(self.items()))
+
+ def __repr__(self):
+ dictreprs = ', '.join(repr(d) for d in self.dicts)
+ return '%s(%s)' % (self.__class__.__name__, dictreprs)
+
class SortedDict(dict):
"A dictionary that keeps its keys in the order in which they're
inserted."
def __init__(self, data=None):


On another note, I'm using svk to mirror django svn. Is it possible to
submit patches made with svk diff rather than svn diff?

Thanks,

John

Michael Radziej

unread,
Feb 14, 2007, 3:37:22 AM2/14/07
to django-d...@googlegroups.com
Hi,

John Calixto:


> I have an almost trivial (although it was helpful to me) enhancement for
> django.utils.datastructures.MergeDict. It basically adds __str__ and
> __repr__ methods so that you can see more meaningful output than just
> the standard "<custom python object>" string.
>
> Here's my diff:
>
> === django/utils/datastructures.py
> ==================================================================
> --- django/utils/datastructures.py (revision 15931)
> +++ django/utils/datastructures.py (local)
> @@ -43,6 +43,13 @@
> return True
> return False
>
> + def __str__(self):
> + return str(dict(self.items()))
> +
> + def __repr__(self):
> + dictreprs = ', '.join(repr(d) for d in self.dicts)
> + return '%s(%s)' % (self.__class__.__name__, dictreprs)
> +

Nice!


> On another note, I'm using svk to mirror django svn. Is it possible to
> submit patches made with svk diff rather than svn diff?

Should be no problem.

Michael

John Calixto

unread,
Feb 15, 2007, 9:27:21 PM2/15/07
to django-d...@googlegroups.com
Thanks Michael. I created a ticket (#3508) and submitted a patch. Based
on the triage policy, it seems "ready for checkin"... but it doesn't
seem kosher for me to decide that on my own :)
-jc
Reply all
Reply to author
Forward
0 new messages