Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hf-kklein committed May 5, 2024
2 parents 8ee03ff + 4a2eff6 commit 2237ac8
Show file tree
Hide file tree
Showing 25 changed files with 472 additions and 463 deletions.
21 changes: 11 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
Quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.0
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: pre-commit/action@v3.0.1

Tests:
runs-on: ${{ matrix.os }}
Expand All @@ -26,28 +26,29 @@ jobs:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install test requirements
run: pip install -r test-requirements.txt
- name: Run tests
run: python setup.py test --addopts "--cov-report xml"
run: python setup.py test
- name: Upload coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
env_vars: OS,PYTHON
token: ${{ secrets.CODECOV_TOKEN }}

Release:
runs-on: ubuntu-latest
needs: [Quality, Tests]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Build source distribution
Expand All @@ -57,7 +58,7 @@ jobs:
pip install wheel
python setup.py bdist_wheel
- name: Publish source package on PyPI
uses: pypa/gh-action-pypi-publish@master
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_password }}
14 changes: 11 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@ repos:
- --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
rev: v1.6.1
hooks:
- id: mypy
files: ^(?!tests)
types: [python]
- id: mypy
files: ^(?!tests)
types: [python]
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.361
hooks:
- id: pyright
additional_dependencies: [pytest, typing-extensions]
types: [python]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.0.272
Expand Down
46 changes: 18 additions & 28 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,7 @@ aiostream
=========


.. image:: https://readthedocs.org/projects/aiostream/badge/?version=latest
:target: http://aiostream.readthedocs.io/en/latest/?badge=latest
:alt:

.. image:: https://codecov.io/gh/vxgmichel/aiostream/branch/master/graph/badge.svg
:target: https://codecov.io/gh/vxgmichel/aiostream
:alt:

.. image:: https://travis-ci.org/vxgmichel/aiostream.svg?branch=master
:target: https://travis-ci.org/vxgmichel/aiostream
:alt:

.. image:: https://img.shields.io/pypi/v/aiostream.svg
:target: https://pypi.python.org/pypi/aiostream
:alt:

.. image:: https://img.shields.io/pypi/pyversions/aiostream.svg
:target: https://pypi.python.org/pypi/aiostream/
:alt:
|docs-badge| |cov-badge| |ci-badge| |version-badge| |pyversion-badge|

Generator-based operators for asynchronous iteration

Expand All @@ -43,14 +25,6 @@ A stream is an enhanced asynchronous iterable providing the following features:
- **Concatenation** - using addition symbol ``+``


Requirements
------------

The stream operators rely heavily on asynchronous generators (`PEP 525`_):

- python >= 3.6


Stream operators
----------------

Expand Down Expand Up @@ -80,7 +54,7 @@ Demonstration

The following example demonstrates most of the streams capabilities:

.. sourcecode:: python
.. code:: python
import asyncio
from aiostream import stream, pipe
Expand Down Expand Up @@ -191,3 +165,19 @@ Vincent Michel: [email protected]

.. _action: http://aiostream.readthedocs.io/en/latest/operators.html#aiostream.stream.action
.. _print: http://aiostream.readthedocs.io/en/latest/operators.html#aiostream.stream.print

.. |docs-badge| image:: https://readthedocs.org/projects/aiostream/badge/?version=latest
:target: http://aiostream.readthedocs.io/en/latest/?badge=latest
:alt:
.. |cov-badge| image:: https://codecov.io/gh/vxgmichel/aiostream/branch/main/graph/badge.svg
:target: https://codecov.io/gh/vxgmichel/aiostream
:alt:
.. |ci-badge| image:: https://github.com/vxgmichel/aiostream/workflows/CI/badge.svg
:target: https://github.com/vxgmichel/aiostream/actions/workflows/ci.yml?query=branch%3Amain
:alt:
.. |version-badge| image:: https://img.shields.io/pypi/v/aiostream.svg
:target: https://pypi.python.org/pypi/aiostream
:alt:
.. |pyversion-badge| image:: https://img.shields.io/pypi/pyversions/aiostream.svg
:target: https://pypi.python.org/pypi/aiostream/
:alt:
14 changes: 9 additions & 5 deletions aiostream/aiter_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Utilities for asynchronous iteration."""

from __future__ import annotations

import sys
from types import TracebackType

import warnings
Expand Down Expand Up @@ -106,7 +108,7 @@ def assert_async_iterator(obj: object) -> None:

# Async iterator context

T = TypeVar("T")
T = TypeVar("T", covariant=True)
Self = TypeVar("Self", bound="AsyncIteratorContext[Any]")


Expand Down Expand Up @@ -200,10 +202,12 @@ async def __aexit__(
# Throw
try:
assert isinstance(self._aiterator, AsyncGenerator)
await self._aiterator.athrow(typ, value, traceback)
raise RuntimeError(
"Async iterator didn't stop after athrow()"
)
if sys.version_info >= (3, 12):
assert value is not None
await self._aiterator.athrow(value)
else:
await self._aiterator.athrow(typ, value, traceback)
raise RuntimeError("Async iterator didn't stop after athrow()")

# Exception has been (most probably) silenced
except StopAsyncIteration as exc:
Expand Down
16 changes: 1 addition & 15 deletions aiostream/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class StreamEmpty(Exception):

# Helpers

T = TypeVar("T")
T = TypeVar("T", covariant=True)
X = TypeVar("X")
A = TypeVar("A", contravariant=True)
P = ParamSpec("P")
Expand Down Expand Up @@ -345,17 +345,6 @@ async def random(offset=0., width=1.):
"since the decorated function becomes an operator class"
)

# Look for "more_sources"
for i, p in enumerate(parameters):
if (
p.name == "more_sources"
and p.kind == inspect.Parameter.VAR_POSITIONAL
):
more_sources_index = i
break
else:
more_sources_index = None

# Injected parameters
self_parameter = inspect.Parameter(
"self", inspect.Parameter.POSITIONAL_OR_KEYWORD
Expand All @@ -372,9 +361,6 @@ async def random(offset=0., width=1.):

# Init method
def init(self: BaseStream[T], *args: P.args, **kwargs: P.kwargs) -> None:
if more_sources_index is not None:
for source in args[more_sources_index:]:
assert_async_iterable(source)
factory = functools.partial(raw, *args, **kwargs)
return BaseStream.__init__(self, factory)

Expand Down
9 changes: 5 additions & 4 deletions aiostream/stream/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
TypeVar,
AsyncIterator,
cast,
Type,
)
from typing_extensions import ParamSpec
from typing_extensions import ParamSpec, Never

from ..stream import time
from ..core import operator, streamcontext
Expand Down Expand Up @@ -122,22 +123,22 @@ async def call(


@operator
async def throw(exc: Exception) -> AsyncIterator[None]:
async def throw(exc: Exception | Type[Exception]) -> AsyncIterator[Never]:
"""Throw an exception without generating any value."""
if False:
yield
raise exc


@operator
async def empty() -> AsyncIterator[None]:
async def empty() -> AsyncIterator[Never]:
"""Terminate without generating any value."""
if False:
yield


@operator
async def never() -> AsyncIterator[None]:
async def never() -> AsyncIterator[Never]:
"""Hang forever without generating any value."""
if False:
yield
Expand Down
2 changes: 1 addition & 1 deletion aiostream/stream/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async def filterindex(


@pipable_operator
def slice(source: AsyncIterable[T], *args: int) -> AsyncIterator[T]:
def slice(source: AsyncIterable[T], *args: int | None) -> AsyncIterator[T]:
"""Slice an asynchronous sequence.
The arguments are the same as the builtin type slice.
Expand Down
Loading

0 comments on commit 2237ac8

Please sign in to comment.