Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions ipykernel/jsonutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from ipython_genutils.encoding import DEFAULT_ENCODING
next_attr_name = '__next__' if py3compat.PY3 else 'next'

if py3compat.PY3:
from collections.abc import MappingView

#-----------------------------------------------------------------------------
# Globals and constants
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -123,6 +126,9 @@ def json_clean(obj):
# containers that we need to convert into lists
container_to_list = (tuple, set, types.GeneratorType)

if py3compat.PY3 and isinstance(obj, MappingView):
obj = list(obj)

# Since bools are a subtype of Integrals, which are a subtype of Reals,
# we have to check them in that order.

Expand All @@ -138,7 +144,7 @@ def json_clean(obj):
if math.isnan(obj) or math.isinf(obj):
return repr(obj)
return float(obj)

if isinstance(obj, atomic_ok):
return obj

Expand Down Expand Up @@ -168,6 +174,6 @@ def json_clean(obj):
return out
if isinstance(obj, datetime):
return obj.strftime(ISO8601)

# we don't understand it, it's probably an unserializable object
raise ValueError("Can't clean for JSON: %r" % obj)