Skip to content

Commit b48eed4

Browse files
committed
Fix up is_figurish typechecks.
1 parent ef0f5b7 commit b48eed4

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

src/py/kaleido/_fig_tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Spec(TypedDict):
5959

6060

6161
# validation function
62-
def _is_figurish(o: Any) -> TypeGuard[Figurish]:
62+
def is_figurish(o: Any) -> TypeGuard[Figurish]:
6363
valid = hasattr(o, "to_dict") or (isinstance(o, dict) and "data" in o)
6464
if not valid:
6565
_logger.debug(
@@ -92,7 +92,7 @@ def coerce_for_js(
9292
path: Path | str | None,
9393
opts: LayoutOpts | None,
9494
) -> Spec:
95-
if not _is_figurish(fig): # VALIDATE FIG
95+
if not is_figurish(fig): # VALIDATE FIG
9696
raise TypeError("Figure supplied doesn't seem to be a valid plotly figure.")
9797
if hasattr(fig, "to_dict"): # COERCE FIG
9898
fig = fig.to_dict()

src/py/kaleido/kaleido.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,15 @@ async def write_fig_from_object(
327327
tasks: set[asyncio.Task] = set()
328328

329329
try:
330-
async for args in _utils.ensure_async_iter(generator):
330+
async for fig_arg in _utils.ensure_async_iter(generator):
331331
spec = _fig_tools.coerce_for_js(
332-
args.get("fig"),
333-
args.get("path", None),
334-
args.get("opts", None),
332+
fig_arg.get("fig"),
333+
fig_arg.get("path", None),
334+
fig_arg.get("opts", None),
335335
)
336336

337337
full_path = _path_tools.determine_path(
338-
args.get("path", None),
338+
fig_arg.get("path", None),
339339
spec["data"],
340340
spec["format"], # should just take spec
341341
)
@@ -344,7 +344,7 @@ async def write_fig_from_object(
344344
self._render_task(
345345
spec=spec,
346346
write_path=full_path if _write else None, # bwrds - compat!
347-
topojson=args.get("topojson"),
347+
topojson=fig_arg.get("topojson"),
348348
),
349349
)
350350
tasks.add(t)
@@ -369,7 +369,10 @@ async def write_fig(
369369
cancel_on_error=False,
370370
) -> tuple[None | Exception]: # TODO this should be filtered
371371
"""Temp."""
372-
if not isinstance(fig, (Iterable, AsyncIterable)):
372+
if _fig_tools.is_figurish(fig) or not isinstance(
373+
fig,
374+
(Iterable, AsyncIterable),
375+
):
373376
fig = [fig]
374377

375378
async def _temp_generator():

0 commit comments

Comments
 (0)