Skip to content

Commit

Permalink
Enable strict pyright checking
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed May 6, 2024
1 parent e697eb9 commit 646e921
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion aiostream/aiter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
TypeVar,
AsyncIterator,
Any,
cast,
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -110,7 +111,9 @@ def assert_async_iterator(obj: object) -> None:
Self = TypeVar("Self", bound="AsyncIteratorContext[Any]")


class AsyncIteratorContext(AsyncIterator[T], AsyncContextManager[Any]):
class AsyncIteratorContext(
AsyncIterator[T], AsyncContextManager["AsyncIteratorContext[T]"]
):
"""Asynchronous iterator with context management.
The context management makes sure the aclose asynchronous method
Expand Down Expand Up @@ -186,6 +189,7 @@ async def __aexit__(
# No method to throw
if not hasattr(self._aiterator, "athrow"):
return False
self._aiterator = cast(AsyncGenerator[T, None], self._aiterator)

# No frame to throw
if not getattr(self._aiterator, "ag_frame", True):
Expand Down Expand Up @@ -240,6 +244,7 @@ async def athrow(self, exc: Exception) -> T:
if self._state == self._FINISHED:
raise RuntimeError(f"{type(self).__name__} is closed and cannot be used")
assert isinstance(self._aiterator, AsyncGenerator)
self._aiterator = cast(AsyncGenerator[T, None], self._aiterator)
item: T = await self._aiterator.athrow(exc)
return item

Expand Down
1 change: 1 addition & 0 deletions aiostream/stream/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ async def base_combine(
# Setup a new source
if streamer is main_streamer:
assert isinstance(result, AsyncIterable)
result = cast(AsyncIterable[T], result)
await manager.enter_and_create_task(result)

# Re-schedule the main streamer if task limit allows it
Expand Down
5 changes: 3 additions & 2 deletions aiostream/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ContextManager,
Iterator,
cast,
Any,
)

import pytest
Expand Down Expand Up @@ -68,7 +69,7 @@ async def assert_aiter(
exception: Exception | None = None,
) -> None:
"""Check the results of a stream using a streamcontext."""
results = []
results: list[object] = []
exception_type = (type(exception),) if exception else ()
try:
async with streamcontext(source) as streamer:
Expand Down Expand Up @@ -184,7 +185,7 @@ def advance_time(self, advance: float) -> None:
if advance:
self._time += advance

def call_at(self, when: float, callback, *args, **kwargs) -> asyncio.TimerHandle: # type: ignore
def call_at(self, when: float, callback: Callable[..., None], *args: Any, **kwargs: Any) -> asyncio.TimerHandle: # type: ignore
self._timers.append(when)
return super().call_at(when, callback, *args, **kwargs)

Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
addopts = "--strict-markers --cov aiostream"

[tool.pyright]
strict = []
strict = [
"aiostream/aiter_utils.py",
"aiostream/manager.py",
"aiostream/pipe.py",
"aiostream/test_utils.py",
]

[tool.mypy]
packages = ["aiostream", "examples"]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@pytest.mark.asyncio
async def test_aggregate(assert_run, assert_cleanup):
async def test_accumulate(assert_run, assert_cleanup):
with assert_cleanup():
xs = stream.range(5) | add_resource.pipe(1) | pipe.accumulate()
await assert_run(xs, [0, 1, 3, 6, 10])
Expand Down

0 comments on commit 646e921

Please sign in to comment.