Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into build-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadeo committed Nov 12, 2024
2 parents 9c90e04 + 97dd284 commit cb79c53
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
5 changes: 2 additions & 3 deletions neptyne_kernel/json_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ def json_clean(obj: Any) -> dict:
def json_default(obj: Any) -> str | int | list | float | None:
if isinstance(obj, Empty):
return None
if hasattr(obj, "__json__"):
return obj.__json__()
try:
from jupyter_client.jsonutil import json_default as jupyter_json_default
except ImportError:
from jupyter_client.jsonutil import date_default as jupyter_json_default

if hasattr(obj, "__json__"):
obj = obj.__json__()

return jupyter_json_default(obj)


Expand Down
3 changes: 2 additions & 1 deletion neptyne_kernel/widgets/register_widget_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Callable

from ..cell_range import CellRange
from ..json_tools import json_default
from ..neptyne_protocol import WidgetParamType
from ..util import list_like
from .base_widget import BaseWidget
Expand Down Expand Up @@ -115,7 +116,7 @@ def test_register_widget():
def test_widgets_with_enums_can_serialize():
scatter = Scatter(x=[1, 2, 3], y=[4, 5, 6], trendline=Scatter.TrendlineType.POLY)

s = json.dumps(scatter)
s = json.dumps(scatter, default=json_default)
scatter2 = Scatter(**json.loads(s))

assert scatter2.trendline == Scatter.TrendlineType.POLY
Expand Down

0 comments on commit cb79c53

Please sign in to comment.