Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't crash PuDB when viewing an object with a buggy str() or repr().

  • Loading branch information...
commit 04a64ba43500dee8939067786deeff8ac82c8a3c 1 parent 4a090bf
@pvaret authored
Showing with 16 additions and 9 deletions.
  1. +16 −9 pudb/var_view.py
View
25 pudb/var_view.py
@@ -198,16 +198,17 @@ def keypress(self, size, key):
custom_stringifier_dict = {}
+def type_stringifier(value):
+ if HAVE_NUMPY and isinstance(value, numpy.ndarray):
+ return "ndarray %s %s" % (value.dtype, value.shape)
+ elif isinstance(value, STR_SAFE_TYPES):
+ return str(value)
+ else:
+ return type(value).__name__
+
def get_stringifier(iinfo):
if iinfo.display_type == "type":
- def _stringifier(value):
- if HAVE_NUMPY and isinstance(value, numpy.ndarray):
- return "ndarray %s %s" % (value.dtype, value.shape)
- elif isinstance(value, STR_SAFE_TYPES):
- return str(value)
- else:
- return type(value).__name__
- return _stringifier
+ return type_stringifier
elif iinfo.display_type == "repr":
return repr
elif iinfo.display_type == "str":
@@ -254,7 +255,13 @@ def walk_value(self, prefix, label, value, id_path=None, attr_prefix=None):
elif isinstance(value, (str, unicode)):
self.add_item(prefix, label, repr(value), id_path, attr_prefix)
else:
- displayed_value = get_stringifier(iinfo)(value)
+ try:
+ displayed_value = get_stringifier(iinfo)(value)
+ except Exception:
+ ## Unfortunately, anything can happen when calling str() or
+ ## repr() on a random object.
+ displayed_value = type_stringifier(value) \
+ + " (!! %s error !!)" % iinfo.display_type
self.add_item(prefix, label,
displayed_value, id_path, attr_prefix)
Please sign in to comment.
Something went wrong with that request. Please try again.