diff --git a/playwright/_impl/_sync_base.py b/playwright/_impl/_sync_base.py index e20caef50..72385719e 100644 --- a/playwright/_impl/_sync_base.py +++ b/playwright/_impl/_sync_base.py @@ -16,7 +16,19 @@ import inspect import traceback from types import TracebackType -from typing import Any, Awaitable, Callable, Dict, Generic, List, Type, TypeVar, cast +from typing import ( + Any, + Callable, + Coroutine, + Dict, + Generator, + Generic, + List, + Type, + TypeVar, + Union, + cast, +) import greenlet @@ -75,10 +87,13 @@ def __init__(self, impl_obj: Any) -> None: def __str__(self) -> str: return self._impl_obj.__str__() - def _sync(self, coro: Awaitable) -> Any: + def _sync( + self, + coro: Union[Coroutine[Any, Any, Any], Generator[Any, Any, Any]], + ) -> Any: __tracebackhide__ = True g_self = greenlet.getcurrent() - task = self._loop.create_task(coro) + task: asyncio.tasks.Task[Any] = self._loop.create_task(coro) setattr(task, "__pw_stack__", inspect.stack()) setattr(task, "__pw_stack_trace__", traceback.extract_stack())