Skip to content

Commit

Permalink
Fix typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrattli committed Dec 12, 2020
1 parent 6cd5b39 commit f1899c5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
8 changes: 5 additions & 3 deletions aioreactive/create.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import logging
from asyncio import Future
from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Optional, Tuple, TypeVar
from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Optional, Tuple, TypeVar, cast

from expression.core import TailCallResult, aiotools, tailrec_async
from expression.core.fn import TailCall
Expand Down Expand Up @@ -66,7 +66,8 @@ async def worker(obv: AsyncObserver[TSource], _: CancellationToken) -> None:
finally:
await obv.aclose()

return of_async_worker(worker)
ret = of_async_worker(worker)
return cast(AsyncObservable[TSource], ret) # NOTE: pyright issue


def of_async_iterable(iterable: AsyncIterable[TSource]) -> AsyncObservable[TSource]:
Expand Down Expand Up @@ -160,7 +161,8 @@ async def worker(obv: AsyncObserver[TSource], token: CancellationToken) -> None:

await obv.aclose()

return of_async_worker(worker)
ret = of_async_worker(worker)
return cast(AsyncObservable[TSource], ret) # NOTE: pyright issue


def defer(factory: Callable[[], AsyncObservable[TSource]]) -> AsyncObservable[TSource]:
Expand Down
2 changes: 1 addition & 1 deletion aioreactive/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
from abc import ABC
from dataclasses import dataclass
from typing import Any, Iterable, NewType, Type, TypeVar, get_origin
from typing import Any, Iterable, NewType, TypeVar, get_origin

from expression.core import SupportsMatch
from expression.system import AsyncDisposable
Expand Down
2 changes: 1 addition & 1 deletion aioreactive/observers.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ async def aclose(self) -> None:
self._is_stopped = True

if self._has_value:
self.set_result(cast(TSource, self._last_value))
self.set_result(cast("TSource", self._last_value))
else:
self.cancel()
await self._aclose()
Expand Down
12 changes: 8 additions & 4 deletions aioreactive/timeshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Iterable, NoReturn, Tuple, TypeVar

from expression.collections import seq
from expression.core import MailboxProcessor, TailCall, TailCallResult, aiotools, match, pipe, snd, tailrec_async
from expression.core import MailboxProcessor, TailCall, TailCallResult, aiotools, match, pipe, fst, tailrec_async
from expression.system import CancellationTokenSource

from .combine import with_latest_from
Expand Down Expand Up @@ -152,8 +152,12 @@ def _sample(source: AsyncObservable[TSource]) -> AsyncObservable[TSource]:
timer = interval(seconds, seconds)

if seconds > 0:
return pipe(source, with_latest_from(timer), map(snd))
else:
return source
return pipe(
source,
with_latest_from(timer),
map(fst),
)

return source

return _sample
14 changes: 9 additions & 5 deletions aioreactive/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def starmap_async(mapper: Callable[[TSource, int], Awaitable[TResult]]) -> Strea
...


def starmap_async(amapper: Callable[..., Awaitable[Any]]) -> Stream[TSource, Any]:
def starmap_async(amapper: Callable[..., Awaitable[TResult]]) -> Stream[Tuple[TSource, ...], TResult]:
"""Map async spreading arguments to the async mapper.
Returns an observable sequence whose elements are the result of
Expand All @@ -96,11 +96,11 @@ def handler(next: Callable[[TResult], Awaitable[None]], x: TSource) -> Awaitable


@overload
def starmap(mapper: Callable[[TSource, int], TResult]) -> Stream[TSource, TResult]:
def starmap(mapper: Callable[[TSource, int], TResult]) -> Stream[Tuple[TSource, int], TResult]:
...


def starmap(mapper: Callable[..., Any]) -> Stream[TSource, Any]:
def starmap(mapper: Callable[..., TResult]) -> Stream[Tuple[TSource, ...], TResult]:
"""Map and spread the arguments to the mapper.
Returns an observable sequence whose elements are the result of
Expand Down Expand Up @@ -291,8 +291,12 @@ async def message_loop(

inner_agent = MailboxProcessor.start(worker)

async def asend(xs: TSource) -> None:
pipe(xs, InnerObservableMsg, inner_agent.post)
async def asend(xs: AsyncObservable[TSource]) -> None:
pipe(
xs,
InnerObservableMsg,
inner_agent.post,
)

async def athrow(error: Exception) -> None:
await safe_obv.athrow(error)
Expand Down
1 change: 0 additions & 1 deletion examples/timeflies/timeflies.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import logging
import signal
import sys
from tkinter import Event, Frame, Label, Misc, Tk
Expand Down

0 comments on commit f1899c5

Please sign in to comment.