Surround repr() with try / except in case object is unprintable (#65)

This commit is contained in:
Delgan 2019-01-10 23:50:48 +01:00 committed by GitHub
parent d5f56d8136
commit c170bf65a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,7 +113,11 @@ class ExceptionFormatter(object):
return [node for node in ast.walk(tree) if isinstance(node, ast.Name)]
def format_value(self, v):
v = repr(v)
try:
v = repr(v)
except Exception:
v = u'<unprintable %s object>' % type(v).__name__
max_length = self._max_length
if max_length is not None and len(v) > max_length:
v = v[:max_length] + '...'