Skip to content

Commit

Permalink
ruff, type checks?
Browse files Browse the repository at this point in the history
  • Loading branch information
chungmin99 committed Apr 21, 2024
1 parent ba6de1c commit 25d670f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/viser/_gui_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
get_origin,
get_type_hints,
)
import plotly.graph_objects as go

from . import _messages
from ._gui_handles import (
Expand All @@ -46,8 +45,8 @@
GuiFolderHandle,
GuiInputHandle,
GuiMarkdownHandle,
GuiPlotlyHandle,
GuiModalHandle,
GuiPlotlyHandle,
GuiTabGroupHandle,
GuiUploadButtonHandle,
SupportsRemoveProtocol,
Expand All @@ -62,6 +61,8 @@
from ._messages import FileTransferPartAck

if TYPE_CHECKING:
import plotly.graph_objects as go

from .infra import ClientId

IntOrFloat = TypeVar("IntOrFloat", int, float)
Expand Down
14 changes: 8 additions & 6 deletions src/viser/_gui_handles.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import imageio.v3 as iio
import numpy as onp
from typing_extensions import Protocol
import plotly.graph_objects as go

from ._icons import svg_from_icon
from ._icons_enum import IconName
Expand All @@ -33,6 +32,8 @@
from .infra import ClientId

if TYPE_CHECKING:
import plotly.graph_objects as go

from ._gui_api import GuiApi
from ._viser import ClientHandle

Expand Down Expand Up @@ -624,13 +625,12 @@ class GuiPlotlyHandle:
_visible: bool
_container_id: str # Parent.
_order: float
_figure: Optional[go.Figure]
_aspect_ratio: Optional[float]
_figure: go.Figure
_aspect_ratio: float

@property
def figure(self) -> str:
def figure(self) -> go.Figure:
"""Current content of this markdown element. Synchronized automatically when assigned."""
assert self._figure is not None
return self._figure

@figure.setter
Expand Down Expand Up @@ -660,7 +660,9 @@ def aspect_ratio(self, aspect_ratio: float) -> None:

def plot_to_json(self) -> str:
"""Convert the plotly figure to an HTML string."""
return self._figure.to_json()
json_str = self._figure.to_json()
assert isinstance(json_str, str)
return json_str

@property
def order(self) -> float:
Expand Down

0 comments on commit 25d670f

Please sign in to comment.