Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore/format/ci: use black stable style 2024; bump flake8 version; add black config to pyproject.toml #100

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/ambv/black
rev: 23.3.0
rev: 24.3.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
rev: 7.0.0
hooks:
- id: flake8
args:
- --extend-ignore=E704
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
- repo: https://github.com/pre-commit/mirrors-mypy
# We can't use the latest version due to a regression in mypy 1.7.0
# See https://github.com/python/mypy/issues/17191 for more information
Expand Down
1 change: 1 addition & 0 deletions aiostream/aiter_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for asynchronous iteration."""

from __future__ import annotations

import sys
Expand Down
21 changes: 10 additions & 11 deletions aiostream/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Core objects for stream operators."""

from __future__ import annotations

import inspect
Expand Down Expand Up @@ -258,28 +259,23 @@ def streamcontext(aiterable: AsyncIterable[T]) -> Streamer[T]:


class OperatorType(Protocol[P, T]):
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Stream[T]:
...
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Stream[T]: ...

def raw(self, *args: P.args, **kwargs: P.kwargs) -> AsyncIterator[T]:
...
def raw(self, *args: P.args, **kwargs: P.kwargs) -> AsyncIterator[T]: ...


class PipableOperatorType(Protocol[A, P, T]):
def __call__(
self, source: AsyncIterable[A], /, *args: P.args, **kwargs: P.kwargs
) -> Stream[T]:
...
) -> Stream[T]: ...

def raw(
self, source: AsyncIterable[A], /, *args: P.args, **kwargs: P.kwargs
) -> AsyncIterator[T]:
...
) -> AsyncIterator[T]: ...

def pipe(
self, *args: P.args, **kwargs: P.kwargs
) -> Callable[[AsyncIterable[A]], Stream[T]]:
...
) -> Callable[[AsyncIterable[A]], Stream[T]]: ...


# Operator decorator
Expand Down Expand Up @@ -494,7 +490,10 @@ def raw(

# Init method
def init(
self: BaseStream[T], arg: AsyncIterable[X], *args: P.args, **kwargs: P.kwargs
self: BaseStream[T],
arg: AsyncIterable[X],
*args: P.args,
**kwargs: P.kwargs,
) -> None:
assert_async_iterable(arg)
if more_sources_index is not None:
Expand Down
1 change: 1 addition & 0 deletions aiostream/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Provide a context to easily manage several streamers running
concurrently.
"""

from __future__ import annotations

import asyncio
Expand Down
1 change: 1 addition & 0 deletions aiostream/pipe.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Gather the pipe operators."""

from __future__ import annotations

from . import stream
Expand Down
7 changes: 4 additions & 3 deletions aiostream/stream/advanced.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Advanced operators (to deal with streams of higher order) ."""

from __future__ import annotations

from typing import AsyncIterator, AsyncIterable, TypeVar, Union, cast
Expand Down Expand Up @@ -46,9 +47,9 @@ async def base_combine(

# Safe context
async with StreamerManager[Union[AsyncIterable[T], T]]() as manager:
main_streamer: Streamer[
AsyncIterable[T] | T
] | None = await manager.enter_and_create_task(source)
main_streamer: Streamer[AsyncIterable[T] | T] | None = (
await manager.enter_and_create_task(source)
)

# Loop over events
while manager.tasks:
Expand Down
10 changes: 9 additions & 1 deletion aiostream/stream/aggregate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
"""Aggregation operators."""

from __future__ import annotations

import asyncio
import builtins
import operator as op
from typing import AsyncIterator, Awaitable, Callable, TypeVar, AsyncIterable, cast
from typing import (
AsyncIterator,
Awaitable,
Callable,
TypeVar,
AsyncIterable,
cast,
)


from . import select
Expand Down
10 changes: 4 additions & 6 deletions aiostream/stream/combine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Combination operators."""

from __future__ import annotations

import asyncio
Expand Down Expand Up @@ -93,18 +94,15 @@ async def zip(


class SmapCallable(Protocol[X, Y]):
def __call__(self, arg: X, /, *args: X) -> Y:
...
def __call__(self, arg: X, /, *args: X) -> Y: ...


class AmapCallable(Protocol[X, Y]):
async def __call__(self, arg: X, /, *args: X) -> Y:
...
async def __call__(self, arg: X, /, *args: X) -> Y: ...


class MapCallable(Protocol[X, Y]):
def __call__(self, arg: X, /, *args: X) -> Awaitable[Y] | Y:
...
def __call__(self, arg: X, /, *args: X) -> Awaitable[Y] | Y: ...


@pipable_operator
Expand Down
11 changes: 6 additions & 5 deletions aiostream/stream/create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Non-pipable creation operators."""

from __future__ import annotations

import sys
Expand Down Expand Up @@ -96,18 +97,18 @@ async def just(value: T) -> AsyncIterator[T]:


class SyncCallable(Protocol[P, Y]):
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Y:
...
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Y: ...


class AsyncCallable(Protocol[P, Y]):
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Awaitable[Y]:
...
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Awaitable[Y]: ...


@operator
async def call(
func: SyncCallable[P, T] | AsyncCallable[P, T], *args: P.args, **kwargs: P.kwargs
func: SyncCallable[P, T] | AsyncCallable[P, T],
*args: P.args,
**kwargs: P.kwargs,
) -> AsyncIterator[T]:
"""Call the given function and generate a single value.

Expand Down
10 changes: 9 additions & 1 deletion aiostream/stream/misc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
"""Extra operators."""

from __future__ import annotations

import asyncio
import builtins

from typing import TypeVar, Awaitable, Callable, AsyncIterable, AsyncIterator, Any
from typing import (
TypeVar,
Awaitable,
Callable,
AsyncIterable,
AsyncIterator,
Any,
)

from .combine import amap, smap
from ..core import pipable_operator
Expand Down
1 change: 1 addition & 0 deletions aiostream/stream/select.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Selection operators."""

from __future__ import annotations

import asyncio
Expand Down
1 change: 1 addition & 0 deletions aiostream/stream/time.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Time-specific operators."""

from __future__ import annotations
import asyncio

Expand Down
6 changes: 2 additions & 4 deletions aiostream/stream/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ async def enumerate(


class AsyncStarmapCallable(Protocol[X, Y]):
def __call__(self, arg: X, /, *args: X) -> Awaitable[Y]:
...
def __call__(self, arg: X, /, *args: X) -> Awaitable[Y]: ...


class SyncStarmapCallable(Protocol[X, Y]):
def __call__(self, arg: X, /, *args: X) -> Y:
...
def __call__(self, arg: X, /, *args: X) -> Y: ...


@pipable_operator
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ addopts = "--strict-markers --cov aiostream"
[tool.pyright]
ignore = ["aiostream/test_utils.py"]

[tool.black]
line-length = 88
target_version = ["py38", "py39", "py310", "py311", "py312"]

[tool.mypy]
strict = true
packages = ["aiostream", "examples"]
Loading