Skip to content

Commit

Permalink
Fix return annotation of Observable.__await__
Browse files Browse the repository at this point in the history
This fixes issues with mypy type checking when awaiting an observable
  • Loading branch information
giff-h authored and dbrattli committed Mar 13, 2022
1 parent 3130ffc commit a227802
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions reactivex/observable/observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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 <reactivex.concat>`.
Expand Down

0 comments on commit a227802

Please sign in to comment.