Skip to content

Commit

Permalink
Fix tests stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
isra17 committed Apr 3, 2024
1 parent 04e0925 commit 7d786b5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 12 deletions.
22 changes: 10 additions & 12 deletions asyncstdlib/itertools.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -63,53 +63,51 @@ class chain(AsyncIterator[T]):
async def aclose(self) -> None: ...

def compress(data: AnyIterable[T], selectors: AnyIterable[Any]) -> AsyncIterator[T]: ...
async def dropwhile(
def dropwhile(
predicate: Callable[[T], Any], iterable: AnyIterable[T]
) -> AsyncIterator[T]: ...
async def filterfalse(
def filterfalse(
predicate: Callable[[T], Any] | None, iterable: AnyIterable[T]
) -> AsyncIterator[T]: ...
@overload
async def islice(
iterable: AnyIterable[T], start: int | None, /
) -> AsyncIterator[T]: ...
def islice(iterable: AnyIterable[T], start: int | None, /) -> AsyncIterator[T]: ...
@overload
async def islice(
def islice(
iterable: AnyIterable[T],
start: int | None,
stop: int | None,
step: int | None = None,
/,
) -> AsyncIterator[T]: ...
@overload
async def starmap(
def starmap(
function: Callable[[T1], T] | Callable[[T1], Awaitable[T]],
iterable: AnyIterable[tuple[T1]],
) -> AsyncIterator[T]: ...
@overload
async def starmap(
def starmap(
function: Callable[[T1, T2], T] | Callable[[T1, T2], Awaitable[T]],
iterable: AnyIterable[tuple[T1, T2]],
) -> AsyncIterator[T]: ...
@overload
async def starmap(
def starmap(
function: Callable[[T1, T2, T3], T] | Callable[[T1, T2, T3], Awaitable[T]],
iterable: AnyIterable[tuple[T1, T2, T3]],
) -> AsyncIterator[T]: ...
@overload
async def starmap(
def starmap(
function: Callable[[T1, T2, T3, T4], T] | Callable[[T1, T2, T3, T4], Awaitable[T]],
iterable: AnyIterable[tuple[T1, T2, T3, T4]],
) -> AsyncIterator[T]: ...
@overload
async def starmap(
def starmap(
function: (
Callable[[T1, T2, T3, T4, T5], T] | Callable[[T1, T2, T3, T4, T5], Awaitable[T]]
),
iterable: AnyIterable[tuple[T1, T2, T3, T4, T5]],
) -> AsyncIterator[T]: ...
@overload
async def starmap(
def starmap(
function: Callable[..., T] | Callable[..., Awaitable[T]],
iterable: AnyIterable[Iterable[Any]],
) -> AsyncIterator[T]: ...
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typetest = [
"mypy; implementation_name=='cpython'",
"pyright",
"typing-extensions",
"mypy-typing-asserts",
]
doc = ["sphinx", "sphinxcontrib-trio"]

Expand All @@ -52,6 +53,7 @@ Source = "https://github.com/maxfischer2781/asyncstdlib"
include = ["unittests"]

[tool.mypy]
plugins = ["mypy_typing_asserts.mypy_plugin"]
files = ["asyncstdlib", "typetests"]
check_untyped_defs = true
no_implicit_optional = true
Expand Down
57 changes: 57 additions & 0 deletions typetests/test_itertools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import typing as t
from asyncstdlib import itertools
from mypy_typing_asserts import assert_type

async def test_cycle() -> None:
async for x in itertools.cycle([1]):
assert_type[int](x)

async def test_accumulate() -> None:
async for x in itertools.accumulate([1]):

Check failure on line 10 in typetests/test_itertools.py

View workflow job for this annotation

GitHub Actions / build

Type of "x" is unknown (reportUnknownVariableType)

Check failure on line 10 in typetests/test_itertools.py

View workflow job for this annotation

GitHub Actions / build

Argument of type "list[int]" cannot be assigned to parameter "iterable" of type "AnyIterable[ADD@accumulate]" in function "accumulate"   Type "Literal[1]" cannot be assigned to type "SupportsAdd"     "Literal[1]" is incompatible with protocol "SupportsAdd"       "__add__" is an incompatible type         Type "(value: int, /) -> int" cannot be assigned to type "(other: Literal[1]) -> Literal[1]"           Position-only parameter mismatch; parameter "other" is not position-only           Position-only parameter mismatch; expected 1 but received 0           Function return type "int" is incompatible with type "Literal[1]" (reportArgumentType)
assert_type[int](x)

Check failure on line 11 in typetests/test_itertools.py

View workflow job for this annotation

GitHub Actions / build

Argument type is unknown   Argument corresponds to parameter "expression" in function "__new__" (reportUnknownArgumentType)

async def test_batched() -> None:
async for x in itertools.batched([1], 1):
assert_type[tuple[int]](x)

Check failure on line 15 in typetests/test_itertools.py

View workflow job for this annotation

GitHub Actions / build

Subscript for class "tuple" will generate runtime exception; enclose type annotation in quotes

async def test_chain() -> None:
async for x in itertools.chain([1]):
assert_type[int](x)

async def test_compress() -> None:
async for x in itertools.compress([1], [1]):
assert_type[int](x)

async def test_dropwhile() -> None:
async for x in itertools.dropwhile(lambda x: True, [1]):
assert_type[int](x)

async def test_filterfalse() -> None:
async for x in itertools.filterfalse(lambda x: True, [1]):
assert_type[int](x)

async def test_starmap() -> None:
def f(x: str) -> int: return int(x)
async for x in itertools.starmap(f, [("1",)]):
assert_type[int](x)

async def test_takewhile() -> None:
async for x in itertools.takewhile(lambda x: True, [1]):
assert_type[int](x)

async def test_tee() -> None:
async for x in itertools.tee([1])[0]:
assert_type[int](x)

async def test_pairwise() -> None:
async for x in itertools.pairwise([1]):
assert_type[tuple[int, int]](x)

Check failure on line 48 in typetests/test_itertools.py

View workflow job for this annotation

GitHub Actions / build

Subscript for class "tuple" will generate runtime exception; enclose type annotation in quotes

async def test_zip_longest() -> None:
async for x in itertools.zip_longest([1]):
assert_type[tuple[int]](x)

Check failure on line 52 in typetests/test_itertools.py

View workflow job for this annotation

GitHub Actions / build

Subscript for class "tuple" will generate runtime exception; enclose type annotation in quotes

async def test_groupby() -> None:
async for x in itertools.groupby([1]):
assert_type[tuple[int, t.AsyncIterator[int]]](x)

Check failure on line 56 in typetests/test_itertools.py

View workflow job for this annotation

GitHub Actions / build

Subscript for class "tuple" will generate runtime exception; enclose type annotation in quotes

0 comments on commit 7d786b5

Please sign in to comment.