Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding #6

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
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
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
Loading