-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements and tests for typing (#144)
- Loading branch information
1 parent
1bdfebb
commit d04558f
Showing
4 changed files
with
70 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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 | ||
|
||
|
||
def test_lazy() -> None: | ||
@lazy | ||
def lazy_func(x: int) -> str: | ||
return str(x) | ||
|
||
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] | ||
assert_type(await non_generator.asyncio(1), str) # type: ignore[assert-type] | ||
|
||
await non_generator.asyncio() # type: ignore[call-arg] | ||
await generator.asyncio() # type: ignore[call-arg] | ||
|
||
|
||
def test_async_call() -> None: | ||
def f(x: int) -> str: | ||
return str(x) | ||
|
||
async_call(f, 1) | ||
if TYPE_CHECKING: | ||
async_call(f, 1, task_cls=FutureBase) # TODO: this should be an error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,6 @@ exclude = ''' | |
| \.eggs | ||
)/ | ||
''' | ||
|
||
[tool.mypy] | ||
warn_unused_ignores = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ Cython>=0.27.1 | |
qcore | ||
pygments | ||
black==24.3.0 | ||
mypy==1.4.1 | ||
mypy==1.10.1 | ||
typing_extensions==4.11.0 |