Skip to content

Commit a227802

Browse files
giff-hdbrattli
authored andcommitted
Fix return annotation of Observable.__await__
This fixes issues with mypy type checking when awaiting an observable
1 parent 3130ffc commit a227802

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

reactivex/observable/observable.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import asyncio
55
import threading
6-
from typing import Any, Callable, Iterable, Optional, TypeVar, Union, cast, overload
6+
from typing import Any, Callable, Generator, Optional, TypeVar, Union, cast, overload
77

88
from reactivex import abc
99
from reactivex.disposable import Disposable
@@ -256,7 +256,7 @@ def run(self) -> Any:
256256

257257
return run(self)
258258

259-
def __await__(self) -> Iterable[_T]:
259+
def __await__(self) -> Generator[Any, None, _T]:
260260
"""Awaits the given observable.
261261
262262
Returns:
@@ -265,7 +265,10 @@ def __await__(self) -> Iterable[_T]:
265265
from ..operators._tofuture import to_future_
266266

267267
loop = asyncio.get_event_loop()
268-
return iter(self.pipe(to_future_(scheduler=AsyncIOScheduler(loop=loop))))
268+
future: asyncio.Future[_T] = self.pipe(
269+
to_future_(scheduler=AsyncIOScheduler(loop=loop))
270+
)
271+
return future.__await__()
269272

270273
def __add__(self, other: Observable[_T]) -> Observable[_T]:
271274
"""Pythonic version of :func:`concat <reactivex.concat>`.

0 commit comments

Comments
 (0)