Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def type_stringifier(value):
if HAVE_NUMPY and isinstance(value, numpy.ndarray):
return text_type("ndarray %s %s") % (value.dtype, value.shape)
elif HAVE_NUMPY and isinstance(value, numpy.number):
return text_type("%s (%s)" % (value, value.dtype))
elif isinstance(value, STR_SAFE_TYPES):
try:
return text_type(value)
except Exception:
pass
elif hasattr(type(value), "safely_stringify_for_pudb"):
try:
# (E.g.) Mock objects will pretend to have this
# and return nonsense.
result = value.safely_stringify_for_pudb()
except Exception:
pass
else:
if isinstance(result, string_types):
return text_type(result)
elif type(value) in [set, frozenset, list, tuple, dict]:
return text_type("%s (%s)") % (type(value).__name__, len(value))
except Exception:
pass
elif hasattr(type(value), "safely_stringify_for_pudb"):
try:
# (E.g.) Mock objects will pretend to have this
# and return nonsense.
result = value.safely_stringify_for_pudb()
except Exception:
pass
else:
if isinstance(result, string_types):
return text_type(result)
elif type(value) in [set, frozenset, list, tuple, dict]:
return text_type("%s (%s)") % (type(value).__name__, len(value))
return text_type(type(value).__name__)
elif hasattr(type(value), "safely_stringify_for_pudb"):
try:
# (E.g.) Mock objects will pretend to have this
# and return nonsense.
result = value.safely_stringify_for_pudb()
except Exception:
pass
else:
if isinstance(result, string_types):
return text_type(result)
elif type(value) in [set, frozenset, list, tuple, dict]:
return text_type("%s (%s)") % (type(value).__name__, len(value))
return text_type(type(value).__name__)
def type_stringifier(value):
if HAVE_NUMPY and isinstance(value, numpy.ndarray):
return text_type("ndarray %s %s") % (value.dtype, value.shape)
elif HAVE_NUMPY and isinstance(value, numpy.number):
return text_type("%s (%s)" % (value, value.dtype))
elif isinstance(value, STR_SAFE_TYPES):
try:
return text_type(value)
except Exception:
pass
elif hasattr(type(value), "safely_stringify_for_pudb"):
try:
# (E.g.) Mock objects will pretend to have this
# and return nonsense.
result = value.safely_stringify_for_pudb()
except Exception:
elif isinstance(value, STR_SAFE_TYPES):
try:
return text_type(value)
except Exception:
pass
elif hasattr(type(value), "safely_stringify_for_pudb"):
try:
# (E.g.) Mock objects will pretend to have this
# and return nonsense.
result = value.safely_stringify_for_pudb()
except Exception:
pass
else:
if isinstance(result, string_types):
return text_type(result)
elif type(value) in [set, frozenset, list, tuple, dict]:
return text_type("%s (%s)") % (type(value).__name__, len(value))
return text_type(type(value).__name__)
return lambda value: text_type(
"ERROR: Invalid custom stringifier file: "
"pudb_stringifer not defined.")
return (lambda value:
text_type(custom_stringifier_dict["pudb_stringifier"](value)))