Skip to content

Commit 3597fbd

Browse files
committed
Fall back to monochrome if _colorize/_pyrepl.utils don't reify (import)
1 parent fede255 commit 3597fbd

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Lib/pprint.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,14 @@ def __init__(
214214

215215
def pprint(self, object):
216216
if self._stream is not None:
217-
if self._color and _colorize.can_colorize(file=self._stream):
218-
sio = _StringIO()
219-
self._format(object, sio, 0, 0, {}, 0)
220-
self._stream.write(_colorize_output(sio.getvalue()))
221-
else:
217+
try:
218+
if self._color and _colorize.can_colorize(file=self._stream):
219+
sio = _StringIO()
220+
self._format(object, sio, 0, 0, {}, 0)
221+
self._stream.write(_colorize_output(sio.getvalue()))
222+
else:
223+
self._format(object, self._stream, 0, 0, {}, 0)
224+
except ImportError:
222225
self._format(object, self._stream, 0, 0, {}, 0)
223226
self._stream.write("\n")
224227

0 commit comments

Comments
 (0)