Skip to content

Commit bd5e0fe

Browse files
committed
Fix bad access and typing errors:
Some of these may have been legit errors found by pyright, some of it is just pyright not accepting certain patterns.
1 parent 70388a2 commit bd5e0fe

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

src/py/kaleido/_utils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
_logger = logistro.getLogger(__name__)
1313

1414
if TYPE_CHECKING:
15-
from typing import Any, Callable, Coroutine
15+
from typing import Any, AsyncIterator, Callable, Coroutine
1616

1717

1818
def event_printer(name: str) -> Callable[[Any], Coroutine[Any, Any, None]]:
@@ -39,7 +39,7 @@ def create_task_log_error(coroutine) -> asyncio.Task:
3939
return t
4040

4141

42-
def ensure_async_iter(obj):
42+
def ensure_async_iter(obj) -> AsyncIterator[Any]:
4343
"""Convert any iterable to an async iterator."""
4444
if hasattr(obj, "__aiter__"):
4545
return obj

src/py/kaleido/kaleido.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ async def open(self):
195195
del self._saved_page_arg
196196

197197
if isinstance(page, (Path, str)):
198-
if (_p := _utils.get_path(page)).is_file():
198+
if (_p := path_tools.get_path(page)).is_file():
199199
self._index = _p.as_uri()
200200
else:
201201
raise FileNotFoundError(f"{page!s} does not exist.")
@@ -333,6 +333,8 @@ async def _render_task(
333333
spec["format"], # should just take spec
334334
)
335335
full_path.touch() # claim our name
336+
else:
337+
full_path = None
336338

337339
tab = await self._get_kaleido_tab()
338340

@@ -354,7 +356,7 @@ async def _render_task(
354356
),
355357
self._timeout,
356358
)
357-
if _write:
359+
if _write and full_path:
358360
render_prof.profile_log.tick("starting file write")
359361
await _utils.to_thread(full_path.write_bytes, img_bytes)
360362
render_prof.profile_log.tick("file write done")
@@ -363,7 +365,7 @@ async def _render_task(
363365
return img_bytes
364366
except BaseException as e:
365367
render_prof.profile_log.tick("errored out")
366-
if _write:
368+
if _write and full_path:
367369
full_path.unlink() # failure, no write
368370
render_prof.error = e
369371
raise
@@ -518,15 +520,15 @@ async def calc_fig(
518520
stacklevel=2,
519521
)
520522

521-
async def _temp_generator():
522-
yield {
523+
spec: FigureDict = {
523524
"fig": fig,
524525
"opts": opts,
525526
"topojson": topojson,
526527
}
527-
528-
return await self.write_fig_from_object(
529-
fig_dicts=_temp_generator(),
528+
# pyright > mypy, but:
529+
# pyright doesn't understand literals in overloads as well
530+
return await self.write_fig_from_object( # type: ignore[reportCallIssue]
531+
fig_dicts=spec,
530532
cancel_on_error=True,
531533
_write=False,
532534
stepper=stepper,

src/py/uv.lock

Lines changed: 26 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)