Call repr() when pretty() fails in _pprint_displayhook

This commit is contained in:
Daniel Shimon 2020-08-05 17:42:19 +03:00
parent 40352638bf
commit d41e6ddf72
2 changed files with 26 additions and 1 deletions

View file

@ -0,0 +1,23 @@
**Added:**
* <news item>
**Changed:**
* <news item>
**Deprecated:**
* <news item>
**Removed:**
* <news item>
**Fixed:**
* Viewing mock objects in the shell
**Security:**
* <news item>

View file

@ -251,9 +251,11 @@ def _pprint_displayhook(value):
builtins._ = value
return
env = builtins.__xonsh__.env
printed_val = None
if env.get("PRETTY_PRINT_RESULTS"):
printed_val = pretty(value)
else:
if not isinstance(printed_val, str):
# pretty may fail (i.e for unittest.mock.Mock)
printed_val = repr(value)
if HAS_PYGMENTS and env.get("COLOR_RESULTS"):
tokens = list(pygments.lex(printed_val, lexer=pyghooks.XonshLexer()))