Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b626ca

Browse files
committed
Fix pprint to be able to handle objects that don't have a __repr__
attribute. Fixes SF bug #1065456.
1 parent fdc58f2 commit 1b626ca

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/pprint.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _format(self, object, stream, indent, allowance, context, level):
131131
write = stream.write
132132

133133
if sepLines:
134-
r = typ.__repr__
134+
r = getattr(typ, "__repr__", None)
135135
if issubclass(typ, dict) and r is dict.__repr__:
136136
write('{')
137137
if self._indent_per_level > 1:
@@ -229,7 +229,7 @@ def _safe_repr(object, context, maxlevels, level):
229229
write(qget(char, repr(char)[1:-1]))
230230
return ("%s%s%s" % (closure, sio.getvalue(), closure)), True, False
231231

232-
r = typ.__repr__
232+
r = getattr(typ, "__repr__", None)
233233
if issubclass(typ, dict) and r is dict.__repr__:
234234
if not object:
235235
return "{}", True, False

0 commit comments

Comments
 (0)