Fix pprint to be able to handle objects that don't have a __repr__

attribute. Fixes SF bug #1065456.
This commit is contained in:
Walter Dörwald 2004-11-15 13:51:41 +00:00
parent fdc58f2391
commit 1b626cac73
1 changed files with 2 additions and 2 deletions

View File

@ -131,7 +131,7 @@ class PrettyPrinter:
write = stream.write write = stream.write
if sepLines: if sepLines:
r = typ.__repr__ r = getattr(typ, "__repr__", None)
if issubclass(typ, dict) and r is dict.__repr__: if issubclass(typ, dict) and r is dict.__repr__:
write('{') write('{')
if self._indent_per_level > 1: if self._indent_per_level > 1:
@ -229,7 +229,7 @@ def _safe_repr(object, context, maxlevels, level):
write(qget(char, repr(char)[1:-1])) write(qget(char, repr(char)[1:-1]))
return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False 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 issubclass(typ, dict) and r is dict.__repr__:
if not object: if not object:
return "{}", True, False return "{}", True, False