]> granicus.if.org Git - python/commitdiff
Fix pprint to be able to handle objects that don't have a __repr__
authorWalter Dörwald <walter@livinglogic.de>
Mon, 15 Nov 2004 13:51:41 +0000 (13:51 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Mon, 15 Nov 2004 13:51:41 +0000 (13:51 +0000)
attribute. Fixes SF bug #1065456.

Lib/pprint.py

index e92b6390e7b27afe4fec206beb37a7c5cccf74da..da6ab1a9c7ac4f4bcf274577a11d472ce059532b 100644 (file)
@@ -131,7 +131,7 @@ class PrettyPrinter:
         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 @@ def _safe_repr(object, context, maxlevels, level):
                 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