Skip to content

Commit 1fb8210

Browse files
authored
Add casts for coro to help pyright (#1366)
1 parent 3b742a2 commit 1fb8210

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

shiny/_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import tempfile
1515
import warnings
1616
from pathlib import Path
17-
from types import ModuleType
17+
from types import CoroutineType, ModuleType
1818
from typing import Any, Awaitable, Callable, Generator, Optional, TypeVar, cast
1919

2020
from ._typing_extensions import ParamSpec, TypeGuard
@@ -374,6 +374,9 @@ def run_coro_sync(coro: Awaitable[R]) -> R:
374374
if not inspect.iscoroutine(coro):
375375
raise TypeError("run_coro_sync requires a Coroutine object.")
376376

377+
# Pyright needs a little help here
378+
coro = cast("CoroutineType[Any, Any, R]", coro)
379+
377380
try:
378381
coro.send(None)
379382
except StopIteration as e:
@@ -404,6 +407,9 @@ def run_coro_hybrid(coro: Awaitable[R]) -> "asyncio.Future[R]":
404407
if not inspect.iscoroutine(coro):
405408
raise TypeError("run_coro_hybrid requires a Coroutine object.")
406409

410+
# Pyright needs a little help here
411+
coro = cast("CoroutineType[Any, Any, R]", coro)
412+
407413
# Inspired by Task.__step method in cpython/Lib/asyncio/tasks.py
408414
def _step(fut: Optional["asyncio.Future[None]"] = None):
409415
assert result_future.cancelled() or not result_future.done()

0 commit comments

Comments
 (0)