Skip to content

Commit

Permalink
fixes, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Jul 16, 2024
1 parent 1d7e2b9 commit 570b06d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
16 changes: 4 additions & 12 deletions asynq/decorators.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def get_async_or_sync_fn(fn: object) -> Any: ...
class PureAsyncDecoratorBinder(qcore.decorators.DecoratorBinder):
def is_pure_async_fn(self) -> bool: ...

class PureAsyncDecorator(
qcore.decorators.DecoratorBase, Generic[_T, _P]
):
class PureAsyncDecorator(qcore.decorators.DecoratorBase, Generic[_T, _P]):
binder_cls = PureAsyncDecoratorBinder
def __init__(
self,
Expand All @@ -47,9 +45,7 @@ class PureAsyncDecorator(
def name(self) -> str: ...
def is_pure_async_fn(self) -> bool: ...
def asyncio(
self,
*args: _P.args,
**kwargs: _P.kwargs,
self, *args: _P.args, **kwargs: _P.kwargs
) -> Coroutine[Any, Any, _T]: ...
def __call__(
self, *args: Any, **kwargs: Any
Expand Down Expand Up @@ -105,14 +101,10 @@ class AsyncAndSyncPairProxyDecorator(AsyncProxyDecorator[_T, _P]):
def __call__(self, *args: Any, **kwargs: Any) -> _T: ...

class _MkAsyncDecorator:
def __call__(
self, fn: Callable[_P, Any]
) -> AsyncDecorator[Any, _P]: ...
def __call__(self, fn: Callable[_P, Any]) -> AsyncDecorator[Any, _P]: ...

class _MkPureAsyncDecorator:
def __call__(
self, fn: Callable[_P, _T]
) -> PureAsyncDecorator[_T, _P]: ...
def __call__(self, fn: Callable[_P, _T]) -> PureAsyncDecorator[_T, _P]: ...

# In reality these two can return other Decorator subclasses, but that doesn't matter for callers.
@overload
Expand Down
18 changes: 10 additions & 8 deletions asynq/tests/test_typing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Any, Generator, TypeVar, overload, Callable
from typing_extensions import ParamSpec, reveal_type, assert_type
from typing import Any, Generator, TYPE_CHECKING
from typing_extensions import assert_type
from asynq.decorators import async_call, lazy, asynq
from asynq.futures import FutureBase

Expand All @@ -8,20 +8,21 @@ def test_lazy() -> None:
@lazy
def lazy_func(x: int) -> str:
return str(x)

assert_type(lazy_func(1), FutureBase[str])

if TYPE_CHECKING:
assert_type(lazy_func(1), FutureBase[str])


def test_dot_asyncio() -> None:
@asynq()
def non_generator(x: int) -> str:
return str(x)

@asynq()
def generator(x: int) -> Generator[Any, Any, str]:
yield None
return str(x)

async def caller() -> None:
# This doesn't work, apparently due to a mypy bug
assert_type(await generator.asyncio(1), str) # type: ignore[assert-type]
Expand All @@ -34,6 +35,7 @@ async def caller() -> None:
def test_async_call() -> None:
def f(x: int) -> str:
return str(x)

async_call(f, 1)
async_call(f, 1, task_cls=FutureBase) # TODO: this should be an error
if TYPE_CHECKING:
async_call(f, 1, task_cls=FutureBase) # TODO: this should be an error

0 comments on commit 570b06d

Please sign in to comment.