[Python-checkins] python/dist/src/Lib pprint.py,1.30,1.31

doerwalter at users.sourceforge.net doerwalter at users.sourceforge.net
Mon Nov 15 14:51:44 CET 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31518/Lib

Modified Files:
	pprint.py 
Log Message:
Fix pprint to be able to handle objects that don't have a __repr__
attribute. Fixes SF bug #1065456.


Index: pprint.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pprint.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- pprint.py	14 May 2004 16:31:56 -0000	1.30
+++ pprint.py	15 Nov 2004 13:51:41 -0000	1.31
@@ -131,7 +131,7 @@
         write = stream.write
 
         if sepLines:
-            r = typ.__repr__
+            r = getattr(typ, "__repr__", None)
             if issubclass(typ, dict) and r is dict.__repr__:
                 write('{')
                 if self._indent_per_level > 1:
@@ -229,7 +229,7 @@
                 write(qget(char, repr(char)[1:-1]))
         return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False
 
-    r = typ.__repr__
+    r = getattr(typ, "__repr__", None)
     if issubclass(typ, dict) and r is dict.__repr__:
         if not object:
             return "{}", True, False



More information about the Python-checkins mailing list