From a2278022e3c7d827bffe5994be92374032f963dd Mon Sep 17 00:00:00 2001 From: Hameed Gifford Date: Sat, 12 Mar 2022 16:44:42 -0500 Subject: [PATCH] Fix return annotation of Observable.__await__ This fixes issues with mypy type checking when awaiting an observable --- reactivex/observable/observable.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/reactivex/observable/observable.py b/reactivex/observable/observable.py index 74c8af606..d13b4237d 100644 --- a/reactivex/observable/observable.py +++ b/reactivex/observable/observable.py @@ -3,7 +3,7 @@ import asyncio import threading -from typing import Any, Callable, Iterable, Optional, TypeVar, Union, cast, overload +from typing import Any, Callable, Generator, Optional, TypeVar, Union, cast, overload from reactivex import abc from reactivex.disposable import Disposable @@ -256,7 +256,7 @@ def run(self) -> Any: return run(self) - def __await__(self) -> Iterable[_T]: + def __await__(self) -> Generator[Any, None, _T]: """Awaits the given observable. Returns: @@ -265,7 +265,10 @@ def __await__(self) -> Iterable[_T]: from ..operators._tofuture import to_future_ loop = asyncio.get_event_loop() - return iter(self.pipe(to_future_(scheduler=AsyncIOScheduler(loop=loop)))) + future: asyncio.Future[_T] = self.pipe( + to_future_(scheduler=AsyncIOScheduler(loop=loop)) + ) + return future.__await__() def __add__(self, other: Observable[_T]) -> Observable[_T]: """Pythonic version of :func:`concat `.