From 8e134e9b9deba30d4e988fc2410c60dd3f703b23 Mon Sep 17 00:00:00 2001 From: Dag Brattli Date: Thu, 12 Nov 2026 02:19:56 +0100 Subject: [PATCH 1/2] feat!: require Python 3.12 and modernize type parameters --- .github/workflows/python-package.yml | 2 +- AGENTS.md | 2 +- README.md | 8 +- README.py | 8 +- TAGGED_UNION_PROPOSAL.md | 4 +- docs/guides/getting-started.py | 19 +- docs/guides/migration-major.md | 15 +- docs/intro.md | 2 +- expression/__init__.py | 2 +- expression/collections/array.py | 119 ++- expression/collections/asyncseq.py | 45 +- expression/collections/block.py | 163 ++-- expression/collections/map.py | 111 +-- expression/collections/maptree.py | 99 ++- expression/collections/seq.py | 267 +++--- expression/core/aiotools.py | 32 +- expression/core/apipe.py | 168 ++-- expression/core/async_builder.py | 65 +- expression/core/builder.py | 57 +- expression/core/compose.py | 163 ++-- expression/core/curry.py | 103 +-- expression/core/fn.py | 32 +- expression/core/mailbox.py | 40 +- expression/core/misc.py | 23 +- expression/core/option.py | 121 +-- expression/core/pipe.py | 819 +++++++++--------- expression/core/result.py | 18 +- expression/core/tagged_union.py | 20 +- expression/core/try_.py | 7 +- expression/core/typing.py | 20 +- expression/effect/async_option.py | 41 +- expression/effect/async_result.py | 46 +- expression/effect/option.py | 35 +- expression/effect/result.py | 42 +- expression/effect/seq.py | 30 +- expression/extra/async_result/async_result.py | 15 +- expression/extra/option/pipeline.py | 70 +- expression/extra/parser.py | 140 ++- expression/extra/result/catch.py | 35 +- expression/extra/result/pipeline.py | 74 +- expression/extra/result/traversable.py | 25 +- pyproject.toml | 10 +- pyrightconfig.json | 5 +- tests/test_union_schema.py | 16 + tests/typing_contracts.py | 13 + typing_tests/pyrightconfig.json | 2 +- uv.lock | 169 +--- 47 files changed, 1530 insertions(+), 1792 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 71a20ba2..6f93bed4 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"] + python-version: ["3.12", "3.13", "3.14", "3.15"] steps: - uses: actions/checkout@v7 diff --git a/AGENTS.md b/AGENTS.md index c2187a1d..0f95cccb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -26,7 +26,7 @@ release pull requests. Do not hand-edit generated release entries. ## Coding Style & Naming Conventions -Write Python compatible with 3.11 and follow PEP 8. Ruff enforces a 120-character line +Write Python compatible with 3.12 and follow PEP 8. Ruff enforces a 120-character line limit, import ordering, Google-style docstrings, and the configured lint rules; Pyright runs in strict mode. Use four-space indentation, `snake_case` for functions and modules, `PascalCase` for classes and tagged-union types, and leading underscores for internal diff --git a/README.md b/README.md index ae2f1836..3c8c6c70 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Expression aims to be a solid, type-safe, pragmatic, and high performance library for -frictionless and practical functional programming in Python 3.11+. +frictionless and practical functional programming in Python 3.12+. By pragmatic, we mean that the goal of the library is to use simple abstractions to enable you to do practical and productive functional programming in Python (instead of @@ -57,7 +57,7 @@ many ways very similar to Python, but F# can also do a lot of things better than ## Getting Started You can install the latest `expression` from PyPI by running `pip` (or -`pip3`). Note that `expression` only works for Python 3.11+. +`pip3`). Note that `expression` only works for Python 3.12+. ```console > pip install expression @@ -625,7 +625,7 @@ Each case exposes only its own fields. `Option` and `Result` use this same model ```python from dataclasses import asdict -from typing import Literal, TypeAlias, assert_never, final +from typing import Literal, assert_never, final from expression import TaggedUnion, case, tag @@ -645,7 +645,7 @@ class Circle: tag: Literal["circle"] = tag() -Shape: TypeAlias = TaggedUnion[Rectangle | Circle] +type Shape = TaggedUnion[Rectangle | Circle] ``` diff --git a/README.py b/README.py index 1ab0ae8e..a6e0bf4e 100644 --- a/README.py +++ b/README.py @@ -18,7 +18,7 @@ # %% [markdown] """ Expression aims to be a solid, type-safe, pragmatic, and high performance library for -frictionless and practical functional programming in Python 3.11+. +frictionless and practical functional programming in Python 3.12+. By pragmatic, we mean that the goal of the library is to use simple abstractions to enable you to do practical and productive functional programming in Python (instead of @@ -66,7 +66,7 @@ ## Getting Started You can install the latest `expression` from PyPI by running `pip` (or -`pip3`). Note that `expression` only works for Python 3.11+. +`pip3`). Note that `expression` only works for Python 3.12+. ```console > pip install expression @@ -689,7 +689,7 @@ async def outer_option() -> AsyncGenerator[int, int]: # %% from dataclasses import asdict -from typing import Literal, TypeAlias, assert_never, final +from typing import Literal, assert_never, final from expression import TaggedUnion, case, tag @@ -709,7 +709,7 @@ class Circle: tag: Literal["circle"] = tag() -Shape: TypeAlias = TaggedUnion[Rectangle | Circle] +type Shape = TaggedUnion[Rectangle | Circle] # %% [markdown] diff --git a/TAGGED_UNION_PROPOSAL.md b/TAGGED_UNION_PROPOSAL.md index 0d03dd5c..e1486f2f 100644 --- a/TAGGED_UNION_PROPOSAL.md +++ b/TAGGED_UNION_PROPOSAL.md @@ -1,7 +1,7 @@ # Tagged unions: implementation and rationale **Status:** Implemented for the next major version of Expression. -**Minimum Python:** 3.11. **Optional Pydantic:** 2.10 or later, below 3. +**Minimum Python:** 3.12. **Optional Pydantic:** 2.10 or later, below 3. Expression now represents tagged unions as explicit, frozen, final case classes combined in public type aliases. Each case declares only its own payload. The @@ -362,7 +362,7 @@ namespace. `Option.Some`, `Result.Ok`, direct union-class construction, and old ordering is also removed. Container awaiting and generator-based Option/Result computations are preserved. See the [migration guide](docs/guides/migration-major.md) for replacements. -The supported minimum is Python 3.11. The repository pins Pyright **1.1.414** in +The supported minimum is Python 3.12. The repository pins Pyright **1.1.414** in [pre-commit](.pre-commit-config.yaml); the design relies on explicit unions and dataclass typing, not on a checker-specific plugin. Versioned dependency requirements live in [pyproject.toml](pyproject.toml). diff --git a/docs/guides/getting-started.py b/docs/guides/getting-started.py index 04504471..fd6afa8a 100644 --- a/docs/guides/getting-started.py +++ b/docs/guides/getting-started.py @@ -2,7 +2,7 @@ """ # Getting started -Expression works with Python 3.11 and later. Install it from PyPI: +Expression works with Python 3.12 and later. Install it from PyPI: ```console python -m pip install expression @@ -25,10 +25,19 @@ scores = [4, 7, 12, 15] + +def qualifies(score: int) -> bool: + return score >= 10 + + +def double(score: int) -> int: + return score * 2 + + total = pipe( scores, - seq.filter(lambda score: score >= 10), - seq.map(lambda score: score * 2), + seq.filter(qualifies), + seq.map(double), seq.sum, ) @@ -48,7 +57,9 @@ """ Both styles use ordinary Python functions, type hints, and values. Choose the style that your team finds easiest to read; the functional form is often easier to extend one step -per line. +per line. Named functions with parameter annotations let type checkers infer the +functional pipeline's intermediate types; unannotated lambdas inside curried calls +may not receive enough type information from the surrounding `pipe` call. ## Where to go next diff --git a/docs/guides/migration-major.md b/docs/guides/migration-major.md index cf0cd8b6..57b3936b 100644 --- a/docs/guides/migration-major.md +++ b/docs/guides/migration-major.md @@ -1,9 +1,22 @@ # Migrating to case unions -This major version requires Python 3.11 or later. The optional Pydantic +This major version requires Python 3.12 or later. The optional Pydantic integration requires Pydantic 2.10 or later to preserve generic payload validation when caller and library type-variable names overlap. +Expression supports at least the latest three stable Python versions. Minimum +Python versions are raised in major releases; this release supports 3.12–3.15. +Python 3.11 users must remain on the previous major version. + +Generic functions and classes now use Python 3.12 type parameters, for example +`def identity[T](value: T) -> T` and `class Seq[T]`. Explicit `TypeVar` +declarations remain where they preserve case covariance or type parameter +defaults, which the new syntax cannot express on Python 3.12. The public +`Option`, `Result`, and `TaggedUnion` aliases remain evaluated aliases for +runtime introspection and Pydantic integration. `Block` and `Map` retain their +legacy class declarations to preserve weak references on early Python 3.12 +patch releases; their generic methods use modern type parameters. + Option and Result now use explicit frozen case classes. Their public types are unions: `Option[T]` consists of `Some[T]` and `Nothing`; `Result[T, E]` consists of `Ok[T]` and `Error[E]`. Each case has only its own payload. Both static checking diff --git a/docs/intro.md b/docs/intro.md index 40512222..a539af77 100644 --- a/docs/intro.md +++ b/docs/intro.md @@ -1,6 +1,6 @@ # Expression -Expression is a practical, typed functional-programming library for Python 3.11+. +Expression is a practical, typed functional-programming library for Python 3.12+. It adds small, composable tools for common Python problems: - transform data in readable pipelines; diff --git a/expression/__init__.py b/expression/__init__.py index f8e5fde8..5600a59f 100644 --- a/expression/__init__.py +++ b/expression/__init__.py @@ -1,7 +1,7 @@ """Expression library. Expression aims to be a solid, type-safe, pragmatic, and high -performance library for practical functional programming in Python 3.11+. +performance library for practical functional programming in Python 3.12+. By pragmatic we mean that the goal of the library is to use simple abstractions to enable you to do practical and productive functional programming in Python. diff --git a/expression/collections/array.py b/expression/collections/array.py index b98b49e8..f20b34a0 100644 --- a/expression/collections/array.py +++ b/expression/collections/array.py @@ -14,7 +14,7 @@ import functools from collections.abc import Callable, Iterable, Iterator, MutableSequence from enum import Enum -from typing import Any, TypeVar, cast +from typing import Any, cast from expression.core import ( NOTHING, @@ -30,14 +30,7 @@ from . import seq -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") -_TState = TypeVar("_TState") - -_TSourceSortable = TypeVar("_TSourceSortable", bound=SupportsLessThan) - -_TSourceSum = TypeVar("_TSourceSum", bound=SupportsSum) -_Array = list[_TSourceSum] | MutableSequence[_TSourceSum] +type _Array[TSourceSum: SupportsSum] = list[TSourceSum] | MutableSequence[TSourceSum] class int8(int): ... @@ -165,7 +158,7 @@ def array_from_initializer( return arr, type_code -class TypedArray(MutableSequence[_TSource], PipeMixin): +class TypedArray[TSource](MutableSequence[TSource], PipeMixin): __match_args__ = ( "initializer", "typecode", @@ -173,7 +166,7 @@ class TypedArray(MutableSequence[_TSource], PipeMixin): def __init__( self, - initializer: Iterable[_TSource] | None = None, + initializer: Iterable[TSource] | None = None, typecode: TypeCode | None = None, ) -> None: if typecode: @@ -184,11 +177,11 @@ def __init__( self.value: _Array[Any] = arr self.typecode = typecode - def map(self, mapping: Callable[[_TSource], _TResult]) -> TypedArray[_TResult]: + def map[TResult](self, mapping: Callable[[TSource], TResult]) -> TypedArray[TResult]: result = builtins.map(mapping, self.value) return TypedArray(result) - def choose(self, chooser: Callable[[_TSource], Option[_TResult]]) -> TypedArray[_TResult]: + def choose[TResult](self, chooser: Callable[[TSource], Option[TResult]]) -> TypedArray[TResult]: """Choose items from the list. Applies the given function to each element of the list. Returns @@ -203,17 +196,17 @@ def choose(self, chooser: Callable[[_TSource], Option[_TResult]]) -> TypedArray[ function. """ - def mapper(x: _TSource) -> TypedArray[_TResult]: + def mapper(x: TSource) -> TypedArray[TResult]: return TypedArray(chooser(x).to_seq()) return self.collect(mapper) - def collect(self, mapping: Callable[[_TSource], TypedArray[_TResult]]) -> TypedArray[_TResult]: + def collect[TResult](self, mapping: Callable[[TSource], TypedArray[TResult]]) -> TypedArray[TResult]: mapped = builtins.map(mapping, self.value) xs = (y for x in mapped for y in x) return TypedArray(xs) - def insert(self, index: int, value: _TSource) -> None: + def insert(self, index: int, value: TSource) -> None: self.value.insert(index, value) def is_empty(self) -> bool: @@ -225,7 +218,7 @@ def empty(cls) -> TypedArray[Any]: """Returns empty array.""" return TypedArray() - def filter(self, predicate: Callable[[_TSource], bool]) -> TypedArray[_TSource]: + def filter(self, predicate: Callable[[TSource], bool]) -> TypedArray[TSource]: """Filter list. Returns a new collection containing only the elements of the @@ -240,7 +233,7 @@ def filter(self, predicate: Callable[[_TSource], bool]) -> TypedArray[_TSource]: """ return TypedArray(builtins.filter(predicate, self.value), typecode=self.typecode) - def fold(self, folder: Callable[[_TState, _TSource], _TState], state: _TState) -> _TState: + def fold[TState](self, folder: Callable[[TState, TSource], TState], state: TState) -> TState: """Fold array. Applies a function to each element of the array, @@ -263,7 +256,7 @@ def fold(self, folder: Callable[[_TState, _TSource], _TState], state: _TState) - """ return functools.reduce(folder, self, state) - def forall(self, predicate: Callable[[_TSource], bool]) -> bool: + def forall(self, predicate: Callable[[TSource], bool]) -> bool: """Test all elements. Tests if all elements of the collection satisfy the given @@ -277,7 +270,7 @@ def forall(self, predicate: Callable[[_TSource], bool]) -> bool: """ return all(predicate(x) for x in self) - def head(self) -> _TSource: + def head(self) -> TSource: """Returns the first element of the list. Args: @@ -292,7 +285,7 @@ def head(self) -> _TSource: head, *_ = self return head - def indexed(self, start: int = 0) -> TypedArray[tuple[int, _TSource]]: + def indexed(self, start: int = 0) -> TypedArray[tuple[int, TSource]]: """Index array elements. Returns a new array whose elements are the corresponding @@ -307,7 +300,7 @@ def indexed(self, start: int = 0) -> TypedArray[tuple[int, _TSource]]: """ return of_seq(enumerate(self)) - def item(self, index: int) -> _TSource: + def item(self, index: int) -> TSource: """Indexes into the list. The first element has index 0. Args: @@ -319,16 +312,16 @@ def item(self, index: int) -> _TSource: return self.value[index] @staticmethod - def of(*args: _TSource) -> TypedArray[_TSource]: + def of(*args: TSource) -> TypedArray[TSource]: """Create list from a number of arguments.""" return TypedArray((*args,)) @staticmethod - def of_seq(xs: Iterable[_TSource]) -> TypedArray[_TSource]: + def of_seq(xs: Iterable[TSource]) -> TypedArray[TSource]: """Create list from iterable sequence.""" return TypedArray((*xs,)) - def skip(self, count: int) -> TypedArray[_TSource]: + def skip(self, count: int) -> TypedArray[TSource]: """Returns the array after removing the first N elements. Args: @@ -339,10 +332,12 @@ def skip(self, count: int) -> TypedArray[_TSource]: """ return TypedArray(self.value[count:]) - def skip_last(self, count: int) -> TypedArray[_TSource]: + def skip_last(self, count: int) -> TypedArray[TSource]: return TypedArray(self.value[:-count] if count != 0 else self.value[:]) - def sort(self: TypedArray[_TSourceSortable], reverse: bool = False) -> TypedArray[_TSourceSortable]: + def sort[TSourceSortable: SupportsLessThan]( + self: TypedArray[TSourceSortable], reverse: bool = False + ) -> TypedArray[TSourceSortable]: """Sort array directly. Returns a new sorted collection. @@ -355,7 +350,7 @@ def sort(self: TypedArray[_TSourceSortable], reverse: bool = False) -> TypedArra """ return TypedArray(builtins.sorted(self.value, reverse=reverse)) - def sort_with(self, func: Callable[[_TSource], Any], reverse: bool = False) -> TypedArray[_TSource]: + def sort_with(self, func: Callable[[TSource], Any], reverse: bool = False) -> TypedArray[TSource]: """Sort array with supplied function. Returns a new sorted collection. @@ -369,21 +364,21 @@ def sort_with(self, func: Callable[[_TSource], Any], reverse: bool = False) -> T """ return TypedArray(builtins.sorted(self.value, key=func, reverse=reverse)) - def sum(self: TypedArray[_TSourceSum]) -> int: + def sum[TSourceSum: SupportsSum](self: TypedArray[TSourceSum]) -> int: return sum(self) - def sum_by(self, projection: Callable[[_TSource], _TSourceSum]) -> int: + def sum_by[TSourceSum: SupportsSum](self, projection: Callable[[TSource], TSourceSum]) -> int: return pipe( self, sum_by(projection), ) - def tail(self) -> TypedArray[_TSource]: + def tail(self) -> TypedArray[TSource]: """Return tail of List.""" _, *tail = self.value return TypedArray(tail) - def take(self, count: int) -> TypedArray[_TSource]: + def take(self, count: int) -> TypedArray[TSource]: """Returns the first N elements of the list. Args: @@ -394,7 +389,7 @@ def take(self, count: int) -> TypedArray[_TSource]: """ return TypedArray(self.value[:count]) - def take_last(self, count: int) -> TypedArray[_TSource]: + def take_last(self, count: int) -> TypedArray[TSource]: """Take last elements. Returns a specified number of contiguous elements from the @@ -408,22 +403,22 @@ def take_last(self, count: int) -> TypedArray[_TSource]: """ return TypedArray(self.value[-count:] if count != 0 else self.value[:0]) - def try_head(self) -> Option[_TSource]: + def try_head(self) -> Option[TSource]: """Try to return first element. Returns the first element of the list, or None if the list is empty. """ if self.value: - value = cast("_TSource", self.value[0]) + value = cast("TSource", self.value[0]) return Some(value) return NOTHING @staticmethod - def unfold( - generator: Callable[[_TState], Option[tuple[_TSource, _TState]]], state: _TState - ) -> TypedArray[_TSource]: + def unfold[TState]( + generator: Callable[[TState], Option[tuple[TSource, TState]]], state: TState + ) -> TypedArray[TSource]: """Unfold array. Returns a list that contains the elements generated by the @@ -453,7 +448,7 @@ def __eq__(self, o: Any) -> bool: def __len__(self) -> int: return len(self.value) - def __iter__(self) -> Iterator[_TSource]: + def __iter__(self) -> Iterator[TSource]: return iter(self.value) def __setitem__(self, key: slice | int, value: Any) -> None: @@ -473,7 +468,7 @@ def __repr__(self) -> str: @curry_flip(1) -def map(source: TypedArray[_TSource], mapper: Callable[[_TSource], _TResult]) -> TypedArray[_TResult]: +def map[TSource, TResult](source: TypedArray[TSource], mapper: Callable[[TSource], TResult]) -> TypedArray[TResult]: """Map array. Builds a new array whose elements are the results of applying @@ -494,7 +489,7 @@ def empty() -> TypedArray[Any]: @curry_flip(1) -def filter(source: TypedArray[_TSource], predicate: Callable[[_TSource], bool]) -> TypedArray[_TSource]: +def filter[TSource](source: TypedArray[TSource], predicate: Callable[[TSource], bool]) -> TypedArray[TSource]: """Filter array. Returns a new array containing only the elements of the @@ -511,11 +506,11 @@ def filter(source: TypedArray[_TSource], predicate: Callable[[_TSource], bool]) @curry_flip(1) -def fold( - source: TypedArray[_TSource], - folder: Callable[[_TState, _TSource], _TState], - state: _TState, -) -> _TState: +def fold[TSource, TState]( + source: TypedArray[TSource], + folder: Callable[[TState, TSource], TState], + state: TState, +) -> TState: """Fold the array. Applies a function to each element of the collection, threading @@ -541,10 +536,10 @@ def fold( @curry_flip(1) -def indexed( - source: TypedArray[_TSource], +def indexed[TSource]( + source: TypedArray[TSource], start: int = 0, -) -> TypedArray[tuple[int, _TSource]]: +) -> TypedArray[tuple[int, TSource]]: return source.indexed() @@ -554,21 +549,21 @@ def is_empty(source: TypedArray[Any]) -> bool: @curry_flip(1) -def item(source: TypedArray[_TSource], index: int) -> _TSource: +def item[TSource](source: TypedArray[TSource], index: int) -> TSource: return source.item(index) -def of(*args: _TSource) -> TypedArray[_TSource]: +def of[TSource](*args: TSource) -> TypedArray[TSource]: """Create list from a number of arguments.""" return TypedArray((*args,)) -def of_seq(xs: Iterable[_TSource]) -> TypedArray[_TSource]: +def of_seq[TSource](xs: Iterable[TSource]) -> TypedArray[TSource]: """Create list from iterable sequence.""" return TypedArray((*xs,)) -def of_option(option: Option[_TSource]) -> TypedArray[_TSource]: +def of_option[TSource](option: Option[TSource]) -> TypedArray[TSource]: match option: case Some(value): return singleton(value) @@ -576,21 +571,23 @@ def of_option(option: Option[_TSource]) -> TypedArray[_TSource]: return empty() -def singleton(value: _TSource) -> TypedArray[_TSource]: +def singleton[TSource](value: TSource) -> TypedArray[TSource]: return TypedArray((value,)) -def sum(source: TypedArray[_TSourceSum]) -> int: +def sum[TSourceSum: SupportsSum](source: TypedArray[TSourceSum]) -> int: return builtins.sum(source.value) @curry_flip(1) -def sum_by(source: TypedArray[_TSource], projection: Callable[[_TSource], _TSourceSum]) -> int: +def sum_by[TSource, TSourceSum: SupportsSum]( + source: TypedArray[TSource], projection: Callable[[TSource], TSourceSum] +) -> int: return builtins.sum(source.map(projection).value) @curry_flip(1) -def take(source: TypedArray[_TSource], count: int) -> TypedArray[_TSource]: +def take[TSource](source: TypedArray[TSource], count: int) -> TypedArray[TSource]: """Return the first N elements of the array. Args: @@ -604,7 +601,7 @@ def take(source: TypedArray[_TSource], count: int) -> TypedArray[_TSource]: @curry_flip(1) -def take_last(source: TypedArray[_TSource], count: int) -> TypedArray[_TSource]: +def take_last[TSource](source: TypedArray[TSource], count: int) -> TypedArray[TSource]: """Take last elements. Returns a specified number of contiguous elements from the end of @@ -620,7 +617,7 @@ def take_last(source: TypedArray[_TSource], count: int) -> TypedArray[_TSource]: return source.take_last(count) -def try_head(source: TypedArray[_TSource]) -> Option[_TSource]: +def try_head[TSource](source: TypedArray[TSource]) -> Option[TSource]: """Try to get the first element from the list. Returns the first element of the list, or None if the list is empty. @@ -635,7 +632,9 @@ def try_head(source: TypedArray[_TSource]) -> Option[_TSource]: @curry_flip(1) -def unfold(state: _TState, generator: Callable[[_TState], Option[tuple[_TSource, _TState]]]) -> TypedArray[_TSource]: +def unfold[TState, TSource]( + state: TState, generator: Callable[[TState], Option[tuple[TSource, TState]]] +) -> TypedArray[TSource]: """Unfold array. Returns a list that contains the elements generated by the diff --git a/expression/collections/asyncseq.py b/expression/collections/asyncseq.py index 87acb8d8..18de7854 100644 --- a/expression/collections/asyncseq.py +++ b/expression/collections/asyncseq.py @@ -1,24 +1,17 @@ import builtins import itertools from collections.abc import AsyncIterable, AsyncIterator, Callable -from typing import Any, TypeVar, cast, overload +from typing import Any, cast, overload from expression.core import Option, pipe from expression.core.typing import SupportsLessThan, SupportsSum -TSource = TypeVar("TSource") -TResult = TypeVar("TResult") -TState = TypeVar("TState") -TSourceSortable = TypeVar("TSourceSortable", bound=SupportsLessThan) -TSourceSum = TypeVar("TSourceSum", bound=SupportsSum) - - -class AsyncSeq(AsyncIterable[TSource]): +class AsyncSeq[TSource](AsyncIterable[TSource]): def __init__(self, ai: AsyncIterable[TSource]): self._ai = ai - async def map(self, mapper: Callable[[TSource], TResult]) -> "AsyncSeq[TResult]": + async def map[TResult](self, mapper: Callable[[TSource], TResult]) -> "AsyncSeq[TResult]": # Use the module-level `map` function defined later to transform the # underlying async iterable and wrap the result back into an AsyncSeq. return AsyncSeq(pipe(self._ai, map(mapper))) # type: ignore[arg-type] @@ -46,7 +39,7 @@ def range(cls, *args: int, **kw: int) -> "AsyncSeq[int]": def __aiter__(self) -> AsyncIterator[TSource]: return self._ai.__aiter__() - async def choose(self, chooser: Callable[[TSource], Option[TResult]]) -> AsyncIterable[TResult]: + async def choose[TResult](self, chooser: Callable[[TSource], Option[TResult]]) -> AsyncIterable[TResult]: """Choose items from the sequence. Applies the given function to each element of the list. Returns @@ -69,7 +62,7 @@ async def _choose(source: AsyncIterable[TSource]) -> AsyncIterable[TResult]: return pipe(self, _choose) - async def collect(self, mapping: Callable[[TSource], AsyncIterable[TResult]]) -> AsyncIterable[TResult]: + async def collect[TResult](self, mapping: Callable[[TSource], AsyncIterable[TResult]]) -> AsyncIterable[TResult]: """Collect items from the sequence. Applies the given function to each element of the list and @@ -125,7 +118,7 @@ async def _filter(source: AsyncIterable[TSource]) -> AsyncIterable[TSource]: return pipe(self, _filter) - async def fold(self, folder: Callable[[TState, TSource], TState], state: TState) -> TState: + async def fold[TState](self, folder: Callable[[TState, TSource], TState], state: TState) -> TState: """Fold elements in sequence. Applies a function to each element of the collection, @@ -136,7 +129,7 @@ async def fold(self, folder: Callable[[TState, TSource], TState], state: TState) result = folder(result, value) return result - async def fold_back(self, folder: Callable[[TSource, TState], TState], state: TState) -> TState: + async def fold_back[TState](self, folder: Callable[[TSource, TState], TState], state: TState) -> TState: """Fold elements in sequence backwards. Applies the function to each element of the collection, @@ -151,7 +144,7 @@ async def fold_back(self, folder: Callable[[TSource, TState], TState], state: TS result = folder(value, result) return result - async def scan(self, scanner: Callable[[TState, TSource], TState], state: TState) -> AsyncIterable[TState]: + async def scan[TState](self, scanner: Callable[[TState, TSource], TState], state: TState) -> AsyncIterable[TState]: """Scan elements in sequence. Like fold, but yields intermediate results. @@ -216,14 +209,14 @@ async def length(self) -> int: count += 1 return count - async def sum(self: "AsyncSeq[TSourceSum]") -> TSourceSum: + async def sum[TSourceSum: SupportsSum](self: "AsyncSeq[TSourceSum]") -> TSourceSum: """Returns the sum of the elements in the sequence.""" result = cast(TSourceSum, 0) async for value in self: result = cast(TSourceSum, result + value) return result - async def max(self: "AsyncSeq[TSourceSortable]") -> TSourceSortable: + async def max[TSourceSortable: SupportsLessThan](self: "AsyncSeq[TSourceSortable]") -> TSourceSortable: """Return maximum of all elements.""" items: list[TSourceSortable] = [] async for value in self: @@ -232,7 +225,7 @@ async def max(self: "AsyncSeq[TSourceSortable]") -> TSourceSortable: raise ValueError("Sequence contains no elements") return builtins.max(items) - async def min(self: "AsyncSeq[TSourceSortable]") -> TSourceSortable: + async def min[TSourceSortable: SupportsLessThan](self: "AsyncSeq[TSourceSortable]") -> TSourceSortable: """Return minimum of all elements.""" items: list[TSourceSortable] = [] async for value in self: @@ -242,7 +235,7 @@ async def min(self: "AsyncSeq[TSourceSortable]") -> TSourceSortable: return builtins.min(items) -def append( +def append[TSource]( other: AsyncIterable[TSource], ) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TSource]]: async def _append(source: AsyncIterable[TSource]) -> AsyncIterable[TSource]: @@ -259,7 +252,7 @@ async def empty() -> AsyncIterable[Any]: yield -async def repeat(value: TSource, times: int | None = None) -> AsyncIterable[TSource]: +async def repeat[TSource](value: TSource, times: int | None = None) -> AsyncIterable[TSource]: for v in itertools.repeat(value, times or 0): yield v @@ -277,7 +270,7 @@ async def range(*args: int, **kw: int) -> AsyncIterable[int]: yield value -def filter(predicate: Callable[[TSource], bool]) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TSource]]: +def filter[TSource](predicate: Callable[[TSource], bool]) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TSource]]: async def _filter(source: AsyncIterable[TSource]) -> AsyncIterable[TSource]: async for value in source: if predicate(value): @@ -286,7 +279,9 @@ async def _filter(source: AsyncIterable[TSource]) -> AsyncIterable[TSource]: return _filter -def map(mapper: Callable[[TSource], TResult]) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TResult]]: +def map[TResult, TSource]( + mapper: Callable[[TSource], TResult], +) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TResult]]: async def _map(source: AsyncIterable[TSource]) -> AsyncIterable[TResult]: async for value in source: yield mapper(value) @@ -294,7 +289,9 @@ async def _map(source: AsyncIterable[TSource]) -> AsyncIterable[TResult]: return _map -def choose(chooser: Callable[[TSource], Option[TResult]]) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TResult]]: +def choose[TSource, TResult]( + chooser: Callable[[TSource], Option[TResult]], +) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TResult]]: """Choose items from the sequence.""" async def _choose(source: AsyncIterable[TSource]) -> AsyncIterable[TResult]: @@ -306,7 +303,7 @@ async def _choose(source: AsyncIterable[TSource]) -> AsyncIterable[TResult]: return _choose -def collect( +def collect[TSource, TResult]( mapping: Callable[[TSource], AsyncIterable[TResult]], ) -> Callable[[AsyncIterable[TSource]], AsyncIterable[TResult]]: """Collect items from the sequence.""" diff --git a/expression/collections/block.py b/expression/collections/block.py index bfb2fbc8..8d1b358d 100644 --- a/expression/collections/block.py +++ b/expression/collections/block.py @@ -25,9 +25,7 @@ import itertools from collections.abc import Callable, Collection, Iterable, Iterator, Sequence from dataclasses import dataclass -from typing import TYPE_CHECKING, Any, Literal, TypeVar, get_args, overload - -from typing_extensions import TypeVarTuple, Unpack +from typing import TYPE_CHECKING, Any, Literal, TypeVar, Unpack, get_args, overload if TYPE_CHECKING: @@ -49,23 +47,12 @@ _TSource = TypeVar("_TSource") -_TSourceSortable = TypeVar("_TSourceSortable", bound=SupportsLessThan) -_TSourceSum = TypeVar("_TSourceSum", bound=SupportsSum) -_TResult = TypeVar("_TResult") -_TState = TypeVar("_TState") - -_T1 = TypeVar("_T1") -_T2 = TypeVar("_T2") -_T3 = TypeVar("_T3") -_T4 = TypeVar("_T4") -_P = TypeVarTuple("_P") +# Keep implicit generics here: early Python 3.12 dataclasses lose the weakref +# slot when PEP 695 adds typing.Generic as a direct base. @dataclass(frozen=True, slots=True, weakref_slot=True, init=False, eq=False, repr=False) -class Block( - Collection[_TSource], # Sequence breaks pydantic - PipeMixin, -): +class Block(Collection[_TSource], PipeMixin): """Immutable list type. Is faster than `List` for prepending, but slower for @@ -96,7 +83,7 @@ def append(self, other: Block[_TSource]) -> Block[_TSource]: """Append other block to end of the block.""" return Block(self._value + other._value) - def choose(self, chooser: Callable[[_TSource], Option[_TResult]]) -> Block[_TResult]: + def choose[TResult](self, chooser: Callable[[_TSource], Option[TResult]]) -> Block[TResult]: """Choose items from the list. Applies the given function to each element of the list. Returns @@ -111,12 +98,12 @@ def choose(self, chooser: Callable[[_TSource], Option[_TResult]]) -> Block[_TRes function. """ - def mapper(x: _TSource) -> Block[_TResult]: + def mapper(x: _TSource) -> Block[TResult]: return Block(chooser(x).to_seq()) return self.collect(mapper) - def collect(self, mapping: Callable[[_TSource], Block[_TResult]]) -> Block[_TResult]: + def collect[TResult](self, mapping: Callable[[_TSource], Block[TResult]]) -> Block[TResult]: """Collect items from the list. Applies the given function to each element of the list and concatenates all the @@ -158,7 +145,7 @@ def filter(self, predicate: Callable[[_TSource], bool]) -> Block[_TSource]: """ return Block(builtins.filter(predicate, self._value)) - def fold(self, folder: Callable[[_TState, _TSource], _TState], state: _TState) -> _TState: + def fold[TState](self, folder: Callable[[TState, _TSource], TState], state: TState) -> TState: """Fold block. Applies a function to each element of the collection, @@ -240,7 +227,7 @@ def is_empty(self) -> bool: """Return `True` if list is empty.""" return not bool(self) - def map(self, mapping: Callable[[_TSource], _TResult]) -> Block[_TResult]: + def map[TResult](self, mapping: Callable[[_TSource], TResult]) -> Block[TResult]: """Map list. Builds a new collection whose elements are the results of @@ -256,7 +243,7 @@ def map(self, mapping: Callable[[_TSource], _TResult]) -> Block[_TResult]: """ return Block((*builtins.map(mapping, self),)) - def starmap(self: Block[tuple[*_P]], mapping: Callable[[Unpack[_P]], _TResult]) -> Block[_TResult]: + def starmap[*P, TResult](self: Block[tuple[*P]], mapping: Callable[[Unpack[P]], TResult]) -> Block[TResult]: """Starmap source sequence. Unpack arguments grouped as tuple elements. Builds a new collection @@ -271,13 +258,15 @@ def starmap(self: Block[tuple[*_P]], mapping: Callable[[Unpack[_P]], _TResult]) """ return Block(starmap(mapping)(self)) - def sum(self: Block[_TSourceSum | Literal[0]]) -> _TSourceSum | Literal[0]: + def sum[TSourceSum: SupportsSum](self: Block[TSourceSum | Literal[0]]) -> TSourceSum | Literal[0]: return builtins.sum(self._value) - def sum_by(self: Block[_TSourceSum], projection: Callable[[_TSourceSum], _TResult]) -> _TResult: + def sum_by[TSourceSum: SupportsSum, TResult]( + self: Block[TSourceSum], projection: Callable[[TSourceSum], TResult] + ) -> TResult: return pipe(self, sum_by(projection)) - def mapi(self, mapping: Callable[[int, _TSource], _TResult]) -> Block[_TResult]: + def mapi[TResult](self, mapping: Callable[[int, _TSource], TResult]) -> Block[TResult]: """Map list with index. Builds a new collection whose elements are the results of @@ -300,7 +289,7 @@ def of(*args: _TSource) -> Block[_TSource]: return Block((*args,)) @staticmethod - def of_seq(xs: Iterable[_TResult]) -> Block[_TResult]: + def of_seq[TResult](xs: Iterable[TResult]) -> Block[TResult]: """Create list from iterable sequence.""" return Block((*xs,)) @@ -395,7 +384,9 @@ def tail(self) -> Block[_TSource]: _, *tail = self._value return Block(tail) - def sort(self: Block[_TSourceSortable], reverse: bool = False) -> Block[_TSourceSortable]: + def sort[TSourceSortable: SupportsLessThan]( + self: Block[TSourceSortable], reverse: bool = False + ) -> Block[TSourceSortable]: """Sort list directly. Returns a new sorted collection. @@ -471,7 +462,9 @@ def try_head(self) -> Option[_TSource]: return NOTHING @staticmethod - def unfold(generator: Callable[[_TState], Option[tuple[_TSource, _TState]]], state: _TState) -> Block[_TSource]: + def unfold[TState]( + generator: Callable[[TState], Option[tuple[_TSource, TState]]], state: TState + ) -> Block[_TSource]: """Unfold block. Returns a list that contains the elements generated by the @@ -489,7 +482,7 @@ def unfold(generator: Callable[[_TState], Option[tuple[_TSource, _TState]]], sta """ return pipe(state, unfold(generator)) - def zip(self, other: Block[_TResult]) -> Block[tuple[_TSource, _TResult]]: + def zip[TResult](self, other: Block[TResult]) -> Block[tuple[_TSource, TResult]]: """Zip block. Combines the two lists into a list of pairs. The two lists @@ -563,17 +556,17 @@ def __get_pydantic_core_schema__(cls, source: Any, handler: GetCoreSchemaHandler @curry_flip(1) -def append(source: Block[_TSource], other: Block[_TSource]) -> Block[_TSource]: +def append[TSource](source: Block[TSource], other: Block[TSource]) -> Block[TSource]: return source.append(other) @curry_flip(1) -def choose(source: Block[_TSource], chooser: Callable[[_TSource], Option[_TResult]]) -> Block[_TResult]: +def choose[TSource, TResult](source: Block[TSource], chooser: Callable[[TSource], Option[TResult]]) -> Block[TResult]: return source.choose(chooser) @curry_flip(1) -def collect(source: Block[_TSource], mapping: Callable[[_TSource], Block[_TResult]]) -> Block[_TResult]: +def collect[TSource, TResult](source: Block[TSource], mapping: Callable[[TSource], Block[TResult]]) -> Block[TResult]: """Collect items from the list. Applies the given function to each element of the list and @@ -591,16 +584,16 @@ def collect(source: Block[_TSource], mapping: Callable[[_TSource], Block[_TResul return source.collect(mapping) -def concat(sources: Iterable[Block[_TSource]]) -> Block[_TSource]: +def concat[TSource](sources: Iterable[Block[TSource]]) -> Block[TSource]: """Concatenate sequence of Block's.""" - def reducer(t: Block[_TSource], s: Block[_TSource]) -> Block[_TSource]: + def reducer(t: Block[TSource], s: Block[TSource]) -> Block[TSource]: return t.append(s) return pipe(sources, seq.fold(reducer, empty)) -def cons(head: _TSource, tail: Block[_TSource]) -> Block[_TSource]: +def cons[TSource](head: TSource, tail: Block[TSource]) -> Block[TSource]: return Block((head, *tail)) @@ -610,7 +603,7 @@ def cons(head: _TSource, tail: Block[_TSource]) -> Block[_TSource]: @curry_flip(1) -def filter(source: Block[_TSource], predicate: Callable[[_TSource], bool]) -> Block[_TSource]: +def filter[TSource](source: Block[TSource], predicate: Callable[[TSource], bool]) -> Block[TSource]: """Filter elements in block. Returns a new collection containing only the elements of the @@ -627,11 +620,11 @@ def filter(source: Block[_TSource], predicate: Callable[[_TSource], bool]) -> Bl @curry_flip(1) -def fold( - source: Block[_TSource], - folder: Callable[[_TState, _TSource], _TState], - state: _TState, -) -> _TState: +def fold[TSource, TState]( + source: Block[TSource], + folder: Callable[[TState, TSource], TState], + state: TState, +) -> TState: """Fold elements in block. Applies a function to each element of the collection, threading @@ -657,7 +650,7 @@ def fold( @curry_flip(1) -def forall(source: Block[_TSource], predicate: Callable[[_TSource], bool]) -> bool: +def forall[TSource](source: Block[TSource], predicate: Callable[[TSource], bool]) -> bool: """For all elements in block. Tests if all elements of the collection satisfy the given @@ -673,7 +666,7 @@ def forall(source: Block[_TSource], predicate: Callable[[_TSource], bool]) -> bo return source.forall(predicate) -def head(source: Block[_TSource]) -> _TSource: +def head[TSource](source: Block[TSource]) -> TSource: """Returns the first element of the list. Args: @@ -688,7 +681,7 @@ def head(source: Block[_TSource]) -> _TSource: return source.head() -def indexed(source: Block[_TSource]) -> Block[tuple[int, _TSource]]: +def indexed[TSource](source: Block[TSource]) -> Block[tuple[int, TSource]]: """Index elements in block. Returns a new list whose elements are the corresponding @@ -702,7 +695,7 @@ def indexed(source: Block[_TSource]) -> Block[tuple[int, _TSource]]: @curry_flip(1) -def item(source: Block[_TSource], index: int) -> _TSource: +def item[TSource](source: Block[TSource], index: int) -> TSource: """Indexes into the list. The first element has index 0. Args: @@ -721,7 +714,7 @@ def is_empty(source: Block[Any]) -> bool: @curry_flip(1) -def map(source: Block[_TSource], mapper: Callable[[_TSource], _TResult]) -> Block[_TResult]: +def map[TSource, TResult](source: Block[TSource], mapper: Callable[[TSource], TResult]) -> Block[TResult]: """Map list. Builds a new collection whose elements are the results of applying @@ -738,10 +731,10 @@ def map(source: Block[_TSource], mapper: Callable[[_TSource], _TResult]) -> Bloc @curry_flip(1) -def reduce( - source: Block[_TSource], - reduction: Callable[[_TSource, _TSource], _TSource], -) -> _TSource: +def reduce[TSource]( + source: Block[TSource], + reduction: Callable[[TSource, TSource], TSource], +) -> TSource: """Reduce elements in block. Apply a function to each element of the collection, threading an @@ -766,7 +759,7 @@ def reduce( return source.tail().fold(reduction, source.head()) -def starmap(mapper: Callable[[Unpack[_P]], _TResult]) -> Callable[[Block[tuple[*_P]]], Block[_TResult]]: +def starmap[TResult, *P](mapper: Callable[[Unpack[P]], TResult]) -> Callable[[Block[tuple[*P]]], Block[TResult]]: """Starmap source sequence. Unpack arguments grouped as tuple elements. Builds a new collection @@ -780,22 +773,26 @@ def starmap(mapper: Callable[[Unpack[_P]], _TResult]) -> Callable[[Block[tuple[* Partially applied map function. """ - def mapper_(args: tuple[*_P]) -> _TResult: + def mapper_(args: tuple[*P]) -> TResult: return mapper(*args) return map(mapper_) -def map2(mapper: Callable[[_T1, _T2], _TResult]) -> Callable[[Block[tuple[_T1, _T2]]], Block[_TResult]]: +def map2[TResult, T1, T2]( + mapper: Callable[[T1, T2], TResult], +) -> Callable[[Block[tuple[T1, T2]]], Block[TResult]]: return starmap(mapper) -def map3(mapper: Callable[[_T1, _T2, _T3], _TResult]) -> Callable[[Block[tuple[_T1, _T2, _T3]]], Block[_TResult]]: +def map3[TResult, T1, T2, T3]( + mapper: Callable[[T1, T2, T3], TResult], +) -> Callable[[Block[tuple[T1, T2, T3]]], Block[TResult]]: return starmap(mapper) @curry_flip(1) -def mapi(source: Block[_TSource], mapper: Callable[[int, _TSource], _TResult]) -> Block[_TResult]: +def mapi[TSource, TResult](source: Block[TSource], mapper: Callable[[int, TSource], TResult]) -> Block[TResult]: """Map list with index. Builds a new collection whose elements are the results of @@ -814,17 +811,17 @@ def mapi(source: Block[_TSource], mapper: Callable[[int, _TSource], _TResult]) - return source.mapi(mapper) -def of(*args: _TSource) -> Block[_TSource]: +def of[TSource](*args: TSource) -> Block[TSource]: """Create list from a number of arguments.""" return Block((*args,)) -def of_seq(xs: Iterable[_TSource]) -> Block[_TSource]: +def of_seq[TSource](xs: Iterable[TSource]) -> Block[TSource]: """Create list from iterable sequence.""" return Block((*xs,)) -def of_option(option: Option[_TSource]) -> Block[_TSource]: +def of_option[TSource](option: Option[TSource]) -> Block[TSource]: match option: case Some(value): return singleton(value) @@ -833,9 +830,9 @@ def of_option(option: Option[_TSource]) -> Block[_TSource]: @curry_flip(1) -def partition( - source: Block[_TSource], predicate: Callable[[_TSource], bool] -) -> tuple[Block[_TSource], Block[_TSource]]: +def partition[TSource]( + source: Block[TSource], predicate: Callable[[TSource], bool] +) -> tuple[Block[TSource], Block[TSource]]: """Partition block. Splits the collection into two collections, containing the @@ -871,12 +868,12 @@ def range(*args: int, **kw: int) -> Block[int]: return Block((*builtins.range(*args, **kw),)) -def singleton(value: _TSource) -> Block[_TSource]: +def singleton[TSource](value: TSource) -> Block[TSource]: return Block((value,)) @curry_flip(1) -def skip(source: Block[_TSource], count: int) -> Block[_TSource]: +def skip[TSource](source: Block[TSource], count: int) -> Block[TSource]: """Returns the list after removing the first N elements. Args: @@ -890,7 +887,7 @@ def skip(source: Block[_TSource], count: int) -> Block[_TSource]: @curry_flip(1) -def skip_last(source: Block[_TSource], count: int) -> Block[_TSource]: +def skip_last[TSource](source: Block[TSource], count: int) -> Block[TSource]: """Returns the list after removing the last N elements. Args: @@ -904,10 +901,10 @@ def skip_last(source: Block[_TSource], count: int) -> Block[_TSource]: @curry_flip(1) -def sort( - source: Block[_TSourceSortable], +def sort[TSourceSortable: SupportsLessThan]( + source: Block[TSourceSortable], reverse: bool = False, -) -> Block[_TSourceSortable]: +) -> Block[TSourceSortable]: """Returns a new sorted collection. Args: @@ -921,7 +918,7 @@ def sort( @curry_flip(1) -def sort_with(source: Block[_TSource], func: Callable[[_TSource], Any], reverse: bool = False) -> Block[_TSource]: +def sort_with[TSource](source: Block[TSource], func: Callable[[TSource], Any], reverse: bool = False) -> Block[TSource]: """Returns a new collection sorted using "func" key function. Args: @@ -935,22 +932,24 @@ def sort_with(source: Block[_TSource], func: Callable[[_TSource], Any], reverse: return source.sort_with(func, reverse) -def sum(source: Block[_TSourceSum | Literal[0]]) -> _TSourceSum | Literal[0]: +def sum[TSourceSum: SupportsSum](source: Block[TSourceSum | Literal[0]]) -> TSourceSum | Literal[0]: return builtins.sum(source) @curry_flip(1) -def sum_by(source: Block[_TSourceSum], projection: Callable[[_TSourceSum], _TResult]) -> _TResult: +def sum_by[TSourceSum: SupportsSum, TResult]( + source: Block[TSourceSum], projection: Callable[[TSourceSum], TResult] +) -> TResult: xs = source.map(projection) return builtins.sum(xs) # type: ignore -def tail(source: Block[_TSource]) -> Block[_TSource]: +def tail[TSource](source: Block[TSource]) -> Block[TSource]: return source.tail() @curry_flip(1) -def take(source: Block[_TSource], count: int) -> Block[_TSource]: +def take[TSource](source: Block[TSource], count: int) -> Block[TSource]: """Returns the first N elements of the list. Args: @@ -964,7 +963,7 @@ def take(source: Block[_TSource], count: int) -> Block[_TSource]: @curry_flip(1) -def take_last(source: Block[_TSource], count: int) -> Block[_TSource]: +def take_last[TSource](source: Block[TSource], count: int) -> Block[TSource]: """Take last elements from block. Returns a specified number of contiguous elements from the end of @@ -980,11 +979,11 @@ def take_last(source: Block[_TSource], count: int) -> Block[_TSource]: return source.take_last(count) -def dict(source: Block[_TSource]) -> list[_TSource]: +def dict[TSource](source: Block[TSource]) -> list[TSource]: return source.dict() -def try_head(source: Block[_TSource]) -> Option[_TSource]: +def try_head[TSource](source: Block[TSource]) -> Option[TSource]: """Try to get the first element from the list. Returns the first element of the list, or None if the list is empty. @@ -999,7 +998,9 @@ def try_head(source: Block[_TSource]) -> Option[_TSource]: @curry_flip(1) -def unfold(state: _TState, generator: Callable[[_TState], Option[tuple[_TSource, _TState]]]) -> Block[_TSource]: +def unfold[TState, TSource]( + state: TState, generator: Callable[[TState], Option[tuple[TSource, TState]]] +) -> Block[TSource]: """Unfold block. Returns a list that contains the elements generated by the @@ -1020,10 +1021,10 @@ def unfold(state: _TState, generator: Callable[[_TState], Option[tuple[_TSource, @curry_flip(1) -def zip( - source: Block[_TSource], - other: Block[_TResult], -) -> Block[tuple[_TSource, _TResult]]: +def zip[TSource, TResult]( + source: Block[TSource], + other: Block[TResult], +) -> Block[tuple[TSource, TResult]]: """Zip block with other. Combines the two lists into a list of pairs. The two lists diff --git a/expression/collections/map.py b/expression/collections/map.py index 9803ef8b..93464ff2 100644 --- a/expression/collections/map.py +++ b/expression/collections/map.py @@ -29,18 +29,11 @@ _Key = TypeVar("_Key", bound=SupportsLessThanAndHash) -_Key_ = TypeVar("_Key_", bound=SupportsLessThanAndHash) _Value = TypeVar("_Value") -_Result = TypeVar("_Result") - -_T1 = TypeVar("_T1") -_T2 = TypeVar("_T2") -_T3 = TypeVar("_T3") -_T4 = TypeVar("_T4") -_T5 = TypeVar("_T5") -_T6 = TypeVar("_T6") +# Keep implicit generics here: early Python 3.12 dataclasses lose the weakref +# slot when PEP 695 adds typing.Generic as a direct base. @dataclass(frozen=True, slots=True, weakref_slot=True, init=False, eq=False, repr=False, match_args=False) class Map(Mapping[_Key, _Value], PipeMixin): """The immutable map class.""" @@ -97,13 +90,13 @@ def iterate(self, f: Callable[[_Key, _Value], None]) -> None: # def MapRange (f:'Value->'Result) = # return Map<'Key, 'Result>(comparer, maptree.map f tree) - def fold(self, folder: Callable[[_Result, tuple[_Key, _Value]], _Result], state: _Result) -> _Result: + def fold[Result](self, folder: Callable[[Result, tuple[_Key, _Value]], Result], state: Result) -> Result: return maptree.fold(folder, state, self._tree) - def fold_back(self, folder: Callable[[tuple[_Key, _Value], _Result], _Result], state: _Result) -> _Result: + def fold_back[Result](self, folder: Callable[[tuple[_Key, _Value], Result], Result], state: Result) -> Result: return maptree.fold_back(folder, self._tree, state) - def map(self, mapping: Callable[[_Key, _Value], _Result]) -> Map[_Key, _Result]: + def map[Result](self, mapping: Callable[[_Key, _Value], Result]) -> Map[_Key, Result]: """Map the mapping. Builds a new collection whose elements are the results of @@ -165,11 +158,11 @@ def try_get_value(self, key: _Key, value: list[_Value]): def try_find(self, key: _Key) -> Option[_Value]: return maptree.try_find(key, self._tree) - def try_pick(self, chooser: Callable[[_Key, _Value], Option[_Result]]) -> Option[_Result]: + def try_pick[Result](self, chooser: Callable[[_Key, _Value], Option[Result]]) -> Option[Result]: return maptree.try_pick(chooser, self._tree) @staticmethod - def of(**args: _Result) -> Map[str, _Result]: + def of[Result](**args: Result) -> Map[str, Result]: return Map(maptree.of_seq(args.items())) @staticmethod @@ -182,7 +175,7 @@ def of_block(lst: Block[tuple[_Key, _Value]]) -> Map[_Key, _Value]: return of_block(lst) @staticmethod - def of_list(lst: list[tuple[_Key_, _Result]]) -> Map[_Key_, _Result]: + def of_list[Key_: SupportsLessThanAndHash, Result](lst: list[tuple[Key_, Result]]) -> Map[Key_, Result]: """Generate map from list. Returns: @@ -191,7 +184,9 @@ def of_list(lst: list[tuple[_Key_, _Result]]) -> Map[_Key_, _Result]: return of_list(lst) @staticmethod - def of_seq(sequence: Iterable[tuple[_Key_, _Result]]) -> Map[_Key_, _Result]: + def of_seq[Key_: SupportsLessThanAndHash, Result]( + sequence: Iterable[tuple[Key_, Result]], + ) -> Map[Key_, Result]: """Generate map from sequence. Generates a new map from an iterable of key/value tuples. This @@ -261,7 +256,7 @@ def __repr__(self) -> str: @curry_flip(1) -def add(table: Map[_Key, _Value], key: _Key, value: _Value) -> Map[_Key, _Value]: +def add[Key: SupportsLessThanAndHash, Value](table: Map[Key, Value], key: Key, value: Value) -> Map[Key, Value]: """Add key with value to map. Returns a new map with the binding added to the given map. If a @@ -282,7 +277,9 @@ def add(table: Map[_Key, _Value], key: _Key, value: _Value) -> Map[_Key, _Value] @curry_flip(1) -def change(table: Map[_Key, _Value], key: _Key, fn: Callable[[Option[_Value]], Option[_Value]]) -> Map[_Key, _Value]: +def change[Key: SupportsLessThanAndHash, Value]( + table: Map[Key, Value], key: Key, fn: Callable[[Option[Value]], Option[Value]] +) -> Map[Key, Value]: """Change element in map. Returns a new map with the value stored under key changed @@ -300,7 +297,7 @@ def change(table: Map[_Key, _Value], key: _Key, fn: Callable[[Option[_Value]], O @curry_flip(1) -def contains_key(table: Map[_Key, Any], key: _Key) -> bool: +def contains_key[Key: SupportsLessThanAndHash](table: Map[Key, Any], key: Key) -> bool: return table.contains_key(key) @@ -309,12 +306,12 @@ def count(table: Map[Any, Any]) -> int: return len(table) -def create(ie: Iterable[tuple[_Key, _Value]]) -> Map[_Key, _Value]: +def create[Key: SupportsLessThanAndHash, Value](ie: Iterable[tuple[Key, Value]]) -> Map[Key, Value]: return Map(maptree.of_seq(ie)) @curry_flip(1) -def find(table: Map[_Key, _Value], key: _Key) -> _Value: +def find[Key: SupportsLessThanAndHash, Value](table: Map[Key, Value], key: Key) -> Value: """Find element with key in map. Lookup an element in the map, raising KeyNotFoundException if no @@ -340,15 +337,19 @@ def is_empty(table: Map[Any, Any]) -> bool: return table.is_empty() -def iterate(action: Callable[[_Key, _Value], None]) -> Callable[[Map[_Key, _Value]], None]: - def _iterate(table: Map[_Key, _Value]) -> None: +def iterate[Key: SupportsLessThanAndHash, Value]( + action: Callable[[Key, Value], None], +) -> Callable[[Map[Key, Value]], None]: + def _iterate(table: Map[Key, Value]) -> None: return table.iterate(action) return _iterate @curry_flip(1) -def try_pick(table: Map[_Key, _Value], chooser: Callable[[_Key, _Value], Option[_Result]]) -> Option[_Result]: +def try_pick[Key: SupportsLessThanAndHash, Value, Result]( + table: Map[Key, Value], chooser: Callable[[Key, Value], Option[Result]] +) -> Option[Result]: """Pick element in map. Searches the map looking for the first element where the given @@ -367,7 +368,9 @@ def try_pick(table: Map[_Key, _Value], chooser: Callable[[_Key, _Value], Option[ @curry_flip(1) -def pick(table: Map[_Key, _Value], chooser: Callable[[_Key, _Value], Option[_Result]]) -> _Result: +def pick[Key: SupportsLessThanAndHash, Value, Result]( + table: Map[Key, Value], chooser: Callable[[Key, Value], Option[Result]] +) -> Result: for res in table.try_pick(chooser): return res else: @@ -375,7 +378,9 @@ def pick(table: Map[_Key, _Value], chooser: Callable[[_Key, _Value], Option[_Res @curry_flip(1) -def exists(table: Map[_Key, _Value], predicate: Callable[[_Key, _Value], bool]) -> bool: +def exists[Key: SupportsLessThanAndHash, Value]( + table: Map[Key, Value], predicate: Callable[[Key, Value], bool] +) -> bool: """Test if element exists in map. Returns true if the given predicate returns true for one of the @@ -394,47 +399,53 @@ def exists(table: Map[_Key, _Value], predicate: Callable[[_Key, _Value], bool]) @curry_flip(1) -def filter(table: Map[_Key, _Value], predicate: Callable[[_Key, _Value], bool]) -> Map[_Key, _Value]: +def filter[Key: SupportsLessThanAndHash, Value]( + table: Map[Key, Value], predicate: Callable[[Key, Value], bool] +) -> Map[Key, Value]: return table.filter(predicate) @curry_flip(1) -def for_all(table: Map[_Key, _Value], predicate: Callable[[_Key, _Value], bool]) -> bool: +def for_all[Key: SupportsLessThanAndHash, Value]( + table: Map[Key, Value], predicate: Callable[[Key, Value], bool] +) -> bool: return table.for_all(predicate) @curry_flip(1) -def map(table: Map[_Key, _Value], mapping: Callable[[_Key, _Value], _Result]) -> Map[_Key, _Result]: +def map[Key: SupportsLessThanAndHash, Value, Result]( + table: Map[Key, Value], mapping: Callable[[Key, Value], Result] +) -> Map[Key, Result]: return table.map(mapping) @curry_flip(1) -def fold( - table: Map[_Key, _Value], - folder: Callable[[_Result, tuple[_Key, _Value]], _Result], - state: _Result, -) -> _Result: +def fold[Key: SupportsLessThanAndHash, Value, Result]( + table: Map[Key, Value], + folder: Callable[[Result, tuple[Key, Value]], Result], + state: Result, +) -> Result: return table.fold(folder, state) @curry_flip(1) -def fold_back( - state: _Result, - folder: Callable[[tuple[_Key, _Value], _Result], _Result], - table: Map[_Key, _Value], -) -> _Result: +def fold_back[Result, Key: SupportsLessThanAndHash, Value]( + state: Result, + folder: Callable[[tuple[Key, Value], Result], Result], + table: Map[Key, Value], +) -> Result: return table.fold_back(folder, state) @curry_flip(1) -def partition( - table: Map[_Key, _Value], predicate: Callable[[_Key, _Value], bool] -) -> tuple[Map[_Key, _Value], Map[_Key, _Value]]: +def partition[Key: SupportsLessThanAndHash, Value]( + table: Map[Key, Value], predicate: Callable[[Key, Value], bool] +) -> tuple[Map[Key, Value], Map[Key, Value]]: return table.partition(predicate) @curry_flip(1) -def remove(table: Map[_Key, _Value], key: _Key) -> Map[_Key, _Value]: +def remove[Key: SupportsLessThanAndHash, Value](table: Map[Key, Value], key: Key) -> Map[Key, Value]: """Remove element from map. Removes an element from the domain of the map. No exception is @@ -450,33 +461,33 @@ def remove(table: Map[_Key, _Value], key: _Key) -> Map[_Key, _Value]: return table.remove(key) -def of(**args: _Value) -> Map[str, _Value]: +def of[Value](**args: Value) -> Map[str, Value]: """Create map from arguments.""" return Map(maptree.of_seq(args.items())) -def of_block(elements: Block[tuple[_Key, _Value]]) -> Map[_Key, _Value]: +def of_block[Key: SupportsLessThanAndHash, Value](elements: Block[tuple[Key, Value]]) -> Map[Key, Value]: return Map(maptree.of_list(elements)) -def of_list(elements: list[tuple[_Key, _Value]]) -> Map[_Key, _Value]: +def of_list[Key: SupportsLessThanAndHash, Value](elements: list[tuple[Key, Value]]) -> Map[Key, Value]: return Map(maptree.of_list(Block(elements))) -def of_seq(elements: Iterable[tuple[_Key, _Value]]) -> Map[_Key, _Value]: +def of_seq[Key: SupportsLessThanAndHash, Value](elements: Iterable[tuple[Key, Value]]) -> Map[Key, Value]: return Map(maptree.of_seq(elements)) -def to_list(table: Map[_Key, _Value]) -> Block[tuple[_Key, _Value]]: +def to_list[Key: SupportsLessThanAndHash, Value](table: Map[Key, Value]) -> Block[tuple[Key, Value]]: return table.to_list() -def to_seq(table: Map[_Key, _Value]) -> Iterable[tuple[_Key, _Value]]: +def to_seq[Key: SupportsLessThanAndHash, Value](table: Map[Key, Value]) -> Iterable[tuple[Key, Value]]: return table.to_seq() @curry_flip(1) -def try_find(table: Map[_Key, _Value], key: _Key) -> Option[_Value]: +def try_find[Key: SupportsLessThanAndHash, Value](table: Map[Key, Value], key: Key) -> Option[Value]: """Try to find element with key in map. Lookup an element in the map, returning a `Some` value if the diff --git a/expression/collections/maptree.py b/expression/collections/maptree.py index eadfa2fe..4dbcf7ae 100644 --- a/expression/collections/maptree.py +++ b/expression/collections/maptree.py @@ -25,7 +25,7 @@ import builtins from collections.abc import Callable, Iterable, Iterator from dataclasses import dataclass -from typing import Any, Generic, TypeVar +from typing import Any from expression.core import NOTHING, Option, Some, failwith, pipe from expression.core.typing import SupportsLessThanAndHash @@ -34,22 +34,17 @@ from .block import Block -Key = TypeVar("Key", bound=SupportsLessThanAndHash) -Value = TypeVar("Value") -Result = TypeVar("Result") - - @dataclass(frozen=True, slots=True) -class MapTreeLeaf(Generic[Key, Value]): +class MapTreeLeaf[Key: SupportsLessThanAndHash, Value]: key: Key value: Value -MapTree = Option[MapTreeLeaf[Key, Value]] +type MapTree[Key: SupportsLessThanAndHash, Value] = Option[MapTreeLeaf[Key, Value]] @dataclass(frozen=True, slots=True) -class MapTreeNode(MapTreeLeaf[Key, Value]): +class MapTreeNode[Key: SupportsLessThanAndHash, Value](MapTreeLeaf[Key, Value]): left: MapTree[Key, Value] right: MapTree[Key, Value] @@ -63,7 +58,7 @@ def is_empty(m: MapTree[Any, Any]): return m.is_none() -def size_aux(acc: int, m: MapTree[Key, Value]) -> int: +def size_aux[Key: SupportsLessThanAndHash, Value](acc: int, m: MapTree[Key, Value]) -> int: match m: case Some(MapTreeNode(left=left, right=right)): return size_aux(size_aux(acc + 1, left), right) @@ -77,7 +72,7 @@ def size(x: MapTree[Any, Any]): return size_aux(0, x) -def height(m: MapTree[Key, Value]) -> int: +def height[Key: SupportsLessThanAndHash, Value](m: MapTree[Key, Value]) -> int: match m: case Some(MapTreeNode(height=height)): return height @@ -90,7 +85,9 @@ def height(m: MapTree[Key, Value]) -> int: TOLERANCE = 2 -def mk(left: MapTree[Key, Value], key: Key, value: Value, right: MapTree[Key, Value]) -> MapTree[Key, Value]: +def mk[Key: SupportsLessThanAndHash, Value]( + left: MapTree[Key, Value], key: Key, value: Value, right: MapTree[Key, Value] +) -> MapTree[Key, Value]: hl = height(left) hr = height(right) m = hr if hl < hr else hl @@ -100,7 +97,9 @@ def mk(left: MapTree[Key, Value], key: Key, value: Value, right: MapTree[Key, Va return Some(MapTreeNode(key, value, left, right, m + 1)) # new map is higher by 1 than the highest -def rebalance(t1: MapTree[Key, Value], k: Key, v: Value, t2: MapTree[Key, Value]) -> MapTree[Key, Value]: +def rebalance[Key: SupportsLessThanAndHash, Value]( + t1: MapTree[Key, Value], k: Key, v: Value, t2: MapTree[Key, Value] +) -> MapTree[Key, Value]: t1h = height(t1) t2h = height(t2) if t2h > t1h + TOLERANCE: # right is heavier than left @@ -146,7 +145,7 @@ def rebalance(t1: MapTree[Key, Value], k: Key, v: Value, t2: MapTree[Key, Value] return mk(t1, k, v, t2) -def add(k: Key, v: Value, m: MapTree[Key, Value]) -> MapTree[Key, Value]: +def add[Key: SupportsLessThanAndHash, Value](k: Key, v: Value, m: MapTree[Key, Value]) -> MapTree[Key, Value]: match m: case Some(MapTreeNode(key=key, value=value, left=left, right=right, height=height)): if k < key: @@ -167,7 +166,7 @@ def add(k: Key, v: Value, m: MapTree[Key, Value]) -> MapTree[Key, Value]: return Some(MapTreeLeaf(k, v)) -def try_find(k: Key, m: MapTree[Key, Value]) -> Option[Value]: +def try_find[Key: SupportsLessThanAndHash, Value](k: Key, m: MapTree[Key, Value]) -> Option[Value]: for m2 in m.to_list(): if k == m2.key: return Some(m2.value) @@ -181,14 +180,14 @@ def try_find(k: Key, m: MapTree[Key, Value]) -> Option[Value]: return NOTHING -def find(k: Key, m: MapTree[Key, Value]) -> Value: +def find[Key: SupportsLessThanAndHash, Value](k: Key, m: MapTree[Key, Value]) -> Value: for v in try_find(k, m).to_list(): return v else: raise KeyError("Key not found") -def partition1( +def partition1[Key: SupportsLessThanAndHash, Value]( predicate: Callable[[Key, Value], bool], k: Key, v: Value, @@ -202,7 +201,7 @@ def partition1( return acc1, add(k, v, acc2) -def partition_aux( +def partition_aux[Key: SupportsLessThanAndHash, Value]( predicate: Callable[[Key, Value], bool], m: MapTree[Key, Value], acc: tuple[MapTree[Key, Value], MapTree[Key, Value]], @@ -218,20 +217,22 @@ def partition_aux( return acc -def partition( +def partition[Key: SupportsLessThanAndHash, Value]( predicate: Callable[[Key, Value], bool], m: MapTree[Key, Value] ) -> tuple[MapTree[Key, Value], MapTree[Key, Value]]: return partition_aux(predicate, m, (empty, empty)) -def filter1(predicate: Callable[[Key, Value], bool], k: Key, v: Value, acc: MapTree[Key, Value]) -> MapTree[Key, Value]: +def filter1[Key: SupportsLessThanAndHash, Value]( + predicate: Callable[[Key, Value], bool], k: Key, v: Value, acc: MapTree[Key, Value] +) -> MapTree[Key, Value]: if predicate(k, v): return add(k, v, acc) else: return acc -def filter_aux( +def filter_aux[Key: SupportsLessThanAndHash, Value]( predicate: Callable[[Key, Value], bool], m: MapTree[Key, Value], acc: MapTree[Key, Value], @@ -247,11 +248,15 @@ def filter_aux( return acc -def filter(f: Callable[[Key, Value], bool], m: MapTree[Key, Value]) -> MapTree[Key, Value]: +def filter[Key: SupportsLessThanAndHash, Value]( + f: Callable[[Key, Value], bool], m: MapTree[Key, Value] +) -> MapTree[Key, Value]: return filter_aux(f, m, empty) -def splice_out_successor(m: MapTree[Key, Value]) -> tuple[Key, Value, Option[MapTreeLeaf[Key, Value]]]: +def splice_out_successor[Key: SupportsLessThanAndHash, Value]( + m: MapTree[Key, Value], +) -> tuple[Key, Value, Option[MapTreeLeaf[Key, Value]]]: match m: case Some(MapTreeNode(key=key, value=value, left=left, right=right)): if is_empty(left): @@ -265,7 +270,7 @@ def splice_out_successor(m: MapTree[Key, Value]) -> tuple[Key, Value, Option[Map failwith("internal error: Map.splice_out_successor") -def remove(k: Key, m: MapTree[Key, Value]) -> Option[MapTreeLeaf[Key, Value]]: +def remove[Key: SupportsLessThanAndHash, Value](k: Key, m: MapTree[Key, Value]) -> Option[MapTreeLeaf[Key, Value]]: match m: case Some(MapTreeNode(key=key, value=value, left=left, right=right)): if k < key: @@ -289,7 +294,9 @@ def remove(k: Key, m: MapTree[Key, Value]) -> Option[MapTreeLeaf[Key, Value]]: return empty -def change(k: Key, u: Callable[[Option[Value]], Option[Value]], m: MapTree[Key, Value]) -> MapTree[Key, Value]: +def change[Key: SupportsLessThanAndHash, Value]( + k: Key, u: Callable[[Option[Value]], Option[Value]], m: MapTree[Key, Value] +) -> MapTree[Key, Value]: match m: case Some(MapTreeNode(key=key, value=value, left=left, right=right, height=height)): if k < key: @@ -331,7 +338,7 @@ def change(k: Key, u: Callable[[Option[Value]], Option[Value]], m: MapTree[Key, return m -def mem(k: Key, m: MapTree[Key, Value]) -> bool: +def mem[Key: SupportsLessThanAndHash, Value](k: Key, m: MapTree[Key, Value]) -> bool: match m: case Some(MapTreeNode(key=key, left=left, right=right)): if k < key: @@ -344,7 +351,7 @@ def mem(k: Key, m: MapTree[Key, Value]) -> bool: return False -def iter(fn: Callable[[Key, Value], None], m: MapTree[Key, Value]) -> None: +def iter[Key: SupportsLessThanAndHash, Value](fn: Callable[[Key, Value], None], m: MapTree[Key, Value]) -> None: """Iterate maptree.""" match m: case Some(MapTreeNode(left=left, right=right, key=key, value=value)): @@ -357,7 +364,9 @@ def iter(fn: Callable[[Key, Value], None], m: MapTree[Key, Value]) -> None: pass -def try_pick(f: Callable[[Key, Value], Option[Result]], m: MapTree[Key, Value]) -> Option[Result]: +def try_pick[Key: SupportsLessThanAndHash, Value, Result]( + f: Callable[[Key, Value], Option[Result]], m: MapTree[Key, Value] +) -> Option[Result]: match m: case Some(MapTreeNode(left=left, right=right, key=key, value=value)): res = try_pick(f, left) @@ -375,7 +384,7 @@ def try_pick(f: Callable[[Key, Value], Option[Result]], m: MapTree[Key, Value]) return NOTHING -def exists(f: Callable[[Key, Value], bool], m: MapTree[Key, Value]) -> bool: +def exists[Key: SupportsLessThanAndHash, Value](f: Callable[[Key, Value], bool], m: MapTree[Key, Value]) -> bool: match m: case Some(MapTreeNode(left=left, right=right, key=key, value=value)): return exists(f, left) or f(key, value) or exists(f, right) @@ -385,7 +394,7 @@ def exists(f: Callable[[Key, Value], bool], m: MapTree[Key, Value]) -> bool: return False -def forall(f: Callable[[Key, Value], bool], m: MapTree[Key, Value]) -> bool: +def forall[Key: SupportsLessThanAndHash, Value](f: Callable[[Key, Value], bool], m: MapTree[Key, Value]) -> bool: match m: case Some(MapTreeNode(left=left, right=right, key=key, value=value)): return forall(f, left) and f(key, value) and forall(f, right) @@ -395,7 +404,9 @@ def forall(f: Callable[[Key, Value], bool], m: MapTree[Key, Value]) -> bool: return True -def map(f: Callable[[Key, Value], Result], m: MapTree[Key, Value]) -> MapTree[Key, Result]: +def map[Result, Key: SupportsLessThanAndHash, Value]( + f: Callable[[Key, Value], Result], m: MapTree[Key, Value] +) -> MapTree[Key, Result]: match m: case Some(MapTreeNode(left=left, right=right, key=key, value=value, height=height)): l2 = map(f, left) @@ -408,7 +419,9 @@ def map(f: Callable[[Key, Value], Result], m: MapTree[Key, Value]) -> MapTree[Ke return empty -def fold_back(f: Callable[[tuple[Key, Value], Result], Result], m: MapTree[Key, Value], x: Result) -> Result: +def fold_back[Result, Key: SupportsLessThanAndHash, Value]( + f: Callable[[tuple[Key, Value], Result], Result], m: MapTree[Key, Value], x: Result +) -> Result: match m: case Some(MapTreeNode(left=left, right=right, key=key, value=value)): x = fold_back(f, right, x) @@ -420,7 +433,9 @@ def fold_back(f: Callable[[tuple[Key, Value], Result], Result], m: MapTree[Key, return x -def fold(f: Callable[[Result, tuple[Key, Value]], Result], x: Result, m: MapTree[Key, Value]) -> Result: +def fold[Result, Key: SupportsLessThanAndHash, Value]( + f: Callable[[Result, tuple[Key, Value]], Result], x: Result, m: MapTree[Key, Value] +) -> Result: match m: case Some(MapTreeNode(left=left, right=right, key=key, value=value)): x = fold(f, x, left) @@ -432,7 +447,7 @@ def fold(f: Callable[[Result, tuple[Key, Value]], Result], x: Result, m: MapTree return x -def to_list(m: MapTree[Key, Value]) -> Block[tuple[Key, Value]]: +def to_list[Key: SupportsLessThanAndHash, Value](m: MapTree[Key, Value]) -> Block[tuple[Key, Value]]: def loop(m: MapTree[Key, Value], acc: Block[tuple[Key, Value]]) -> Block[tuple[Key, Value]]: match m: case Some(MapTreeNode(left=left, right=right, key=key, value=value)): @@ -445,7 +460,7 @@ def loop(m: MapTree[Key, Value], acc: Block[tuple[Key, Value]]) -> Block[tuple[K return loop(m, block.empty) -def of_list(xs: Block[tuple[Key, Value]]) -> MapTree[Key, Value]: +def of_list[Key: SupportsLessThanAndHash, Value](xs: Block[tuple[Key, Value]]) -> MapTree[Key, Value]: def folder(acc: MapTree[Key, Value], kv: tuple[Key, Value]): k, v = kv return add(k, v, acc) @@ -453,7 +468,9 @@ def folder(acc: MapTree[Key, Value], kv: tuple[Key, Value]): return xs.fold(folder, empty) -def mk_from_iterator(acc: MapTree[Key, Value], e: Iterator[tuple[Key, Value]]) -> MapTree[Key, Value]: +def mk_from_iterator[Key: SupportsLessThanAndHash, Value]( + acc: MapTree[Key, Value], e: Iterator[tuple[Key, Value]] +) -> MapTree[Key, Value]: try: (x, y) = next(e) except StopIteration: @@ -462,7 +479,7 @@ def mk_from_iterator(acc: MapTree[Key, Value], e: Iterator[tuple[Key, Value]]) - return mk_from_iterator(add(x, y, acc), e) -def of_seq(xs: Iterable[tuple[Key, Value]]) -> MapTree[Key, Value]: +def of_seq[Key: SupportsLessThanAndHash, Value](xs: Iterable[tuple[Key, Value]]) -> MapTree[Key, Value]: ie = builtins.iter(xs) return mk_from_iterator(empty, ie) @@ -473,7 +490,7 @@ def of_seq(xs: Iterable[tuple[Key, Value]]) -> MapTree[Key, Value]: # collapseLHS: # a) Always returns either [] or a list starting with MapOne. # b) The "fringe" of the set stack is unchanged. -def collapseLHS(stack: Block[MapTree[Key, Value]]) -> Block[MapTree[Key, Value]]: +def collapseLHS[Key: SupportsLessThanAndHash, Value](stack: Block[MapTree[Key, Value]]) -> Block[MapTree[Key, Value]]: if stack.is_empty(): return block.empty m, rest = stack.head(), stack.tail() @@ -487,7 +504,7 @@ def collapseLHS(stack: Block[MapTree[Key, Value]]) -> Block[MapTree[Key, Value]] return collapseLHS(rest) -class MkIterator(Iterator[tuple[Key, Value]]): +class MkIterator[Key: SupportsLessThanAndHash, Value](Iterator[tuple[Key, Value]]): def __init__(self, m: MapTree[Key, Value]) -> None: self.stack = collapseLHS(block.singleton(m)) @@ -514,11 +531,11 @@ def already_finished(): failwith("enumeration already finished") -def mk_iterator(m: MapTree[Key, Value]) -> Iterator[tuple[Key, Value]]: +def mk_iterator[Key: SupportsLessThanAndHash, Value](m: MapTree[Key, Value]) -> Iterator[tuple[Key, Value]]: return MkIterator(m) -def to_seq(s: MapTree[Key, Value]) -> Iterable[tuple[Key, Value]]: +def to_seq[Key: SupportsLessThanAndHash, Value](s: MapTree[Key, Value]) -> Iterable[tuple[Key, Value]]: it = mk_iterator(s) def folder(it: Iterator[tuple[Key, Value]]): diff --git a/expression/collections/seq.py b/expression/collections/seq.py index cf8f9ed7..fe68febe 100644 --- a/expression/collections/seq.py +++ b/expression/collections/seq.py @@ -28,7 +28,7 @@ import functools import itertools from collections.abc import Callable, Iterable, Iterator -from typing import TYPE_CHECKING, Any, TypeVar, cast, overload +from typing import TYPE_CHECKING, Any, cast, overload from expression.core import ( NOTHING, @@ -47,19 +47,8 @@ if TYPE_CHECKING: from .block import Block -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") -_TState = TypeVar("_TState") -_TSupportsGreaterThan = TypeVar("_TSupportsGreaterThan", bound=SupportsGreaterThan) -_TSupportsLessThan = TypeVar("_TSupportsLessThan", bound=SupportsLessThan) -_TSupportsSum = TypeVar("_TSupportsSum", bound=SupportsSum) -_T1 = TypeVar("_T1") -_T2 = TypeVar("_T2") -_T3 = TypeVar("_T3") -_T4 = TypeVar("_T4") - -class Seq(Iterable[_TSource], PipeMixin): +class Seq[TSource](Iterable[TSource], PipeMixin): """Sequence type. Contains instance methods for dot-chaining operators methods on @@ -72,18 +61,18 @@ class Seq(Iterable[_TSource], PipeMixin): __match_args__ = ("iterable",) - def __init__(self, iterable: Iterable[_TSource] = ()) -> None: + def __init__(self, iterable: Iterable[TSource] = ()) -> None: self._value = iterable @staticmethod - def of(*args: _TResult) -> Seq[_TResult]: + def of[TResult](*args: TResult) -> Seq[TResult]: return Seq(args) @classmethod - def of_iterable(cls, source: Iterable[_TSource]) -> Seq[_TSource]: + def of_iterable(cls, source: Iterable[TSource]) -> Seq[TSource]: return cls(source) - def append(self, *others: Iterable[_TSource]) -> Seq[_TSource]: + def append(self, *others: Iterable[TSource]) -> Seq[TSource]: """Append sequence to other sequences. Wraps the given enumerations as a single concatenated @@ -91,10 +80,10 @@ def append(self, *others: Iterable[_TSource]) -> Seq[_TSource]: """ return Seq(concat(self._value, *others)) - def filter(self, predicate: Callable[[_TSource], bool]) -> Seq[_TSource]: + def filter(self, predicate: Callable[[TSource], bool]) -> Seq[TSource]: return Seq(filter(predicate)(self)) - def choose(self, chooser: Callable[[_TSource], Option[_TResult]]) -> Seq[_TResult]: + def choose[TResult](self, chooser: Callable[[TSource], Option[TResult]]) -> Seq[TResult]: """Choose items from the sequence. Applies the given function to each element of the list. Returns @@ -111,7 +100,7 @@ def choose(self, chooser: Callable[[_TSource], Option[_TResult]]) -> Seq[_TResul xs = pipe(self, choose(chooser)) return Seq(xs) - def concat(self: Seq[Seq[_TResult]]) -> Seq[_TResult]: + def concat[TResult](self: Seq[Seq[TResult]]) -> Seq[TResult]: """Concatenate sequences. Combines the given variable number of enumerations and/or @@ -119,7 +108,7 @@ def concat(self: Seq[Seq[_TResult]]) -> Seq[_TResult]: """ return Seq(concat(*self)) - def collect(self, mapping: Callable[[_TSource], Seq[_TResult]]) -> Seq[_TResult]: + def collect[TResult](self, mapping: Callable[[TSource], Seq[TResult]]) -> Seq[TResult]: """Collect items from the sequence. Applies the given function to each element of the list and @@ -136,7 +125,7 @@ def collect(self, mapping: Callable[[_TSource], Seq[_TResult]]) -> Seq[_TResult] return self.map(mapping).concat() @staticmethod - def delay(generator: Callable[[], Iterable[_TSource]]) -> Iterable[_TSource]: + def delay(generator: Callable[[], Iterable[TSource]]) -> Iterable[TSource]: """Delay sequence. Returns a sequence that is built from the given delayed specification of a @@ -151,11 +140,11 @@ def delay(generator: Callable[[], Iterable[_TSource]]) -> Iterable[_TSource]: return delay(generator) @staticmethod - def empty() -> Seq[_TSource]: + def empty() -> Seq[TSource]: """Returns empty sequence.""" return Seq() - def fold(self, folder: Callable[[_TState, _TSource], _TState], state: _TState) -> _TState: + def fold[TState](self, folder: Callable[[TState, TSource], TState], state: TState) -> TState: """Fold sequence. Applies a function to each element of the collection, @@ -174,7 +163,7 @@ def fold(self, folder: Callable[[_TState, _TSource], _TState], state: _TState) - """ return functools.reduce(folder, self, state) - def head(self) -> _TSource: + def head(self) -> TSource: """Returns the first element of the sequence.""" return head(self) @@ -182,7 +171,7 @@ def length(self) -> int: """Returns the length of the sequence.""" return length(self) - def map(self, mapper: Callable[[_TSource], _TResult]) -> Seq[_TResult]: + def map[TResult](self, mapper: Callable[[TSource], TResult]) -> Seq[TResult]: """Map sequence. Builds a new collection whose elements are the results of @@ -198,19 +187,19 @@ def map(self, mapper: Callable[[_TSource], _TResult]) -> Seq[_TResult]: return Seq(pipe(self, map(mapper))) @overload - def starmap(self: Seq[tuple[_T1, _T2]], mapping: Callable[[_T1, _T2], _TResult]) -> Seq[_TResult]: ... + def starmap[T1, T2, TResult](self: Seq[tuple[T1, T2]], mapping: Callable[[T1, T2], TResult]) -> Seq[TResult]: ... @overload - def starmap( - self: Seq[tuple[_T1, _T2, _T3]], - mapping: Callable[[_T1, _T2, _T3], _TResult], - ) -> Seq[_TResult]: ... + def starmap[T1, T2, T3, TResult]( + self: Seq[tuple[T1, T2, T3]], + mapping: Callable[[T1, T2, T3], TResult], + ) -> Seq[TResult]: ... @overload - def starmap( - self: Seq[tuple[_T1, _T2, _T3, _T4]], - mapping: Callable[[_T1, _T2, _T3, _T4], _TResult], - ) -> Seq[_TResult]: ... + def starmap[T1, T2, T3, T4, TResult]( + self: Seq[tuple[T1, T2, T3, T4]], + mapping: Callable[[T1, T2, T3, T4], TResult], + ) -> Seq[TResult]: ... def starmap(self: Seq[Any], mapping: Callable[..., Any]) -> Seq[Any]: """Starmap source sequence. @@ -228,7 +217,7 @@ def starmap(self: Seq[Any], mapping: Callable[..., Any]) -> Seq[Any]: """ return Seq(starmap(mapping)(self)) - def mapi(self, mapping: Callable[[int, _TSource], _TResult]) -> Seq[_TResult]: + def mapi[TResult](self, mapping: Callable[[int, TSource], TResult]) -> Seq[TResult]: """Map list with index. Builds a new collection whose elements are the results of @@ -245,7 +234,7 @@ def mapi(self, mapping: Callable[[int, _TSource], _TResult]) -> Seq[_TResult]: """ return Seq(mapi(mapping)(self)) - def pairwise(self) -> Seq[tuple[_TSource, _TSource]]: + def pairwise(self) -> Seq[tuple[TSource, TSource]]: """Return adjacent elements paired with their predecessor.""" return Seq(pairwise(self)) @@ -265,7 +254,7 @@ def range(start: int, stop: int, step: int) -> Iterable[int]: ... def range(*args: int, **kw: int) -> Iterable[int]: return range(*args, **kw) - def scan(self, scanner: Callable[[_TState, _TSource], _TState], state: _TState) -> Iterable[_TState]: + def scan[TState](self, scanner: Callable[[TState, TSource], TState], state: TState) -> Iterable[TState]: """Scan sequence. Like fold, but computes on-demand and returns the sequence of @@ -281,7 +270,7 @@ def scan(self, scanner: Callable[[_TState, _TSource], _TState], state: _TState) """ return Seq(itertools.accumulate(self._value, scanner, initial=state)) - def skip(self, count: int) -> Seq[_TSource]: + def skip(self, count: int) -> Seq[TSource]: """Skip elements from sequence. Returns a sequence that skips N elements of the underlying @@ -292,11 +281,11 @@ def skip(self, count: int) -> Seq[_TSource]: """ return Seq(pipe(self, skip(count))) - def sum(self: Seq[_TSupportsSum]) -> _TSupportsSum: + def sum[TSupportsSum: SupportsSum](self: Seq[TSupportsSum]) -> TSupportsSum: """Returns the sum of the elements in the sequence.""" return sum(self) - def sum_by(self, projection: Callable[[_TSource], _TSupportsSum]) -> _TSupportsSum: + def sum_by[TSupportsSum: SupportsSum](self, projection: Callable[[TSource], TSupportsSum]) -> TSupportsSum: """Sum the sequence by projection. Returns the sum of the results generated by applying the @@ -304,7 +293,7 @@ def sum_by(self, projection: Callable[[_TSource], _TSupportsSum]) -> _TSupportsS """ return pipe(self, sum_by(projection)) - def tail(self) -> Seq[_TSource]: + def tail(self) -> Seq[TSource]: """Return the tail of the sequence. Returns a sequence that skips 1 element of the underlying @@ -313,7 +302,7 @@ def tail(self) -> Seq[_TSource]: """ return self.skip(1) - def take(self, count: int) -> Seq[_TSource]: + def take(self, count: int) -> Seq[TSource]: """Returns the first N elements of the sequence. Args: @@ -321,7 +310,7 @@ def take(self, count: int) -> Seq[_TSource]: """ return Seq(pipe(self, take(count))) - def take_while(self, predicate: Callable[[_TSource], bool]) -> Seq[_TSource]: + def take_while(self, predicate: Callable[[TSource], bool]) -> Seq[TSource]: """Returns elements while a predicate holds. Returns a sequence that yields elements from the underlying @@ -334,18 +323,18 @@ def take_while(self, predicate: Callable[[_TSource], bool]) -> Seq[_TSource]: """ return Seq(pipe(self, take_while(predicate))) - def to_list(self) -> Block[_TSource]: + def to_list(self) -> Block[TSource]: return to_list(self) - def try_find_index(self, predicate: Callable[[_TSource], bool]) -> Option[int]: + def try_find_index(self, predicate: Callable[[TSource], bool]) -> Option[int]: """Return the index of the first element matching the predicate, if any.""" return pipe(self, try_find_index(predicate)) - def try_pick(self, chooser: Callable[[_TSource], Option[_TResult]]) -> Option[_TResult]: + def try_pick[TResult](self, chooser: Callable[[TSource], Option[TResult]]) -> Option[TResult]: """Return the first value produced by the chooser, if any.""" return pipe(self, try_pick(chooser)) - def dict(self) -> Iterable[_TSource]: + def dict(self) -> Iterable[TSource]: """Returns a json serializable representation of the list.""" def to_obj(value: Any) -> Any: @@ -357,11 +346,11 @@ def to_obj(value: Any) -> Any: return (to_obj(value) for value in self) @classmethod - def unfold( + def unfold[TState]( cls, - generator: Callable[[_TState], Option[tuple[_TSource, _TState]]], - state: _TState, - ) -> Iterable[_TSource]: + generator: Callable[[TState], Option[tuple[TSource, TState]]], + state: TState, + ) -> Iterable[TSource]: """Unfold sequence. Returns a list that contains the elements generated by the @@ -379,7 +368,7 @@ def unfold( """ return pipe(state, unfold(generator)) - def zip(self, other: Iterable[_TResult]) -> Iterable[tuple[_TSource, _TResult]]: + def zip[TResult](self, other: Iterable[TResult]) -> Iterable[tuple[TSource, TResult]]: """Zip sequence. Combines the two sequences into a list of pairs. The two @@ -395,7 +384,7 @@ def zip(self, other: Iterable[_TResult]) -> Iterable[tuple[_TSource, _TResult]]: """ return builtins.zip(self, other) - def __iter__(self) -> Iterator[_TSource]: + def __iter__(self) -> Iterator[TSource]: """Return iterator for sequence.""" # Make sure we return a proper generator that can handle send, throw, and close return (x for x in self._value) @@ -420,38 +409,40 @@ def __str__(self) -> str: return repr(self) -class SeqGen(Iterable[_TSource]): +class SeqGen[TSource](Iterable[TSource]): """Sequence from a generator function. We use this to allow multiple iterations over the same sequence generated by a generator function. """ - def __init__(self, gen: Callable[[], Iterable[_TSource]]) -> None: + def __init__(self, gen: Callable[[], Iterable[TSource]]) -> None: self.gen = gen - def __iter__(self) -> Iterator[_TSource]: + def __iter__(self) -> Iterator[TSource]: xs = self.gen() # Make sure we return a proper generator that can handle send, throw, and close return (x for x in xs) -def append( - *others: Iterable[_TSource], -) -> Callable[[Iterable[_TSource]], Iterable[_TSource]]: +def append[TSource]( + *others: Iterable[TSource], +) -> Callable[[Iterable[TSource]], Iterable[TSource]]: """Append sequence to other sequences. Wraps the given enumerations as a single concatenated enumeration. """ - def _(source: Iterable[_TSource]) -> Iterable[_TSource]: + def _(source: Iterable[TSource]) -> Iterable[TSource]: return concat(source, *others) return _ @curry_flip(1) -def choose(source: Iterable[_TSource], chooser: Callable[[_TSource], Option[_TResult]]) -> Iterable[_TResult]: +def choose[TSource, TResult]( + source: Iterable[TSource], chooser: Callable[[TSource], Option[TResult]] +) -> Iterable[TResult]: """Choose items from the sequence. Applies the given function to each element of the list. Returns @@ -467,17 +458,17 @@ def choose(source: Iterable[_TSource], chooser: Callable[[_TSource], Option[_TRe function. """ - def mapper(x: _TSource) -> Iterable[_TResult]: + def mapper(x: TSource) -> Iterable[TResult]: return chooser(x).to_seq() return pipe(source, collect(mapper)) @curry_flip(1) -def collect( - source: Iterable[_TSource], - mapping: Callable[[_TSource], Iterable[_TResult]], -) -> Iterable[_TResult]: +def collect[TSource, TResult]( + source: Iterable[TSource], + mapping: Callable[[TSource], Iterable[TResult]], +) -> Iterable[TResult]: """Collect items from the sequence. Applies the given function to each element of the list and @@ -493,14 +484,14 @@ def collect( function. """ - def gen() -> Iterator[_TResult]: + def gen() -> Iterator[TResult]: for xs in source: yield from mapping(xs) return SeqGen(gen) -def concat(*iterables: Iterable[_TSource]) -> Iterable[_TSource]: +def concat[TSource](*iterables: Iterable[TSource]) -> Iterable[TSource]: """Concatenate sequences. Combines the given variable number of enumerations and/or @@ -513,14 +504,14 @@ def concat(*iterables: Iterable[_TSource]) -> Iterable[_TSource]: The result sequence. """ - def gen() -> Iterator[_TSource]: + def gen() -> Iterator[TSource]: for it in iterables: yield from it return SeqGen(gen) -def delay(generator: Callable[[], Iterable[_TSource]]) -> Iterable[_TSource]: +def delay[TSource](generator: Callable[[], Iterable[TSource]]) -> Iterable[TSource]: """Delay sequence. Returns a sequence that is built from the given delayed @@ -540,7 +531,7 @@ def delay(generator: Callable[[], Iterable[_TSource]]) -> Iterable[_TSource]: @curry_flip(1) -def filter(source: Iterable[_TSource], predicate: Callable[[_TSource], bool]) -> Iterable[_TSource]: +def filter[TSource](source: Iterable[TSource], predicate: Callable[[TSource], bool]) -> Iterable[TSource]: """Filter sequence. Filters the sequence to a new sequence containing only the @@ -559,11 +550,11 @@ def filter(source: Iterable[_TSource], predicate: Callable[[_TSource], bool]) -> @curry_flip(1) -def fold( - source: Iterable[_TSource], - folder: Callable[[_TState, _TSource], _TState], - state: _TState, -) -> _TState: +def fold[TSource, TState]( + source: Iterable[TSource], + folder: Callable[[TState, TSource], TState], + state: TState, +) -> TState: """Fold elements in sequence. Applies a function to each element of the collection, @@ -585,9 +576,9 @@ def fold( return functools.reduce(folder, source, state) -def fold_back( - folder: Callable[[_TSource, _TState], _TState], source: Iterable[_TSource] -) -> Callable[[_TState], _TState]: +def fold_back[TState, TSource]( + folder: Callable[[TSource, TState], TState], source: Iterable[TSource] +) -> Callable[[TState], TState]: """Fold elements in sequence backwards. Applies a function to each element of the collection, @@ -604,7 +595,7 @@ def fold_back( Partially applied fold_back function. """ - def _fold_back(state: _TState) -> _TState: + def _fold_back(state: TState) -> TState: """Partially applied fold_back function. Returns: @@ -616,7 +607,7 @@ def _fold_back(state: _TState) -> _TState: return _fold_back -def head(source: Iterable[_TSource]) -> _TSource: +def head[TSource](source: Iterable[TSource]) -> TSource: """Return the first element of the sequence. Args: @@ -634,7 +625,7 @@ def head(source: Iterable[_TSource]) -> _TSource: raise ValueError("Sequence contains no elements") -def init_infinite(initializer: Callable[[int], _TSource]) -> Iterable[_TSource]: +def init_infinite[TSource](initializer: Callable[[int], TSource]) -> Iterable[TSource]: """Generate infinite sequence. Generates a new sequence which, when iterated, will return @@ -646,16 +637,16 @@ def init_infinite(initializer: Callable[[int], _TSource]) -> Iterable[_TSource]: Iteration can continue up to `sys.maxsize`. """ - class Infinite(Iterable[_TResult]): + class Infinite[TResult](Iterable[TResult]): """An infinite iterable. Where each iterator starts counting at 0. """ - def __init__(self, initializer: Callable[[int], _TResult]) -> None: + def __init__(self, initializer: Callable[[int], TResult]) -> None: self.initializer = initializer - def __iter__(self) -> Iterator[_TResult]: + def __iter__(self) -> Iterator[TResult]: return builtins.map(self.initializer, itertools.count(0, 1)) return Infinite(initializer) @@ -666,7 +657,7 @@ def __iter__(self) -> Iterator[_TResult]: @curry_flip(1) -def iter(source: Iterable[_TSource], action: Callable[[_TSource], None]) -> None: +def iter[TSource](source: Iterable[TSource], action: Callable[[TSource], None]) -> None: """Applies the given function to each element of the collection. Args: @@ -686,7 +677,7 @@ def length(source: Seq[Any]) -> int: @curry_flip(1) -def map(source: Iterable[_TSource], mapper: Callable[[_TSource], _TResult]) -> Iterable[_TResult]: +def map[TSource, TResult](source: Iterable[TSource], mapper: Callable[[TSource], TResult]) -> Iterable[TResult]: """Map source sequence. Builds a new collection whose elements are the results of @@ -709,19 +700,21 @@ def gen(): @overload -def starmap(mapper: Callable[[_T1, _T2], _TResult]) -> Callable[[Iterable[tuple[_T1, _T2]]], Iterable[_TResult]]: ... +def starmap[TResult, T1, T2]( + mapper: Callable[[T1, T2], TResult], +) -> Callable[[Iterable[tuple[T1, T2]]], Iterable[TResult]]: ... @overload -def starmap( - mapper: Callable[[_T1, _T2, _T3], _TResult], -) -> Callable[[Iterable[tuple[_T1, _T2, _T3]]], Iterable[_TResult]]: ... +def starmap[TResult, T1, T2, T3]( + mapper: Callable[[T1, T2, T3], TResult], +) -> Callable[[Iterable[tuple[T1, T2, T3]]], Iterable[TResult]]: ... @overload -def starmap( - mapper: Callable[[_T1, _T2, _T3, _T4], _TResult], -) -> Callable[[Iterable[tuple[_T1, _T2, _T3, _T4]]], Iterable[_TResult]]: ... +def starmap[TResult, T1, T2, T3, T4]( + mapper: Callable[[T1, T2, T3, T4], TResult], +) -> Callable[[Iterable[tuple[T1, T2, T3, T4]]], Iterable[TResult]]: ... def starmap(mapper: Callable[..., Any]) -> Callable[[Iterable[Any]], Iterable[Any]]: @@ -744,16 +737,20 @@ def mapper_(args: tuple[Any, ...]) -> Any: return map(mapper_) -def map2(mapper: Callable[[_T1, _T2], _TResult]) -> Callable[[Iterable[tuple[_T1, _T2]]], Iterable[_TResult]]: +def map2[TResult, T1, T2]( + mapper: Callable[[T1, T2], TResult], +) -> Callable[[Iterable[tuple[T1, T2]]], Iterable[TResult]]: return starmap(mapper) -def map3(mapper: Callable[[_T1, _T2, _T3], _TResult]) -> Callable[[Iterable[tuple[_T1, _T2, _T3]]], Iterable[_TResult]]: +def map3[TResult, T1, T2, T3]( + mapper: Callable[[T1, T2, T3], TResult], +) -> Callable[[Iterable[tuple[T1, T2, T3]]], Iterable[TResult]]: return starmap(mapper) @curry_flip(1) -def mapi(source: Iterable[_TSource], mapping: Callable[[int, _TSource], _TResult]) -> Iterable[_TResult]: +def mapi[TSource, TResult](source: Iterable[TSource], mapping: Callable[[int, TSource], TResult]) -> Iterable[TResult]: """Map list with index. Builds a new collection whose elements are the results of @@ -772,24 +769,24 @@ def mapi(source: Iterable[_TSource], mapping: Callable[[int, _TSource], _TResult return (*itertools.starmap(mapping, builtins.enumerate(source)),) -def max(source: Iterable[_TSupportsGreaterThan]) -> _TSupportsGreaterThan: +def max[TSupportsGreaterThan: SupportsGreaterThan](source: Iterable[TSupportsGreaterThan]) -> TSupportsGreaterThan: """Return maximum of all elements. Returns the greatest of all elements of the sequence, compared via `max()`. """ - value: _TSupportsGreaterThan = builtins.max(source) + value: TSupportsGreaterThan = builtins.max(source) return value @curry_flip(1) -def max_by( - source: Iterable[_TSource], projection: Callable[[_TSource], _TSupportsGreaterThan] -) -> _TSupportsGreaterThan: +def max_by[TSource, TSupportsGreaterThan: SupportsGreaterThan]( + source: Iterable[TSource], projection: Callable[[TSource], TSupportsGreaterThan] +) -> TSupportsGreaterThan: return builtins.max(projection(x) for x in source) -def min(source: Iterable[_TSupportsLessThan]) -> _TSupportsLessThan: +def min[TSupportsLessThan: SupportsLessThan](source: Iterable[TSupportsLessThan]) -> TSupportsLessThan: """Return the minimum of all elements. Returns the smallest of all elements of the sequence, compared via @@ -799,11 +796,13 @@ def min(source: Iterable[_TSupportsLessThan]) -> _TSupportsLessThan: @curry_flip(1) -def min_by(source: Iterable[_TSource], projection: Callable[[_TSource], _TSupportsLessThan]) -> _TSupportsLessThan: +def min_by[TSource, TSupportsLessThan: SupportsLessThan]( + source: Iterable[TSource], projection: Callable[[TSource], TSupportsLessThan] +) -> TSupportsLessThan: return builtins.min(projection(x) for x in source) -def of(*args: _TSource) -> Seq[_TSource]: +def of[TSource](*args: TSource) -> Seq[TSource]: """Create sequence from iterable. Enables fluent dot chaining on the created sequence object. @@ -811,7 +810,7 @@ def of(*args: _TSource) -> Seq[_TSource]: return Seq(args) -def of_iterable(source: Iterable[_TSource]) -> Seq[_TSource]: +def of_iterable[TSource](source: Iterable[TSource]) -> Seq[TSource]: """Alias to `Seq.of`.""" return Seq(source) @@ -820,7 +819,7 @@ def of_iterable(source: Iterable[_TSource]) -> Seq[_TSource]: """Alias to `seq.of_iterable`.""" -def pairwise(source: Iterable[_TSource]) -> Iterable[tuple[_TSource, _TSource]]: +def pairwise[TSource](source: Iterable[TSource]) -> Iterable[tuple[TSource, TSource]]: """Return adjacent elements paired with their predecessor. The result is evaluated lazily and contains no elements when the source has @@ -859,11 +858,11 @@ def range(*args: int, **kw: int) -> Iterable[int]: @curry_flip(1) -def scan( - source: Iterable[_TSource], - scanner: Callable[[_TState, _TSource], _TState], - state: _TState, -) -> Iterable[_TState]: +def scan[TSource, TState]( + source: Iterable[TSource], + scanner: Callable[[TState, TSource], TState], + state: TState, +) -> Iterable[TState]: """Scan elements in sequence. Like fold, but computes on-demand and returns the sequence of @@ -877,7 +876,7 @@ def scan( return itertools.accumulate(source, scanner, initial=state) -def singleton(item: _TSource) -> Seq[_TSource]: +def singleton[TSource](item: TSource) -> Seq[TSource]: """Returns a sequence that yields one item only. Args: @@ -890,7 +889,7 @@ def singleton(item: _TSource) -> Seq[_TSource]: @curry_flip(1) -def skip(source: Iterable[_TSource], count: int) -> Iterable[_TSource]: +def skip[TSource](source: Iterable[TSource], count: int) -> Iterable[TSource]: """Skip elements from sequence. Returns a sequence that skips N elements of the underlying @@ -909,14 +908,16 @@ def gen(): return SeqGen(gen) -def sum(source: Iterable[_TSupportsSum]) -> _TSupportsSum: +def sum[TSupportsSum: SupportsSum](source: Iterable[TSupportsSum]) -> TSupportsSum: """Returns the sum of the elements in the sequence.""" ret = builtins.sum(source) - return cast(_TSupportsSum, ret) + return cast(TSupportsSum, ret) @curry_flip(1) -def sum_by(source: Iterable[_TSource], projection: Callable[[_TSource], _TSupportsSum]) -> _TSupportsSum: +def sum_by[TSource, TSupportsSum: SupportsSum]( + source: Iterable[TSource], projection: Callable[[TSource], TSupportsSum] +) -> TSupportsSum: """Sum all elements in sequence. Returns the sum of the results generated by applying the function to @@ -925,18 +926,18 @@ def sum_by(source: Iterable[_TSource], projection: Callable[[_TSource], _TSuppor return sum(projection(x) for x in source) -def tail(source: Iterable[_TSource]) -> Iterable[_TSource]: +def tail[TSource](source: Iterable[TSource]) -> Iterable[TSource]: """Return tail of sequence. Returns a sequence that skips 1 element of the underlying sequence and then yields the remaining elements of the sequence. """ - proj = cast(Callable[[Iterable[_TSource]], Iterable[_TSource]], skip(1)) + proj = cast(Callable[[Iterable[TSource]], Iterable[TSource]], skip(1)) return proj(source) @curry_flip(1) -def take(source: Iterable[_TSource], count: int) -> Iterable[_TSource]: +def take[TSource](source: Iterable[TSource], count: int) -> Iterable[TSource]: """Returns the first N elements of the sequence. Args: @@ -960,7 +961,7 @@ def gen(): @curry_flip(1) -def take_while(source: Iterable[_TSource], predicate: Callable[[_TSource], bool]) -> Iterable[_TSource]: +def take_while[TSource](source: Iterable[TSource], predicate: Callable[[TSource], bool]) -> Iterable[TSource]: """Returns elements while a predicate holds. Returns a sequence that yields elements from the underlying @@ -976,7 +977,7 @@ def take_while(source: Iterable[_TSource], predicate: Callable[[_TSource], bool] The result sequence. """ - def gen() -> Iterator[_TSource]: + def gen() -> Iterator[TSource]: for item in source: if not predicate(item): break @@ -985,14 +986,14 @@ def gen() -> Iterator[_TSource]: return SeqGen(gen) -def to_list(source: Iterable[_TSource]) -> Block[_TSource]: +def to_list[TSource](source: Iterable[TSource]) -> Block[TSource]: from .block import Block return Block.of_seq(source) @curry_flip(1) -def try_find_index(source: Iterable[_TSource], predicate: Callable[[_TSource], bool]) -> Option[int]: +def try_find_index[TSource](source: Iterable[TSource], predicate: Callable[[TSource], bool]) -> Option[int]: """Return the index of the first element matching the predicate, if any. Indices are zero-based, and evaluation stops as soon as the predicate @@ -1018,7 +1019,9 @@ def try_find_index(source: Iterable[_TSource], predicate: Callable[[_TSource], b @curry_flip(1) -def try_pick(source: Iterable[_TSource], chooser: Callable[[_TSource], Option[_TResult]]) -> Option[_TResult]: +def try_pick[TSource, TResult]( + source: Iterable[TSource], chooser: Callable[[TSource], Option[TResult]] +) -> Option[TResult]: """Return the first value produced by the chooser, if any. The chooser is evaluated in sequence order, and evaluation stops as @@ -1045,7 +1048,9 @@ def try_pick(source: Iterable[_TSource], chooser: Callable[[_TSource], Option[_T @curry_flip(1) -def unfold(state: _TState, generator: Callable[[_TState], Option[tuple[_TSource, _TState]]]) -> Iterable[_TSource]: +def unfold[TState, TSource]( + state: TState, generator: Callable[[TState], Option[tuple[TSource, TState]]] +) -> Iterable[TSource]: """Unfold sequence. Generates a list that contains the elements generated by the given @@ -1071,9 +1076,9 @@ def unfold(state: _TState, generator: Callable[[_TState], Option[tuple[_TSource, yield item -def zip( - source1: Iterable[_TSource], -) -> Callable[[Iterable[_TResult]], Iterable[tuple[_TSource, _TResult]]]: +def zip[TSource, TResult]( + source1: Iterable[TSource], +) -> Callable[[Iterable[TResult]], Iterable[tuple[TSource, TResult]]]: """Zip sequence with other. Combines the two sequences into a list of pairs. The two @@ -1088,7 +1093,7 @@ def zip( Partially applied zip function. """ - def _zip(source2: Iterable[_TResult]) -> Iterable[tuple[_TSource, _TResult]]: + def _zip(source2: Iterable[TResult]) -> Iterable[tuple[TSource, TResult]]: """Curried function. Combines the two sequences into a list of pairs. The two diff --git a/expression/core/aiotools.py b/expression/core/aiotools.py index 1d0d51cf..5853df1f 100644 --- a/expression/core/aiotools.py +++ b/expression/core/aiotools.py @@ -12,17 +12,15 @@ from asyncio import Future, Task from collections.abc import Awaitable, Callable from inspect import iscoroutine -from typing import Any, TypeVar +from typing import Any from expression.system import CancellationToken, ObjectDisposedException, OperationCanceledError -_TSource = TypeVar("_TSource") - -Continuation = Callable[[_TSource], None] -Callbacks = Callable[ +type Continuation[TSource] = Callable[[TSource], None] +type Callbacks[TSource] = Callable[ [ - Continuation[_TSource], + Continuation[TSource], Continuation[Exception], Continuation[OperationCanceledError], ], @@ -30,7 +28,7 @@ ] -def from_continuations(callback: Callbacks[_TSource]) -> Awaitable[_TSource]: +def from_continuations[TSource](callback: Callbacks[TSource]) -> Awaitable[TSource]: """Create async computation from continuations. Creates an asynchronous computation that captures the current @@ -45,9 +43,9 @@ def from_continuations(callback: Callbacks[_TSource]) -> Awaitable[_TSource]: An asynchronous computation that provides the callback with the current continuations. """ - future: Future[_TSource] = asyncio.Future() + future: Future[TSource] = asyncio.Future() - def done(value: _TSource) -> None: + def done(value: TSource) -> None: if not future.done(): future.set_result(value) @@ -69,8 +67,8 @@ def cancel(_: OperationCanceledError) -> None: __running_tasks: set[Task[Any]] = set() -def _start_task(computation: Awaitable[_TSource], token: CancellationToken | None = None) -> Task[_TSource]: - async def runner() -> _TSource: +def _start_task[TSource](computation: Awaitable[TSource], token: CancellationToken | None = None) -> Task[TSource]: + async def runner() -> TSource: if token is not None and token.is_cancellation_requested: raise asyncio.CancelledError() return await computation @@ -89,7 +87,7 @@ def cancel() -> None: except ObjectDisposedException: cancel() - def cleanup(completed: Task[_TSource]) -> None: + def cleanup(completed: Task[TSource]) -> None: __running_tasks.discard(completed) if registration is not None: registration.dispose() @@ -114,16 +112,16 @@ def start_immediate(computation: Awaitable[Any], token: CancellationToken | None _start_task(computation, token) -def run_synchronously(computation: Awaitable[_TSource]) -> _TSource: +def run_synchronously[TSource](computation: Awaitable[TSource]) -> TSource: """Runs the asynchronous computation and await its result.""" - async def runner() -> _TSource: + async def runner() -> TSource: return await computation return asyncio.run(runner()) -async def singleton(value: _TSource) -> _TSource: +async def singleton[TSource](value: TSource) -> TSource: """Async function that returns a single value.""" return value @@ -143,14 +141,14 @@ async def empty() -> None: """Async no-op.""" -def from_result(result: _TSource) -> Awaitable[_TSource]: +def from_result[TSource](result: TSource) -> Awaitable[TSource]: """Awaitable from result. Creates a async operation that's completed successfully with the specified result. """ - async def from_result(result: _TSource) -> _TSource: + async def from_result(result: TSource) -> TSource: """Async return value.""" return result diff --git a/expression/core/apipe.py b/expression/core/apipe.py index 23125a18..fa2dc2c9 100644 --- a/expression/core/apipe.py +++ b/expression/core/apipe.py @@ -6,138 +6,124 @@ import inspect from collections.abc import Callable, Coroutine -from typing import Any, TypeVar, overload +from typing import Any, overload -_A = TypeVar("_A") -_B = TypeVar("_B") -_C = TypeVar("_C") -_D = TypeVar("_D") -_E = TypeVar("_E") -_F = TypeVar("_F") -_G = TypeVar("_G") -_H = TypeVar("_H") -_T = TypeVar("_T") -_J = TypeVar("_J") - -_X = TypeVar("_X") -_Y = TypeVar("_Y") - -SyncCallable = Callable[[_X], _Y] -AsyncCallable = Callable[[_X], Coroutine[Any, Any, _Y]] -SyncOrAsyncCallable = SyncCallable[_X, _Y] | AsyncCallable[_X, _Y] +type SyncCallable[X, Y] = Callable[[X], Y] +type AsyncCallable[X, Y] = Callable[[X], Coroutine[Any, Any, Y]] +type SyncOrAsyncCallable[X, Y] = SyncCallable[X, Y] | AsyncCallable[X, Y] @overload -async def apipe(value: Coroutine[Any, Any, _A] | _A, /) -> _A: ... +async def apipe[A](value: Coroutine[Any, Any, A] | A, /) -> A: ... @overload -async def apipe( - value: Coroutine[Any, Any, _A] | _A, - fn1: SyncOrAsyncCallable[_A, _B], +async def apipe[A, B]( + value: Coroutine[Any, Any, A] | A, + fn1: SyncOrAsyncCallable[A, B], /, -) -> _B: ... +) -> B: ... @overload -async def apipe( - value: Coroutine[Any, Any, _A] | _A, - fn1: SyncOrAsyncCallable[_A, _B], - fn2: SyncOrAsyncCallable[_B, _C], +async def apipe[A, B, C]( + value: Coroutine[Any, Any, A] | A, + fn1: SyncOrAsyncCallable[A, B], + fn2: SyncOrAsyncCallable[B, C], /, -) -> _C: ... +) -> C: ... @overload -async def apipe( - value: Coroutine[Any, Any, _A] | _A, - fn1: SyncOrAsyncCallable[_A, _B], - fn2: SyncOrAsyncCallable[_B, _C], - fn3: SyncOrAsyncCallable[_C, _D], +async def apipe[A, B, C, D]( + value: Coroutine[Any, Any, A] | A, + fn1: SyncOrAsyncCallable[A, B], + fn2: SyncOrAsyncCallable[B, C], + fn3: SyncOrAsyncCallable[C, D], /, -) -> _D: ... +) -> D: ... @overload -async def apipe( - value: Coroutine[Any, Any, _A] | _A, - fn1: SyncOrAsyncCallable[_A, _B], - fn2: SyncOrAsyncCallable[_B, _C], - fn3: SyncOrAsyncCallable[_C, _D], - fn4: SyncOrAsyncCallable[_D, _E], +async def apipe[A, B, C, D, E]( + value: Coroutine[Any, Any, A] | A, + fn1: SyncOrAsyncCallable[A, B], + fn2: SyncOrAsyncCallable[B, C], + fn3: SyncOrAsyncCallable[C, D], + fn4: SyncOrAsyncCallable[D, E], /, -) -> _E: ... +) -> E: ... @overload -async def apipe( - value: Coroutine[Any, Any, _A] | _A, - fn1: SyncOrAsyncCallable[_A, _B], - fn2: SyncOrAsyncCallable[_B, _C], - fn3: SyncOrAsyncCallable[_C, _D], - fn4: SyncOrAsyncCallable[_D, _E], - fn5: SyncOrAsyncCallable[_E, _F], +async def apipe[A, B, C, D, E, F]( + value: Coroutine[Any, Any, A] | A, + fn1: SyncOrAsyncCallable[A, B], + fn2: SyncOrAsyncCallable[B, C], + fn3: SyncOrAsyncCallable[C, D], + fn4: SyncOrAsyncCallable[D, E], + fn5: SyncOrAsyncCallable[E, F], /, -) -> _F: ... +) -> F: ... @overload -async def apipe( - value: Coroutine[Any, Any, _A] | _A, - fn1: SyncOrAsyncCallable[_A, _B], - fn2: SyncOrAsyncCallable[_B, _C], - fn3: SyncOrAsyncCallable[_C, _D], - fn4: SyncOrAsyncCallable[_D, _E], - fn5: SyncOrAsyncCallable[_E, _F], - fn6: SyncOrAsyncCallable[_F, _G], +async def apipe[A, B, C, D, E, F, G]( + value: Coroutine[Any, Any, A] | A, + fn1: SyncOrAsyncCallable[A, B], + fn2: SyncOrAsyncCallable[B, C], + fn3: SyncOrAsyncCallable[C, D], + fn4: SyncOrAsyncCallable[D, E], + fn5: SyncOrAsyncCallable[E, F], + fn6: SyncOrAsyncCallable[F, G], /, -) -> _G: ... +) -> G: ... @overload -async def apipe( - value: Coroutine[Any, Any, _A] | _A, - fn1: SyncOrAsyncCallable[_A, _B], - fn2: SyncOrAsyncCallable[_B, _C], - fn3: SyncOrAsyncCallable[_C, _D], - fn4: SyncOrAsyncCallable[_D, _E], - fn5: SyncOrAsyncCallable[_E, _F], - fn6: SyncOrAsyncCallable[_F, _G], - fn7: SyncOrAsyncCallable[_G, _H], +async def apipe[A, B, C, D, E, F, G, H]( + value: Coroutine[Any, Any, A] | A, + fn1: SyncOrAsyncCallable[A, B], + fn2: SyncOrAsyncCallable[B, C], + fn3: SyncOrAsyncCallable[C, D], + fn4: SyncOrAsyncCallable[D, E], + fn5: SyncOrAsyncCallable[E, F], + fn6: SyncOrAsyncCallable[F, G], + fn7: SyncOrAsyncCallable[G, H], /, -) -> _H: ... +) -> H: ... @overload -async def apipe( - value: Coroutine[Any, Any, _A] | _A, - fn1: SyncOrAsyncCallable[_A, _B], - fn2: SyncOrAsyncCallable[_B, _C], - fn3: SyncOrAsyncCallable[_C, _D], - fn4: SyncOrAsyncCallable[_D, _E], - fn5: SyncOrAsyncCallable[_E, _F], - fn6: SyncOrAsyncCallable[_F, _G], - fn7: SyncOrAsyncCallable[_G, _H], - fn8: SyncOrAsyncCallable[_H, _T], +async def apipe[A, B, C, D, E, F, G, H, T]( + value: Coroutine[Any, Any, A] | A, + fn1: SyncOrAsyncCallable[A, B], + fn2: SyncOrAsyncCallable[B, C], + fn3: SyncOrAsyncCallable[C, D], + fn4: SyncOrAsyncCallable[D, E], + fn5: SyncOrAsyncCallable[E, F], + fn6: SyncOrAsyncCallable[F, G], + fn7: SyncOrAsyncCallable[G, H], + fn8: SyncOrAsyncCallable[H, T], /, -) -> _T: ... +) -> T: ... @overload -async def apipe( - value: Coroutine[Any, Any, _A] | _A, - fn1: SyncOrAsyncCallable[_A, _B], - fn2: SyncOrAsyncCallable[_B, _C], - fn3: SyncOrAsyncCallable[_C, _D], - fn4: SyncOrAsyncCallable[_D, _E], - fn5: SyncOrAsyncCallable[_E, _F], - fn6: SyncOrAsyncCallable[_F, _G], - fn7: SyncOrAsyncCallable[_G, _H], - fn8: SyncOrAsyncCallable[_H, _T], - fn9: SyncOrAsyncCallable[_T, _J], +async def apipe[A, B, C, D, E, F, G, H, T, J]( + value: Coroutine[Any, Any, A] | A, + fn1: SyncOrAsyncCallable[A, B], + fn2: SyncOrAsyncCallable[B, C], + fn3: SyncOrAsyncCallable[C, D], + fn4: SyncOrAsyncCallable[D, E], + fn5: SyncOrAsyncCallable[E, F], + fn6: SyncOrAsyncCallable[F, G], + fn7: SyncOrAsyncCallable[G, H], + fn8: SyncOrAsyncCallable[H, T], + fn9: SyncOrAsyncCallable[T, J], /, -) -> _J: ... +) -> J: ... async def apipe(value: Any, *functions: SyncOrAsyncCallable[Any, Any]) -> Any: diff --git a/expression/core/async_builder.py b/expression/core/async_builder.py index 5354d207..fd85fdd4 100644 --- a/expression/core/async_builder.py +++ b/expression/core/async_builder.py @@ -8,45 +8,38 @@ from abc import ABC from collections.abc import AsyncGenerator, Awaitable, Callable from functools import wraps -from typing import Any, Generic, TypeVar, cast - -from typing_extensions import ParamSpec +from typing import Any, cast from .error import EffectError -_T = TypeVar("_T") # The container item type -_M = TypeVar("_M") # for container type -_P = ParamSpec("_P") - - -class AsyncBuilderState(Generic[_T]): +class AsyncBuilderState[T]: """Encapsulates the state of an async builder computation.""" def __init__(self): self.is_done = False -class AsyncBuilder(Generic[_T, _M], ABC): # Corrected Generic definition +class AsyncBuilder[T, M](ABC): # Corrected Generic definition """Async effect builder.""" # Required methods async def bind( - self, xs: _M, fn: Callable[[_T], Awaitable[_M]] - ) -> _M: # Use concrete types for Callable input and output + self, xs: M, fn: Callable[[T], Awaitable[M]] + ) -> M: # Use concrete types for Callable input and output raise NotImplementedError("AsyncBuilder does not implement a `bind` method") - async def return_(self, x: _T) -> _M: + async def return_(self, x: T) -> M: raise NotImplementedError("AsyncBuilder does not implement a `return` method") - async def return_from(self, xs: _M) -> _M: + async def return_from(self, xs: M) -> M: raise NotImplementedError("AsyncBuilder does not implement a `return` from method") - async def combine(self, xs: _M, ys: _M) -> _M: + async def combine(self, xs: M, ys: M) -> M: """Used for combining multiple statements in the effect.""" raise NotImplementedError("AsyncBuilder does not implement a `combine` method") - async def zero(self) -> _M: + async def zero(self) -> M: """Zero effect. Called if the effect raises StopAsyncIteration without a value, i.e @@ -55,14 +48,14 @@ async def zero(self) -> _M: raise NotImplementedError("AsyncBuilder does not implement a `zero` method") # Optional methods for control flow - async def delay(self, fn: Callable[[], _M]) -> _M: + async def delay(self, fn: Callable[[], M]) -> M: """Delay the computation. Default implementation is to return the result of the function. """ return fn() - async def run(self, computation: _M) -> _M: + async def run(self, computation: M) -> M: """Run a computation. Default implementation is to return the computation as is. @@ -72,17 +65,17 @@ async def run(self, computation: _M) -> _M: # Internal implementation async def _send( self, - gen: AsyncGenerator[_T, Any], - state: AsyncBuilderState[_T], # Use AsyncBuilderState - value: _T, - ) -> _M: + gen: AsyncGenerator[T, Any], + state: AsyncBuilderState[T], # Use AsyncBuilderState + value: T, + ) -> M: try: yielded = await gen.asend(value) return await self.return_(yielded) except EffectError as error: # Effect errors (Nothing, Error, etc) short circuits state.is_done = True - return await self.return_from(cast("_M", error.args[0])) + return await self.return_from(cast("M", error.args[0])) except StopAsyncIteration: state.is_done = True raise @@ -90,13 +83,13 @@ async def _send( state.is_done = True raise - def __call__( + def __call__[**P]( self, fn: Callable[ - _P, - AsyncGenerator[_T, Any] | Awaitable[_T | None] | _T | None, + P, + AsyncGenerator[T, Any] | Awaitable[T | None] | T | None, ], - ) -> Callable[_P, Awaitable[_M]]: + ) -> Callable[P, Awaitable[M]]: """The builder decorator. A body without a `yield` statement is a plain async function. Its @@ -106,7 +99,7 @@ def __call__( """ @wraps(fn) - async def wrapper(*args: _P.args, **kw: _P.kwargs) -> _M: + async def wrapper(*args: P.args, **kw: P.kwargs) -> M: body = fn(*args, **kw) if not inspect.isasyncgen(body): @@ -114,21 +107,21 @@ async def wrapper(*args: _P.args, **kw: _P.kwargs) -> _M: # function. Treat its return value like a `return` statement: # a value maps to return_(value), a None return value maps # to zero(). - result_value: _T | None + result_value: T | None if inspect.iscoroutine(body): - result_value = await cast("Awaitable[_T]", body) + result_value = await cast("Awaitable[T]", body) else: - result_value = cast("_T | None", body) + result_value = cast("T | None", body) if result_value is None: return await self.run(await self.zero()) return await self.run(await self.return_(result_value)) - gen = cast("AsyncGenerator[_T, Any]", body) - state = AsyncBuilderState[_T]() # Initialize AsyncBuilderState - result: _M = await self.zero() # Initialize result - value: _M + gen = cast("AsyncGenerator[T, Any]", body) + state = AsyncBuilderState[T]() # Initialize AsyncBuilderState + result: M = await self.zero() # Initialize result + value: M - async def binder(value: Any) -> _M: + async def binder(value: Any) -> M: ret = await self._send(gen, state, value) # Pass state to _send return await self.delay(lambda: ret) # Delay every bind call diff --git a/expression/core/builder.py b/expression/core/builder.py index 10f8cb60..b6717b32 100644 --- a/expression/core/builder.py +++ b/expression/core/builder.py @@ -3,19 +3,12 @@ from collections.abc import Callable, Generator from dataclasses import dataclass from functools import wraps -from typing import Any, Generic, TypeVar, cast - -from typing_extensions import ParamSpec +from typing import Any, cast from .error import EffectError -_T = TypeVar("_T") # for value type -_M = TypeVar("_M") # for monadic type -_P = ParamSpec("_P") - - -class BuilderState(Generic[_T]): +class BuilderState[T]: """Legacy computation state, retained for import compatibility.""" def __init__(self) -> None: @@ -23,8 +16,8 @@ def __init__(self) -> None: @dataclass(frozen=True) -class _Produced(Generic[_M]): - value: _M +class _Produced[M]: + value: M is_terminal: bool = False @@ -33,7 +26,7 @@ class _Completed: pass -class Builder(Generic[_T, _M], ABC): +class Builder[T, M](ABC): """Eager generator effect builder. Each bind must invoke its continuation exactly once, synchronously. @@ -42,20 +35,20 @@ class Builder(Generic[_T, _M], ABC): """ # Required methods - def bind(self, xs: _M, fn: Callable[[_T], _M]) -> _M: + def bind(self, xs: M, fn: Callable[[T], M]) -> M: raise NotImplementedError("Builder does not implement a `bind` method") - def return_(self, x: _T) -> _M: + def return_(self, x: T) -> M: raise NotImplementedError("Builder does not implement a `return` method") - def return_from(self, xs: _M) -> _M: + def return_from(self, xs: M) -> M: raise NotImplementedError("Builder does not implement a `return` from method") - def combine(self, xs: _M, ys: _M) -> _M: + def combine(self, xs: M, ys: M) -> M: """Used for combining multiple statements in the effect.""" raise NotImplementedError("Builder does not implement a `combine` method") - def zero(self) -> _M: + def zero(self) -> M: """Zero effect. Called if the effect raises StopIteration without a value, i.e @@ -64,14 +57,14 @@ def zero(self) -> _M: raise NotImplementedError("Builder does not implement a `zero` method") # Optional methods for control flow - def delay(self, fn: Callable[[], _M]) -> _M: + def delay(self, fn: Callable[[], M]) -> M: """Delay the computation. Default implementation is to return the result of the function. """ return fn() - def run(self, computation: _M) -> _M: + def run(self, computation: M) -> M: """Run a computation. Default implementation is to return the computation as is. @@ -79,26 +72,26 @@ def run(self, computation: _M) -> _M: return computation # Internal implementation - def _send(self, gen: Generator[Any, Any, Any], value: Any) -> _Produced[_M] | _Completed: + def _send(self, gen: Generator[Any, Any, Any], value: Any) -> _Produced[M] | _Completed: # Only generator advancement may signal completion or effect failure. # Exceptions from builder hooks must propagate unchanged. try: yielded = gen.send(value) except EffectError as error: - return _Produced(self.return_from(cast("_M", error.args[0])), is_terminal=True) + return _Produced(self.return_from(cast("M", error.args[0])), is_terminal=True) except StopIteration as ex: if ex.value is None: return _Completed() return _Produced(self.return_(ex.value), is_terminal=True) return _Produced(self.return_(yielded)) - def _advance(self, gen: Generator[Any, Any, Any], current: _M) -> tuple[_M, _Produced[_M] | _Completed]: + def _advance(self, gen: Generator[Any, Any, Any], current: M) -> tuple[M, _Produced[M] | _Completed]: """Perform one bind while enforcing ownership of its continuation.""" active = True called = False - step: _Produced[_M] | _Completed = _Completed() + step: _Produced[M] | _Completed = _Completed() - def binder(sent: Any) -> _M: + def binder(sent: Any) -> M: nonlocal called, step if not active or called: raise RuntimeError("Builder requires a synchronous, single-use bind continuation") @@ -117,7 +110,7 @@ def binder(sent: Any) -> _M: raise RuntimeError("Builder.bind must invoke its continuation exactly once synchronously") return bound, step - def _evaluate_generator(self, gen: Generator[Any, Any, Any]) -> _M: + def _evaluate_generator(self, gen: Generator[Any, Any, Any]) -> M: """Accumulate eager steps without growing the Python call stack.""" initial = self._send(gen, None) if isinstance(initial, _Completed): @@ -133,20 +126,20 @@ def _evaluate_generator(self, gen: Generator[Any, Any, Any]) -> _M: terminal = step.is_terminal return result - def _run_generator(self, gen: Generator[Any, Any, Any]) -> _M: + def _run_generator(self, gen: Generator[Any, Any, Any]) -> M: """Own generator cleanup through evaluation and the final run hook.""" try: return self.run(self._evaluate_generator(gen)) finally: gen.close() - def __call__( + def __call__[**P]( self, fn: Callable[ - _P, - Generator[_T | None, _T, _T | None] | Generator[_T | None, None, _T | None] | _T | None, + P, + Generator[T | None, T, T | None] | Generator[T | None, None, T | None] | T | None, ], - ) -> Callable[_P, _M]: + ) -> Callable[P, M]: """The builder decorator. A body without a `yield` statement is a plain function. Its return @@ -155,14 +148,14 @@ def __call__( """ @wraps(fn) - def wrapper(*args: _P.args, **kw: _P.kwargs) -> _M: + def wrapper(*args: P.args, **kw: P.kwargs) -> M: body = fn(*args, **kw) if not inspect.isgenerator(body): # A body without a `yield` statement is a plain function. # Treat its return value like a `return` statement: a value # maps to return_(value), a None return value maps to zero(). - result_value = cast("_T | None", body) + result_value = cast("T | None", body) if result_value is None: return self.run(self.zero()) return self.run(self.return_(result_value)) diff --git a/expression/core/compose.py b/expression/core/compose.py index 8228ec37..85821a2a 100644 --- a/expression/core/compose.py +++ b/expression/core/compose.py @@ -1,116 +1,99 @@ from collections.abc import Callable from functools import reduce -from typing import Any, TypeVar, overload - -from typing_extensions import TypeVarTuple, Unpack - - -_A = TypeVar("_A") -_B = TypeVar("_B") -_C = TypeVar("_C") -_D = TypeVar("_D") -_E = TypeVar("_E") -_F = TypeVar("_F") -_G = TypeVar("_G") -_H = TypeVar("_H") -_T = TypeVar("_T") -_J = TypeVar("_J") - -_P = TypeVarTuple("_P") -_X = TypeVarTuple("_X") -_Y = TypeVarTuple("_Y") -_Z = TypeVarTuple("_Z") +from typing import Any, Unpack, overload @overload -def compose() -> Callable[[_A], _A]: ... +def compose[A]() -> Callable[[A], A]: ... @overload -def compose(__fn1: Callable[[_A], _B]) -> Callable[[_A], _B]: ... +def compose[B, A](__fn1: Callable[[A], B]) -> Callable[[A], B]: ... @overload -def compose(__fn1: Callable[[_A], _B], __fn2: Callable[[_B], _C]) -> Callable[[_A], _C]: ... +def compose[B, A, C](__fn1: Callable[[A], B], __fn2: Callable[[B], C]) -> Callable[[A], C]: ... @overload -def compose(__fn1: Callable[[_A], _B], __fn2: Callable[[_B], _C], __fn3: Callable[[_C], _D]) -> Callable[[_A], _D]: ... +def compose[B, A, C, D]( + __fn1: Callable[[A], B], __fn2: Callable[[B], C], __fn3: Callable[[C], D] +) -> Callable[[A], D]: ... @overload -def compose( - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], +def compose[B, A, C, D, E]( + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], /, -) -> Callable[[_A], _E]: ... +) -> Callable[[A], E]: ... @overload -def compose( - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], +def compose[B, A, C, D, E, F]( + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], /, -) -> Callable[[_A], _F]: ... +) -> Callable[[A], F]: ... @overload -def compose( - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], +def compose[B, A, C, D, E, F, G]( + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], /, -) -> Callable[[_A], _G]: ... +) -> Callable[[A], G]: ... @overload -def compose( - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], +def compose[B, A, C, D, E, F, G, H]( + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], /, -) -> Callable[[_A], _H]: ... +) -> Callable[[A], H]: ... @overload -def compose( - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], +def compose[B, A, C, D, E, F, G, H, T]( + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], /, -) -> Callable[[_A], _T]: ... +) -> Callable[[A], T]: ... @overload -def compose( - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], +def compose[B, A, C, D, E, F, G, H, T, J]( + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], /, -) -> Callable[[_A], _J]: ... +) -> Callable[[A], J]: ... def compose(*fns: Callable[[Any], Any]) -> Callable[[Any], Any]: @@ -146,32 +129,32 @@ def starcompose() -> Callable[[Any], Any]: ... @overload -def starcompose(fn1: Callable[[Unpack[_P]], _A], /) -> Callable[[Unpack[_P]], _A]: ... +def starcompose[A, *P](fn1: Callable[[Unpack[P]], A], /) -> Callable[[Unpack[P]], A]: ... @overload -def starcompose( - fn1: Callable[[Unpack[_P]], tuple[*_Y]], fn2: Callable[[Unpack[_Y]], _B], / -) -> Callable[[Unpack[_P]], _B]: ... +def starcompose[*P, *Y, B]( + fn1: Callable[[Unpack[P]], tuple[*Y]], fn2: Callable[[Unpack[Y]], B], / +) -> Callable[[Unpack[P]], B]: ... @overload -def starcompose( - fn1: Callable[[Unpack[_P]], tuple[*_Y]], - fn2: Callable[[Unpack[_Y]], tuple[*_Z]], - fn3: Callable[[Unpack[_Z]], _C], +def starcompose[*P, *Y, *Z, C]( + fn1: Callable[[Unpack[P]], tuple[*Y]], + fn2: Callable[[Unpack[Y]], tuple[*Z]], + fn3: Callable[[Unpack[Z]], C], /, -) -> Callable[[Unpack[_P]], _C]: ... +) -> Callable[[Unpack[P]], C]: ... @overload -def starcompose( - fn1: Callable[[Unpack[_P]], tuple[*_Y]], - fn2: Callable[[Unpack[_Y]], tuple[*_Z]], - fn3: Callable[[Unpack[_Z]], tuple[*_X]], - fn4: Callable[[Unpack[_X]], _D], +def starcompose[*P, *Y, *Z, *X, D]( + fn1: Callable[[Unpack[P]], tuple[*Y]], + fn2: Callable[[Unpack[Y]], tuple[*Z]], + fn3: Callable[[Unpack[Z]], tuple[*X]], + fn4: Callable[[Unpack[X]], D], /, -) -> Callable[[Unpack[_P]], _D]: ... +) -> Callable[[Unpack[P]], D]: ... def starcompose(*fns: Callable[..., Any]) -> Callable[..., Any]: diff --git a/expression/core/curry.py b/expression/core/curry.py index e6ccb1c1..782c53cf 100644 --- a/expression/core/curry.py +++ b/expression/core/curry.py @@ -1,16 +1,7 @@ import functools from collections.abc import Callable -from typing import Any, Concatenate, Literal, TypeVar, overload +from typing import Any, Concatenate, Literal, overload -from typing_extensions import ParamSpec - - -_P = ParamSpec("_P") -_A = TypeVar("_A") -_B = TypeVar("_B") -_C = TypeVar("_C") -_D = TypeVar("_D") -_E = TypeVar("_E") _Arity = Literal[0, 1, 2, 3, 4] @@ -25,42 +16,42 @@ def wrapper(*args_: Any, **kw: Any) -> Any: @overload -def curry(num_args: Literal[0]) -> Callable[[Callable[_P, _B]], Callable[_P, _B]]: ... +def curry[**P, B](num_args: Literal[0]) -> Callable[[Callable[P, B]], Callable[P, B]]: ... @overload -def curry( +def curry[B, A, **P]( num_args: Literal[1], -) -> Callable[[Callable[Concatenate[_A, _P], _B]], Callable[[_A], Callable[_P, _B]]]: ... +) -> Callable[[Callable[Concatenate[A, P], B]], Callable[[A], Callable[P, B]]]: ... @overload -def curry( +def curry[C, A, B, **P]( num_args: Literal[2], ) -> Callable[ - [Callable[Concatenate[_A, _B, _P], _C]], + [Callable[Concatenate[A, B, P], C]], Callable[ - [_A], + [A], Callable[ - [_B], - Callable[_P, _C], + [B], + Callable[P, C], ], ], ]: ... @overload -def curry( +def curry[D, A, B, C, **P]( num_args: Literal[3], ) -> Callable[ - [Callable[Concatenate[_A, _B, _C, _P], _D]], + [Callable[Concatenate[A, B, C, P], D]], Callable[ - [_A], + [A], Callable[ - [_B], + [B], Callable[ - [_C], - Callable[_P, _D], + [C], + Callable[P, D], ], ], ], @@ -68,17 +59,17 @@ def curry( @overload -def curry( +def curry[E, A, B, C, D, **P]( num_args: Literal[4], ) -> Callable[ - [Callable[Concatenate[_A, _B, _C, _D, _P], _E]], + [Callable[Concatenate[A, B, C, D, P], E]], Callable[ - [_A], + [A], Callable[ - [_B], + [B], Callable[ - [_C], - Callable[[_D], Callable[_P, _E]], + [C], + Callable[[D], Callable[P, E]], ], ], ], @@ -109,44 +100,44 @@ def wrapper(fun: Callable[..., Any]) -> Callable[..., Any]: @overload -def curry_flip( +def curry_flip[**P, A]( num_args: Literal[0], -) -> Callable[[Callable[_P, _A]], Callable[_P, _A]]: ... +) -> Callable[[Callable[P, A]], Callable[P, A]]: ... @overload -def curry_flip( +def curry_flip[**P, B, A]( num_args: Literal[1], -) -> Callable[[Callable[Concatenate[_A, _P], _B]], Callable[_P, Callable[[_A], _B]]]: ... +) -> Callable[[Callable[Concatenate[A, P], B]], Callable[P, Callable[[A], B]]]: ... @overload -def curry_flip( +def curry_flip[**P, C, A, B]( num_args: Literal[2], ) -> Callable[ - [Callable[Concatenate[_A, _B, _P], _C]], + [Callable[Concatenate[A, B, P], C]], Callable[ - _P, + P, Callable[ - [_A], - Callable[[_B], _C], + [A], + Callable[[B], C], ], ], ]: ... @overload -def curry_flip( +def curry_flip[**P, D, A, B, C]( num_args: Literal[3], ) -> Callable[ - [Callable[Concatenate[_A, _B, _C, _P], _D]], + [Callable[Concatenate[A, B, C, P], D]], Callable[ - _P, + P, Callable[ - [_A], + [A], Callable[ - [_B], - Callable[[_C], _D], + [B], + Callable[[C], D], ], ], ], @@ -154,17 +145,17 @@ def curry_flip( @overload -def curry_flip( +def curry_flip[**P, E, A, B, C, D]( num_args: Literal[4], ) -> Callable[ - [Callable[Concatenate[_A, _B, _C, _D, _P], _E]], + [Callable[Concatenate[A, B, C, D, P], E]], Callable[ - _P, + P, Callable[ - [_A], + [A], Callable[ - [_B], - Callable[[_C], Callable[[_D], _E]], + [B], + Callable[[C], Callable[[D], E]], ], ], ], @@ -205,12 +196,12 @@ def _wrap_curried(*curry_args: Any) -> Any: return _wrap_fun -def pipeable( - function: Callable[Concatenate[_A, _P], _B], +def pipeable[B, A, **P]( + function: Callable[Concatenate[A, P], B], /, - *args: _P.args, - **kwargs: _P.kwargs, -) -> Callable[[_A], _B]: + *args: P.args, + **kwargs: P.kwargs, +) -> Callable[[A], B]: """Partially apply a function's arguments after its pipeline value. Args: diff --git a/expression/core/fn.py b/expression/core/fn.py index 0f0038ed..33b0205d 100644 --- a/expression/core/fn.py +++ b/expression/core/fn.py @@ -2,31 +2,25 @@ import functools from collections.abc import Awaitable, Callable -from typing import Generic, TypeVar, cast +from typing import cast -from typing_extensions import ParamSpec - -_TResult = TypeVar("_TResult") -_P = ParamSpec("_P") - - -class TailCall(Generic[_P]): +class TailCall[**P]: """Returns a tail call. If a `tailrec` decorated function return a `TailCall` then the function will be called again with the new arguments provided. """ - def __init__(self, *args: _P.args, **kw: _P.kwargs): + def __init__(self, *args: P.args, **kw: P.kwargs): self.args = args self.kw = kw -TailCallResult = _TResult | TailCall[_P] +type TailCallResult[TResult, **P] = TResult | TailCall[P] -def tailrec(fn: Callable[_P, TailCallResult[_TResult, _P]]) -> Callable[_P, _TResult]: +def tailrec[**P, TResult](fn: Callable[P, TailCallResult[TResult, P]]) -> Callable[P, TResult]: """Tail call recursive function decorator. Can be used to create tail call recursive functions that will not @@ -34,9 +28,9 @@ def tailrec(fn: Callable[_P, TailCallResult[_TResult, _P]]) -> Callable[_P, _TRe of `TailCall` with the next arguments to be used for the next call. """ - def trampoline(bouncer: TailCallResult[_TResult, _P]) -> _TResult: + def trampoline(bouncer: TailCallResult[TResult, P]) -> TResult: while isinstance(bouncer, TailCall): - bouncer = cast(TailCall[_P], bouncer) + bouncer = cast(TailCall[P], bouncer) args, kw = bouncer.args, bouncer.kw bouncer = fn(*args, **kw) @@ -44,25 +38,27 @@ def trampoline(bouncer: TailCallResult[_TResult, _P]) -> _TResult: return bouncer @functools.wraps(fn) - def wrapper(*args: _P.args, **kw: _P.kwargs) -> _TResult: + def wrapper(*args: P.args, **kw: P.kwargs) -> TResult: return trampoline(fn(*args, **kw)) return wrapper -def tailrec_async(fn: Callable[_P, Awaitable[TailCallResult[_TResult, _P]]]) -> Callable[_P, Awaitable[_TResult]]: +def tailrec_async[**P, TResult]( + fn: Callable[P, Awaitable[TailCallResult[TResult, P]]], +) -> Callable[P, Awaitable[TResult]]: """Tail call recursive async function decorator.""" - async def trampoline(bouncer: TailCallResult[_TResult, _P]) -> _TResult: + async def trampoline(bouncer: TailCallResult[TResult, P]) -> TResult: while isinstance(bouncer, TailCall): - bouncer = cast(TailCall[_P], bouncer) + bouncer = cast(TailCall[P], bouncer) args, kw = bouncer.args, bouncer.kw bouncer = await fn(*args, **kw) return bouncer @functools.wraps(fn) - async def wrapper(*args: _P.args, **kw: _P.kwargs) -> _TResult: + async def wrapper(*args: P.args, **kw: P.kwargs) -> TResult: result = await fn(*args, **kw) return await trampoline(result) diff --git a/expression/core/mailbox.py b/expression/core/mailbox.py index cf774bee..938ed8f2 100644 --- a/expression/core/mailbox.py +++ b/expression/core/mailbox.py @@ -16,27 +16,21 @@ from collections.abc import AsyncGenerator, Awaitable, Callable from contextlib import asynccontextmanager from queue import Empty, SimpleQueue -from typing import Generic, TypeVar from expression.system import CancellationToken, ObjectDisposedException from .aiotools import _start_task # pyright: ignore[reportPrivateUsage] -_Msg = TypeVar("_Msg") -_Reply = TypeVar("_Reply") -_StartedMsg = TypeVar("_StartedMsg") - - -class AsyncReplyChannel(Generic[_Reply]): - def __init__(self, fn: Callable[[_Reply], None]) -> None: +class AsyncReplyChannel[Reply]: + def __init__(self, fn: Callable[[Reply], None]) -> None: self.fn = fn - def reply(self, r: _Reply) -> None: + def reply(self, r: Reply) -> None: self.fn(r) -class MailboxProcessor(Generic[_Msg]): +class MailboxProcessor[Msg]: """A FIFO mailbox with one reader and thread-safe posting and replies. Construct and receive on the same running event loop. Timeouts use seconds, @@ -44,7 +38,7 @@ class MailboxProcessor(Generic[_Msg]): """ def __init__(self, cancellation_token: CancellationToken | None = None) -> None: - self.messages: SimpleQueue[_Msg] = SimpleQueue() + self.messages: SimpleQueue[Msg] = SimpleQueue() self.token = cancellation_token or CancellationToken.none() self.loop = asyncio.get_running_loop() # Presence owns the reader slot, even after the signal completes. @@ -59,29 +53,29 @@ def _wake(self) -> None: if self._receive_signal is not None and not self._receive_signal.done(): self._receive_signal.set_result(None) - def post(self, msg: _Msg) -> None: + def post(self, msg: Msg) -> None: """Post a message synchronously, including from another thread.""" if self.loop.is_closed(): raise RuntimeError("Mailbox event loop is closed") self.messages.put(msg) self.loop.call_soon_threadsafe(self._wake) - def post_and_async_reply( - self, build_message: Callable[[AsyncReplyChannel[_Reply]], _Msg], timeout: float | None = None - ) -> Awaitable[_Reply]: + def post_and_async_reply[Reply]( + self, build_message: Callable[[AsyncReplyChannel[Reply]], Msg], timeout: float | None = None + ) -> Awaitable[Reply]: """Post immediately and await a reply, optionally timing out in seconds. The first reply wins, including None. Replies may come from any thread; late replies after cancellation or timeout are ignored. """ self._check_loop() - future: asyncio.Future[_Reply] = self.loop.create_future() + future: asyncio.Future[Reply] = self.loop.create_future() - def complete(value: _Reply) -> None: + def complete(value: Reply) -> None: if not future.done(): future.set_result(value) - def reply(value: _Reply) -> None: + def reply(value: Reply) -> None: if not self.loop.is_closed(): self.loop.call_soon_threadsafe(complete, value) @@ -90,7 +84,7 @@ def reply(value: _Reply) -> None: return future return asyncio.wait_for(future, timeout) - async def receive(self, timeout: float | None = None) -> _Msg: + async def receive(self, timeout: float | None = None) -> Msg: """Receive the next message; raise TimeoutError after timeout seconds. Only one receive may be active. Cancellation or timeout releases the @@ -146,12 +140,12 @@ async def wait(self) -> None: await asyncio.shield(self._task) @staticmethod - def start( - body: Callable[[MailboxProcessor[_StartedMsg]], Awaitable[None]], + def start[StartedMsg]( + body: Callable[[MailboxProcessor[StartedMsg]], Awaitable[None]], cancellation_token: CancellationToken | None = None, - ) -> MailboxProcessor[_StartedMsg]: + ) -> MailboxProcessor[StartedMsg]: """Start a body whose completion can be observed with wait().""" - mbox: MailboxProcessor[_StartedMsg] = MailboxProcessor(cancellation_token) + mbox: MailboxProcessor[StartedMsg] = MailboxProcessor(cancellation_token) mbox._task = _start_task(body(mbox), cancellation_token) return mbox diff --git a/expression/core/misc.py b/expression/core/misc.py index 86987347..8dddeeb8 100644 --- a/expression/core/misc.py +++ b/expression/core/misc.py @@ -1,17 +1,8 @@ from collections.abc import Callable -from typing import Any, TypeVar +from typing import Any -from typing_extensions import TypeVarTuple - -_A = TypeVar("_A") -_B = TypeVar("_B") -_P = TypeVarTuple("_P") -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") - - -def identity(value: _A) -> _A: +def identity[A](value: A) -> A: """Identity function. Returns value given as argument. @@ -19,30 +10,30 @@ def identity(value: _A) -> _A: return value -def starid(*value: *_P) -> tuple[*_P]: +def starid[*P](*value: *P) -> tuple[*P]: return value -def flip(fn: Callable[[_A, _B], _TResult]) -> Callable[[_B, _A], _TResult]: +def flip[TResult, A, B](fn: Callable[[A, B], TResult]) -> Callable[[B, A], TResult]: """Flips the arguments for a function taking two arguments. Example: >>> fn(a, b) == flip(fn)(b, a) """ - def _flip(b: _B, a: _A) -> Any: + def _flip(b: B, a: A) -> Any: return fn(a, b) return _flip -def snd(value: tuple[Any, _TSource]) -> _TSource: +def snd[TSource](value: tuple[Any, TSource]) -> TSource: """Return second argument of the tuple.""" _, b = value return b -def fst(value: tuple[_TSource, Any]) -> _TSource: +def fst[TSource](value: tuple[TSource, Any]) -> TSource: """Return first argument of the tuple.""" a, _ = value return a diff --git a/expression/core/option.py b/expression/core/option.py index 1c6e44c7..b142edb4 100644 --- a/expression/core/option.py +++ b/expression/core/option.py @@ -19,11 +19,12 @@ Never, TypeAlias, TypeGuard, + Unpack, final, overload, ) -from typing_extensions import TypeVar, TypeVarTuple, Unpack +from typing_extensions import TypeVar from ._serialization import encode from ._union_schema import UnionSchema @@ -39,19 +40,12 @@ _TSourceOut = TypeVar("_TSourceOut", covariant=True) -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") -_TError = TypeVar("_TError") _TEmpty = TypeVar("_TEmpty", default=Never) -_T1 = TypeVar("_T1") -_T2 = TypeVar("_T2") -_TOption = TypeVar("_TOption", bound="Some[object] | Nothing") -_P = TypeVarTuple("_P") @final @case -class Some(PipeMixin, Generic[_TSourceOut]): +class Some(PipeMixin, Generic[_TSourceOut]): # noqa: UP046 - Preserve explicit covariance. """An optional value that is present, including when its payload is None.""" some: _TSourceOut @@ -65,23 +59,23 @@ def default_with(self, getter: Callable[[], object]) -> _TSourceOut: """Return the present value without evaluating the fallback.""" return self.some - def map(self, mapper: Callable[[_TSourceOut], _TResult]) -> Some[_TResult]: + def map[TResult](self, mapper: Callable[[_TSourceOut], TResult]) -> Some[TResult]: """Transform the present value.""" return Some(mapper(self.some)) - def map2(self, mapper: Callable[[_TSourceOut, _T2], _TResult], other: Option[_T2]) -> Option[_TResult]: + def map2[TResult, T2](self, mapper: Callable[[_TSourceOut, T2], TResult], other: Option[T2]) -> Option[TResult]: """Transform two present values, or return Nothing.""" return other.map(lambda value: mapper(self.some, value)) - def apply(self, function: Option[Callable[[_TSourceOut], _TResult]]) -> Option[_TResult]: + def apply[TResult](self, function: Option[Callable[[_TSourceOut], TResult]]) -> Option[TResult]: """Apply an optional function to the present value.""" return function.map(lambda mapper: mapper(self.some)) - def starmap(self: Some[tuple[*_P]], mapper: Callable[[Unpack[_P]], _TResult]) -> Some[_TResult]: + def starmap[*P, TResult](self: Some[tuple[*P]], mapper: Callable[[Unpack[P]], TResult]) -> Some[TResult]: """Apply a function to the unpacked tuple payload.""" return Some(mapper(*self.some)) - def bind(self, mapper: Callable[[_TSourceOut], _TOption]) -> _TOption: + def bind[TOption: Some[object] | Nothing](self, mapper: Callable[[_TSourceOut], TOption]) -> TOption: """Apply a function returning another option.""" return mapper(self.some) @@ -168,11 +162,11 @@ def __new__(cls) -> Nothing: cls._instance = object.__new__(cls) return cls._instance - def default_value(self, value: _TResult) -> _TResult: + def default_value[TResult](self, value: TResult) -> TResult: """Return the fallback value.""" return value - def default_with(self, getter: Callable[[], _TResult]) -> _TResult: + def default_with[TResult](self, getter: Callable[[], TResult]) -> TResult: """Evaluate the fallback factory.""" return getter() @@ -180,7 +174,7 @@ def map(self, mapper: Callable[[Never], object]) -> Nothing: """Keep the empty option without evaluating the mapper.""" return self - def map2(self, mapper: Callable[[Never, _T2], object], other: Option[_T2]) -> Nothing: + def map2[T2](self, mapper: Callable[[Never, T2], object], other: Option[T2]) -> Nothing: """Keep the empty option without evaluating the mapper.""" return self @@ -192,15 +186,15 @@ def starmap(self, mapper: Callable[..., object]) -> Nothing: """Keep the empty option without evaluating the mapper.""" return self - def bind(self, mapper: Callable[[Never], _TOption]) -> Nothing: + def bind[TOption: Some[object] | Nothing](self, mapper: Callable[[Never], TOption]) -> Nothing: """Keep the empty option without evaluating the continuation.""" return self - def or_else(self, if_none: _TOption) -> _TOption: + def or_else[TOption: Some[object] | Nothing](self, if_none: TOption) -> TOption: """Return the fallback option.""" return if_none - def or_else_with(self, if_none: Callable[[], _TOption]) -> _TOption: + def or_else_with[TOption: Some[object] | Nothing](self, if_none: Callable[[], TOption]) -> TOption: """Evaluate the fallback option factory.""" return if_none() @@ -230,13 +224,13 @@ def to_optional(self) -> None: """Return None.""" return None - def to_result(self, error: _TError) -> Error[_TError]: + def to_result[TError](self, error: TError) -> Error[TError]: """Return the supplied error as a failed result.""" from expression.core.result import Error return Error(error) - def to_result_with(self, error: Callable[[], _TError]) -> Error[_TError]: + def to_result_with[TError](self, error: Callable[[], TError]) -> Error[TError]: """Evaluate the error factory and return a failed result.""" from expression.core.result import Error @@ -267,52 +261,55 @@ def __str__(self) -> str: """The canonical empty option, available without a constructor call.""" -Option: TypeAlias = Annotated[Some[_TSourceOut] | Nothing, UnionSchema(canonical_values=(NOTHING,))] +# Keep an evaluated alias for runtime union introspection and Pydantic schemas. +Option: TypeAlias = Annotated[Some[_TSourceOut] | Nothing, UnionSchema(canonical_values=(NOTHING,))] # noqa: UP040 -def bind(mapper: Callable[[_TSource], _TOption]) -> Callable[[Option[_TSource]], _TOption | Nothing]: +def bind[TOption: Some[object] | Nothing, TSource]( + mapper: Callable[[TSource], TOption], +) -> Callable[[Option[TSource]], TOption | Nothing]: """Apply an option-returning function to a present value.""" - def apply(source: Option[_TSource]) -> _TOption | Nothing: + def apply(source: Option[TSource]) -> TOption | Nothing: return source.bind(mapper) return apply -class _DefaultValue(Generic[_T1]): - def __init__(self, value: _T1) -> None: +class _DefaultValue[T1]: + def __init__(self, value: T1) -> None: self._value = value @overload - def __call__(self, source: Some[_TSource]) -> _TSource: ... + def __call__[TSource](self, source: Some[TSource]) -> TSource: ... @overload - def __call__(self, source: Nothing) -> _T1: ... + def __call__(self, source: Nothing) -> T1: ... - def __call__(self, source: Option[_TSource]) -> _TSource | _T1: + def __call__[TSource](self, source: Option[TSource]) -> TSource | T1: return source.default_value(self._value) -def default_value(value: _T1) -> _DefaultValue[_T1]: +def default_value[T1](value: T1) -> _DefaultValue[T1]: """Return an operation selecting the payload or a fallback value.""" return _DefaultValue(value) -class _DefaultWith(Generic[_T1]): - def __init__(self, getter: Callable[[], _T1]) -> None: +class _DefaultWith[T1]: + def __init__(self, getter: Callable[[], T1]) -> None: self._getter = getter @overload - def __call__(self, source: Some[_TSource]) -> _TSource: ... + def __call__[TSource](self, source: Some[TSource]) -> TSource: ... @overload - def __call__(self, source: Nothing) -> _T1: ... + def __call__(self, source: Nothing) -> T1: ... - def __call__(self, source: Option[_TSource]) -> _TSource | _T1: + def __call__[TSource](self, source: Option[TSource]) -> TSource | T1: return source.default_with(self._getter) -def default_with(getter: Callable[[], _T1]) -> _DefaultWith[_T1]: +def default_with[T1](getter: Callable[[], T1]) -> _DefaultWith[T1]: """Return an operation selecting the payload or evaluating a fallback.""" return _DefaultWith(getter) @@ -322,18 +319,18 @@ def is_none(option: Option[object]) -> TypeGuard[Nothing]: return isinstance(option, Nothing) -def is_some(option: Option[_TSource]) -> TypeGuard[Some[_TSource]]: +def is_some[TSource](option: Option[TSource]) -> TypeGuard[Some[TSource]]: """Narrow an option to its present case.""" return isinstance(option, Some) @curry_flip(1) -def map(option: Option[_TSource], mapper: Callable[[_TSource], _TResult]) -> Option[_TResult]: +def map[TSource, TResult](option: Option[TSource], mapper: Callable[[TSource], TResult]) -> Option[TResult]: return option.map(mapper) @curry_flip(2) -def map2(opt1: Option[_T1], opt2: Option[_T2], mapper: Callable[[_T1, _T2], _TResult]) -> Option[_TResult]: +def map2[T1, T2, TResult](opt1: Option[T1], opt2: Option[T2], mapper: Callable[[T1, T2], TResult]) -> Option[TResult]: return opt1.map2(mapper, opt2) @@ -342,24 +339,28 @@ def apply(function: Nothing) -> Callable[[Option[object]], Nothing]: ... @overload -def apply(function: Option[Callable[[_TSource], _TResult]]) -> Callable[[Option[_TSource]], Option[_TResult]]: ... +def apply[TResult, TSource]( + function: Option[Callable[[TSource], TResult]], +) -> Callable[[Option[TSource]], Option[TResult]]: ... -def apply(function: Option[Callable[[_TSource], _TResult]]) -> Callable[[Option[_TSource]], Option[_TResult]]: +def apply[TResult, TSource]( + function: Option[Callable[[TSource], TResult]], +) -> Callable[[Option[TSource]], Option[TResult]]: """Apply an optional function to an optional value.""" - def apply(source: Option[_TSource]) -> Option[_TResult]: + def apply(source: Option[TSource]) -> Option[TResult]: return source.apply(function) return apply @curry_flip(1) -def starmap(option: Option[tuple[*_P]], mapper: Callable[[Unpack[_P]], _TResult]) -> Option[_TResult]: +def starmap[*P, TResult](option: Option[tuple[*P]], mapper: Callable[[Unpack[P]], TResult]) -> Option[TResult]: return option.starmap(mapper) -def or_else(option: Option[_TSource], if_none: Option[_TResult]) -> Option[_TSource | _TResult]: +def or_else[TSource, TResult](option: Option[TSource], if_none: Option[TResult]) -> Option[TSource | TResult]: """Return the first present option, allowing a different fallback type.""" return option.or_else(if_none) @@ -375,14 +376,14 @@ def to_seq(option: Option[_TEmpty]) -> Seq[_TEmpty]: @overload -def to_optional(value: Some[_TSource]) -> _TSource: ... +def to_optional[TSource](value: Some[TSource]) -> TSource: ... @overload def to_optional(value: Nothing) -> None: ... -def to_optional(value: Option[_TSource]) -> _TSource | None: +def to_optional[TSource](value: Option[TSource]) -> TSource | None: """Erase the option wrapper, mapping Nothing to None.""" return value.to_optional() @@ -392,10 +393,10 @@ def of_optional(value: None) -> Nothing: ... @overload -def of_optional(value: _TSource | None) -> Option[_TSource]: ... +def of_optional[TSource](value: TSource | None) -> Option[TSource]: ... -def of_optional(value: _TSource | None) -> Option[_TSource]: +def of_optional[TSource](value: TSource | None) -> Option[TSource]: """Wrap a value, treating None as absence.""" return NOTHING if value is None else Some(value) @@ -405,23 +406,23 @@ def of_obj(value: None) -> Nothing: ... @overload -def of_obj(value: _TSource | None) -> Option[_TSource]: ... +def of_obj[TSource](value: TSource | None) -> Option[TSource]: ... -def of_obj(value: _TSource | None) -> Option[_TSource]: +def of_obj[TSource](value: TSource | None) -> Option[TSource]: """Wrap a value, treating None as absence.""" return of_optional(value) @overload -def of_result(result: Ok[_TSource]) -> Some[_TSource]: ... +def of_result[TSource](result: Ok[TSource]) -> Some[TSource]: ... @overload def of_result(result: Error[object]) -> Nothing: ... -def of_result(result: Result[_TSource, object]) -> Option[_TSource]: +def of_result[TSource](result: Result[TSource, object]) -> Option[TSource]: """Keep the successful result payload, or return Nothing.""" from expression.core.result import Ok @@ -429,26 +430,26 @@ def of_result(result: Result[_TSource, object]) -> Option[_TSource]: @overload -def to_result(value: Some[_TSource], error: object) -> Ok[_TSource]: ... +def to_result[TSource](value: Some[TSource], error: object) -> Ok[TSource]: ... @overload -def to_result(value: Nothing, error: _TError) -> Error[_TError]: ... +def to_result[TError](value: Nothing, error: TError) -> Error[TError]: ... -def to_result(value: Option[_TSource], error: _TError) -> Result[_TSource, _TError]: +def to_result[TSource, TError](value: Option[TSource], error: TError) -> Result[TSource, TError]: return value.to_result(error) @overload -def to_result_with(value: Some[_TSource], error: Callable[[], object]) -> Ok[_TSource]: ... +def to_result_with[TSource](value: Some[TSource], error: Callable[[], object]) -> Ok[TSource]: ... @overload -def to_result_with(value: Nothing, error: Callable[[], _TError]) -> Error[_TError]: ... +def to_result_with[TError](value: Nothing, error: Callable[[], TError]) -> Error[TError]: ... -def to_result_with(value: Option[_TSource], error: Callable[[], _TError]) -> Result[_TSource, _TError]: +def to_result_with[TSource, TError](value: Option[TSource], error: Callable[[], TError]) -> Result[TSource, TError]: return value.to_result_with(error) @@ -457,7 +458,7 @@ def model_dump(value: Option[object]) -> builtins.dict[str, object]: return value.dict() -def default_arg(value: Option[_TSource], default_value: _T1) -> _TSource | _T1: +def default_arg[TSource, T1](value: Option[TSource], default_value: T1) -> TSource | T1: """Return the payload or an uncurried fallback value.""" return value.default_value(default_value) diff --git a/expression/core/pipe.py b/expression/core/pipe.py index 72ec362f..f9094448 100644 --- a/expression/core/pipe.py +++ b/expression/core/pipe.py @@ -13,280 +13,253 @@ """ from collections.abc import Callable -from typing import Any, TypeVar, cast, overload - -from typing_extensions import TypeVarTuple, Unpack +from typing import Any, Unpack, cast, overload from .compose import compose, starcompose from .misc import starid -_A = TypeVar("_A") -_B = TypeVar("_B") -_C = TypeVar("_C") -_D = TypeVar("_D") -_E = TypeVar("_E") -_F = TypeVar("_F") -_G = TypeVar("_G") -_H = TypeVar("_H") -_T = TypeVar("_T") -_J = TypeVar("_J") -_I = TypeVar("_I") -_K1 = TypeVar("_K1") -_L = TypeVar("_L") -_M = TypeVar("_M") -_N = TypeVar("_N") -_O = TypeVar("_O") -_P1 = TypeVar("_P1") -_P = TypeVarTuple("_P") -_Q = TypeVarTuple("_Q") -_X = TypeVarTuple("_X") -_Y = TypeVarTuple("_Y") -_Z = TypeVarTuple("_Z") -_K = TypeVarTuple("_K") - - @overload -def pipe(value: _A, /) -> _A: ... +def pipe[A](value: A, /) -> A: ... @overload -def pipe(value: _A, fn1: Callable[[_A], _B], /) -> _B: ... +def pipe[A, B](value: A, fn1: Callable[[A], B], /) -> B: ... @overload -def pipe(value: _A, fn1: Callable[[_A], _B], fn2: Callable[[_B], _C], /) -> _C: ... +def pipe[A, B, C](value: A, fn1: Callable[[A], B], fn2: Callable[[B], C], /) -> C: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], +def pipe[A, B, C, D]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], /, -) -> _D: ... +) -> D: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], +def pipe[A, B, C, D, E]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], /, -) -> _E: ... +) -> E: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], +def pipe[A, B, C, D, E, F]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], /, -) -> _F: ... +) -> F: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], +def pipe[A, B, C, D, E, F, G]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], /, -) -> _G: ... +) -> G: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], +def pipe[A, B, C, D, E, F, G, H]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], /, -) -> _H: ... +) -> H: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], +def pipe[A, B, C, D, E, F, G, H, T]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], /, -) -> _T: ... +) -> T: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], +def pipe[A, B, C, D, E, F, G, H, T, J]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], /, -) -> _J: ... +) -> J: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], +def pipe[A, B, C, D, E, F, G, H, T, J, I]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], /, -) -> _I: ... +) -> I: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], +def pipe[A, B, C, D, E, F, G, H, T, J, I, K1]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], /, -) -> _K1: ... +) -> K1: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], - fn12: Callable[[_K1], _L], +def pipe[A, B, C, D, E, F, G, H, T, J, I, K1, L]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], + fn12: Callable[[K1], L], /, -) -> _L: ... +) -> L: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], - fn12: Callable[[_K1], _L], - fn13: Callable[[_L], _M], +def pipe[A, B, C, D, E, F, G, H, T, J, I, K1, L, M]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], + fn12: Callable[[K1], L], + fn13: Callable[[L], M], /, -) -> _M: ... +) -> M: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], - fn12: Callable[[_K1], _L], - fn13: Callable[[_L], _M], - fn14: Callable[[_M], _N], +def pipe[A, B, C, D, E, F, G, H, T, J, I, K1, L, M, N]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], + fn12: Callable[[K1], L], + fn13: Callable[[L], M], + fn14: Callable[[M], N], /, -) -> _N: ... +) -> N: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], - fn12: Callable[[_K1], _L], - fn13: Callable[[_L], _M], - fn14: Callable[[_M], _N], - fn15: Callable[[_N], _O], +def pipe[A, B, C, D, E, F, G, H, T, J, I, K1, L, M, N, O]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], + fn12: Callable[[K1], L], + fn13: Callable[[L], M], + fn14: Callable[[M], N], + fn15: Callable[[N], O], /, -) -> _O: ... +) -> O: ... @overload -def pipe( - value: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], - fn12: Callable[[_K1], _L], - fn13: Callable[[_L], _M], - fn14: Callable[[_M], _N], - fn15: Callable[[_N], _O], - fn16: Callable[[_O], _P1], +def pipe[A, B, C, D, E, F, G, H, T, J, I, K1, L, M, N, O, P1]( + value: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], + fn12: Callable[[K1], L], + fn13: Callable[[L], M], + fn14: Callable[[M], N], + fn15: Callable[[N], O], + fn16: Callable[[O], P1], /, -) -> _P1: ... +) -> P1: ... def pipe(value: Any, *fns: Callable[[Any], Any]) -> Any: @@ -304,30 +277,30 @@ def pipe(value: Any, *fns: Callable[[Any], Any]) -> Any: @overload -def pipe2(values: tuple[_A, _B], /) -> tuple[_A, _B]: ... +def pipe2[A, B](values: tuple[A, B], /) -> tuple[A, B]: ... @overload -def pipe2(values: tuple[_A, _B], fn1: Callable[[_A], Callable[[_B], _C]], /) -> _C: ... +def pipe2[A, B, C](values: tuple[A, B], fn1: Callable[[A], Callable[[B], C]], /) -> C: ... @overload -def pipe2( - values: tuple[_A, _B], - fn1: Callable[[_A], Callable[[_B], _C]], - fn2: Callable[[_C], _D], +def pipe2[A, B, C, D]( + values: tuple[A, B], + fn1: Callable[[A], Callable[[B], C]], + fn2: Callable[[C], D], /, -) -> _D: ... +) -> D: ... @overload -def pipe2( - values: tuple[_A, _B], - fn1: Callable[[_A], Callable[[_B], _C]], - fn2: Callable[[_C], _D], - fn3: Callable[[_D], _E], +def pipe2[A, B, C, D, E]( + values: tuple[A, B], + fn1: Callable[[A], Callable[[B], C]], + fn2: Callable[[C], D], + fn3: Callable[[D], E], /, -) -> _E: ... +) -> E: ... def pipe2(values: Any, /, *fns: Any) -> Any: @@ -339,57 +312,57 @@ def pipe3(values: Any, /, *fns: Any) -> Any: @overload -def starpipe(args: tuple[*_P], fn1: Callable[[Unpack[_P]], _B], /) -> _B: ... +def starpipe[*P, B](args: tuple[*P], fn1: Callable[[Unpack[P]], B], /) -> B: ... @overload -def starpipe(args: tuple[*_P], fn1: Callable[[Unpack[_P]], tuple[*_Q]], fn2: Callable[[*_Q], _B], /) -> _B: ... +def starpipe[*P, *Q, B](args: tuple[*P], fn1: Callable[[Unpack[P]], tuple[*Q]], fn2: Callable[[*Q], B], /) -> B: ... @overload -def starpipe( - args: tuple[*_P], - fn1: Callable[[Unpack[_P]], tuple[*_Q]], - fn2: Callable[[Unpack[_Q]], tuple[*_X]], - fn3: Callable[[Unpack[_X]], _B], +def starpipe[*P, *Q, *X, B]( + args: tuple[*P], + fn1: Callable[[Unpack[P]], tuple[*Q]], + fn2: Callable[[Unpack[Q]], tuple[*X]], + fn3: Callable[[Unpack[X]], B], /, -) -> _B: ... +) -> B: ... @overload -def starpipe( - args: tuple[*_P], - fn1: Callable[[Unpack[_P]], tuple[*_Q]], - fn2: Callable[[Unpack[_Q]], tuple[*_X]], - fn3: Callable[[Unpack[_X]], tuple[*_Y]], - fn4: Callable[[Unpack[_Y]], _B], +def starpipe[*P, *Q, *X, *Y, B]( + args: tuple[*P], + fn1: Callable[[Unpack[P]], tuple[*Q]], + fn2: Callable[[Unpack[Q]], tuple[*X]], + fn3: Callable[[Unpack[X]], tuple[*Y]], + fn4: Callable[[Unpack[Y]], B], /, -) -> _B: ... +) -> B: ... @overload -def starpipe( - args: tuple[*_P], - fn1: Callable[[Unpack[_P]], tuple[*_Q]], - fn2: Callable[[Unpack[_Q]], tuple[*_X]], - fn3: Callable[[Unpack[_X]], tuple[*_Y]], - fn4: Callable[[Unpack[_Y]], tuple[*_Z]], - fn5: Callable[[Unpack[_Z]], _B], +def starpipe[*P, *Q, *X, *Y, *Z, B]( + args: tuple[*P], + fn1: Callable[[Unpack[P]], tuple[*Q]], + fn2: Callable[[Unpack[Q]], tuple[*X]], + fn3: Callable[[Unpack[X]], tuple[*Y]], + fn4: Callable[[Unpack[Y]], tuple[*Z]], + fn5: Callable[[Unpack[Z]], B], /, -) -> _B: ... +) -> B: ... @overload -def starpipe( - args: tuple[*_P], - fn1: Callable[[Unpack[_P]], tuple[*_Q]], - fn2: Callable[[Unpack[_Q]], tuple[*_X]], - fn3: Callable[[Unpack[_X]], tuple[*_Y]], - fn4: Callable[[Unpack[_Y]], tuple[*_Z]], - fn5: Callable[[Unpack[_Z]], tuple[*_K]], - fn6: Callable[[Unpack[_K]], _B], +def starpipe[*P, *Q, *X, *Y, *Z, *K, B]( + args: tuple[*P], + fn1: Callable[[Unpack[P]], tuple[*Q]], + fn2: Callable[[Unpack[Q]], tuple[*X]], + fn3: Callable[[Unpack[X]], tuple[*Y]], + fn4: Callable[[Unpack[Y]], tuple[*Z]], + fn5: Callable[[Unpack[Z]], tuple[*K]], + fn6: Callable[[Unpack[K]], B], /, -) -> _B: ... +) -> B: ... def starpipe(args: Any, /, *fns: Callable[..., Any]) -> Any: @@ -417,221 +390,221 @@ class PipeMixin: __slots__ = () @overload - def pipe(self: _A, fn1: Callable[[_A], _B], /) -> _B: ... + def pipe[A, B](self: A, fn1: Callable[[A], B], /) -> B: ... @overload - def pipe(self: _A, fn1: Callable[[_A], _B], fn2: Callable[[_B], _C], /) -> _C: ... + def pipe[A, B, C](self: A, fn1: Callable[[A], B], fn2: Callable[[B], C], /) -> C: ... @overload - def pipe(self: _A, fn1: Callable[[_A], _B], fn2: Callable[[_B], _C], fn3: Callable[[_C], _D], /) -> _D: ... + def pipe[A, B, C, D](self: A, fn1: Callable[[A], B], fn2: Callable[[B], C], fn3: Callable[[C], D], /) -> D: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], + def pipe[A, B, C, D, E]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], /, - ) -> _E: ... + ) -> E: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], + def pipe[A, B, C, D, E, F]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], /, - ) -> _F: ... + ) -> F: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], + def pipe[A, B, C, D, E, F, G]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], /, - ) -> _G: ... + ) -> G: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], + def pipe[A, B, C, D, E, F, G, H]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], /, - ) -> _H: ... + ) -> H: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], + def pipe[A, B, C, D, E, F, G, H, T]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], /, - ) -> _T: ... + ) -> T: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], + def pipe[A, B, C, D, E, F, G, H, T, J]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], /, - ) -> _J: ... + ) -> J: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], + def pipe[A, B, C, D, E, F, G, H, T, J, I]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], /, - ) -> _I: ... + ) -> I: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], + def pipe[A, B, C, D, E, F, G, H, T, J, I, K1]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], /, - ) -> _K1: ... + ) -> K1: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], - fn12: Callable[[_K1], _L], + def pipe[A, B, C, D, E, F, G, H, T, J, I, K1, L]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], + fn12: Callable[[K1], L], /, - ) -> _L: ... + ) -> L: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], - fn12: Callable[[_K1], _L], - fn13: Callable[[_L], _M], + def pipe[A, B, C, D, E, F, G, H, T, J, I, K1, L, M]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], + fn12: Callable[[K1], L], + fn13: Callable[[L], M], /, - ) -> _M: ... + ) -> M: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], - fn12: Callable[[_K1], _L], - fn13: Callable[[_L], _M], - fn14: Callable[[_M], _N], + def pipe[A, B, C, D, E, F, G, H, T, J, I, K1, L, M, N]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], + fn12: Callable[[K1], L], + fn13: Callable[[L], M], + fn14: Callable[[M], N], /, - ) -> _N: ... + ) -> N: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], - fn12: Callable[[_K1], _L], - fn13: Callable[[_L], _M], - fn14: Callable[[_M], _N], - fn15: Callable[[_N], _O], + def pipe[A, B, C, D, E, F, G, H, T, J, I, K1, L, M, N, O]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], + fn12: Callable[[K1], L], + fn13: Callable[[L], M], + fn14: Callable[[M], N], + fn15: Callable[[N], O], /, - ) -> _O: ... + ) -> O: ... @overload - def pipe( - self: _A, - fn1: Callable[[_A], _B], - fn2: Callable[[_B], _C], - fn3: Callable[[_C], _D], - fn4: Callable[[_D], _E], - fn5: Callable[[_E], _F], - fn6: Callable[[_F], _G], - fn7: Callable[[_G], _H], - fn8: Callable[[_H], _T], - fn9: Callable[[_T], _J], - fn10: Callable[[_J], _I], - fn11: Callable[[_I], _K1], - fn12: Callable[[_K1], _L], - fn13: Callable[[_L], _M], - fn14: Callable[[_M], _N], - fn15: Callable[[_N], _O], - fn16: Callable[[_O], _P1], + def pipe[A, B, C, D, E, F, G, H, T, J, I, K1, L, M, N, O, P1]( + self: A, + fn1: Callable[[A], B], + fn2: Callable[[B], C], + fn3: Callable[[C], D], + fn4: Callable[[D], E], + fn5: Callable[[E], F], + fn6: Callable[[F], G], + fn7: Callable[[G], H], + fn8: Callable[[H], T], + fn9: Callable[[T], J], + fn10: Callable[[J], I], + fn11: Callable[[I], K1], + fn12: Callable[[K1], L], + fn13: Callable[[L], M], + fn14: Callable[[M], N], + fn15: Callable[[N], O], + fn16: Callable[[O], P1], /, - ) -> _P1: ... + ) -> P1: ... def pipe(self, *args: Any) -> Any: """Pipe the left side object through the given functions.""" diff --git a/expression/core/result.py b/expression/core/result.py index ce1a36d7..83ee4524 100644 --- a/expression/core/result.py +++ b/expression/core/result.py @@ -47,14 +47,11 @@ _U = TypeVar("_U", default=Never) _F = TypeVar("_F", default=Never) _R = TypeVar("_R", bound="Ok[object] | Error[object]", default=Never) -_Input = TypeVar("_Input", contravariant=True) -_Output = TypeVar("_Output", covariant=True) -_Failure = TypeVar("_Failure", covariant=True) @final @case -class Ok(PipeMixin, Generic[_T]): +class Ok(PipeMixin, Generic[_T]): # noqa: UP046 - Python 3.12 cannot express type parameter defaults. """A successful result containing a value.""" ok: _T @@ -141,7 +138,7 @@ def __str__(self) -> str: @final @case -class Error(PipeMixin, Generic[_E]): +class Error(PipeMixin, Generic[_E]): # noqa: UP046 - Python 3.12 cannot express type parameter defaults. """A failed result containing an error.""" error: _E @@ -229,7 +226,8 @@ def __str__(self) -> str: return f"Error {self.error}" -Result: TypeAlias = TaggedUnion[Ok[_T] | Error[_E]] +# Keep an evaluated alias for runtime union introspection and Pydantic schemas. +Result: TypeAlias = TaggedUnion[Ok[_T] | Error[_E]] # noqa: UP040 # Case-specific callable overloads preserve the untouched channel when a pipe @@ -290,12 +288,12 @@ def map(mapper: Callable[[_A], _U]) -> _Map[_A, _U]: return _Map(mapper) -class _ResultOperation(Protocol[_Input, _Output, _Failure]): +class _ResultOperation[Input, Output, Failure](Protocol): @overload - def __call__(self, source: Ok[_Input], /) -> Result[_Output, _Failure]: ... + def __call__(self, source: Ok[Input], /) -> Result[Output, Failure]: ... @overload - def __call__(self, source: Error[_E], /) -> Error[_E] | Error[_Failure]: ... + def __call__(self, source: Error[_E], /) -> Error[_E] | Error[Failure]: ... class _Map2Ok(_ResultOperation[_B, _U, Never], Generic[_A, _B, _U]): @@ -313,7 +311,7 @@ def __call__(self, other: Result[_B, _F]) -> Result[_U, _F]: return other.map(lambda value: self._mapper(self._value, value)) -class _Map2Error(_ResultOperation[object, Never, _E], Generic[_E]): +class _Map2Error(_ResultOperation[object, Never, _E], Generic[_E]): # noqa: UP046 - Python 3.12 cannot express type parameter defaults. def __init__(self, source: Error[_E]) -> None: self._source = source diff --git a/expression/core/tagged_union.py b/expression/core/tagged_union.py index d69f7823..17e5c41e 100644 --- a/expression/core/tagged_union.py +++ b/expression/core/tagged_union.py @@ -30,16 +30,14 @@ from ._union_schema import UnionSchema -_T = TypeVar("_T") - - class _TaggedCase(Protocol): @property def tag(self) -> str: ... _Case = TypeVar("_Case", bound=_TaggedCase) -TaggedUnion: TypeAlias = Annotated[_Case, UnionSchema()] +# Keep an evaluated alias for runtime union introspection and Pydantic schemas. +TaggedUnion: TypeAlias = Annotated[_Case, UnionSchema()] # noqa: UP040 def tag(*, init: Literal[False] = False, repr: bool = False) -> Any: @@ -54,17 +52,17 @@ def tag(*, init: Literal[False] = False, repr: bool = False) -> Any: @overload -def case(_cls: type[_T], /, *, repr: bool = True, kw_only: bool = False) -> type[_T]: ... +def case[T](_cls: type[T], /, *, repr: bool = True, kw_only: bool = False) -> type[T]: ... @overload -def case(*, repr: bool = True, kw_only: bool = False) -> Callable[[type[_T]], type[_T]]: ... +def case[T](*, repr: bool = True, kw_only: bool = False) -> Callable[[type[T]], type[T]]: ... @dataclass_transform(frozen_default=True, field_specifiers=(tag, field)) -def case( - _cls: type[_T] | None = None, /, *, repr: bool = True, kw_only: bool = False -) -> type[_T] | Callable[[type[_T]], type[_T]]: +def case[T]( + _cls: type[T] | None = None, /, *, repr: bool = True, kw_only: bool = False +) -> type[T] | Callable[[type[T]], type[T]]: """Create a frozen case dataclass with runtime subclass rejection. Apply ``@final`` as well for static subclass rejection. Cases have ordinary @@ -73,10 +71,10 @@ def case( ordinary values rather than automatically interned singletons. """ - def transform(cls: type[_T]) -> type[_T]: + def transform(cls: type[T]) -> type[T]: return apply(cls, _declaration_namespace()) - def apply(cls: type[_T], namespace: dict[str, object]) -> type[_T]: + def apply(cls: type[T], namespace: dict[str, object]) -> type[T]: if is_dataclass(cls): raise TypeError("@case requires a new class without a dataclass or case base") if "__init__" in vars(cls): diff --git a/expression/core/try_.py b/expression/core/try_.py index af7a4aaa..5d76faf4 100644 --- a/expression/core/try_.py +++ b/expression/core/try_.py @@ -1,15 +1,12 @@ """Result specialized to exception errors, with convenience constructors.""" -from typing import TypeAlias, TypeVar - from .result import Error, Ok, Result -_T = TypeVar("_T") -Try: TypeAlias = Result[_T, Exception] +type Try[T] = Result[T, Exception] -def Success(value: _T) -> Ok[_T]: +def Success[T](value: T) -> Ok[T]: """Construct a successful Try value.""" return Ok(value) diff --git a/expression/core/typing.py b/expression/core/typing.py index 0d9f6071..169f6a15 100644 --- a/expression/core/typing.py +++ b/expression/core/typing.py @@ -2,13 +2,7 @@ from abc import abstractmethod from collections.abc import Iterable -from typing import Any, Protocol, TypeVar, get_origin - - -_T_co = TypeVar("_T_co", covariant=True) - -_Base = TypeVar("_Base") -_Derived = TypeVar("_Derived") +from typing import Any, Protocol, get_origin class SupportsLessThan(Protocol): @@ -37,11 +31,11 @@ def __gt__(self, __other: Any) -> bool: raise NotImplementedError -class SupportsMatch(Protocol[_T_co]): +class SupportsMatch[T_co](Protocol): """Pattern matching protocol.""" @abstractmethod - def __match__(self, pattern: Any) -> Iterable[_T_co]: + def __match__(self, pattern: Any) -> Iterable[T_co]: """Match pattern with value. Return a singleton iterable item (e.g `[ value ]`) if pattern @@ -58,7 +52,7 @@ class ModelField: def validate(self, value: Any, values: dict[str, str], loc: str) -> tuple[Any, Any]: ... -def upcast(type: type[_Base], expr: _Base) -> _Base: +def upcast[Base](type: type[Base], expr: Base) -> Base: """Upcast expression from a `Derived` to `Base`. Note: F# `:>` or `upcast`. @@ -66,7 +60,7 @@ def upcast(type: type[_Base], expr: _Base) -> _Base: return expr -def downcast(type: type[_Derived], expr: Any) -> _Derived: +def downcast[Derived](type: type[Derived], expr: Any) -> Derived: """Downcast expression `Derived` to `Base`. Checks at compile time that the type of expression Base is a @@ -79,7 +73,7 @@ def downcast(type: type[_Derived], expr: Any) -> _Derived: return expr -def try_downcast(type_: type[_Derived], expr: Any) -> _Derived | None: +def try_downcast[Derived](type_: type[Derived], expr: Any) -> Derived | None: """Downcast expression `Base` to `Derived`. Check that the `Derived` type is a supertype of `Base`. @@ -89,7 +83,7 @@ def try_downcast(type_: type[_Derived], expr: Any) -> _Derived | None: Returns: None if `Derived` is not a supertype of `Base`. """ - origin: type[_Derived] | None = get_origin(type_) or type_ + origin: type[Derived] | None = get_origin(type_) or type_ if origin is not None and isinstance(expr, origin): return expr diff --git a/expression/effect/async_option.py b/expression/effect/async_option.py index 690007ca..6f83a313 100644 --- a/expression/effect/async_option.py +++ b/expression/effect/async_option.py @@ -6,29 +6,24 @@ """ from collections.abc import AsyncGenerator, Awaitable, Callable -from typing import Any, ParamSpec, TypeVar +from typing import Any from expression.core import NOTHING, Option, Some from expression.core.async_builder import AsyncBuilder -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") -_P = ParamSpec("_P") - - -class AsyncOptionBuilder(AsyncBuilder[_TSource, Option[Any]]): +class AsyncOptionBuilder[TSource](AsyncBuilder[TSource, Option[Any]]): """AsyncOption builder. The AsyncOption builder allows for composing asynchronous operations that may return an optional value, using the Option type. """ - async def bind( + async def bind[TResult]( self, - xs: Option[_TSource], - fn: Callable[[Any], Awaitable[Option[_TResult]]], - ) -> Option[_TResult]: + xs: Option[TSource], + fn: Callable[[Any], Awaitable[Option[TResult]]], + ) -> Option[TResult]: """Bind a function to an async option value. In F# computation expressions, this corresponds to ``let!`` and enables @@ -47,7 +42,7 @@ async def bind( case _: return NOTHING - async def return_(self, x: _TSource) -> Option[_TSource]: + async def return_(self, x: TSource) -> Option[TSource]: """Wrap a value in an async option. In F# computation expressions, this corresponds to ``return`` and lifts @@ -61,7 +56,7 @@ async def return_(self, x: _TSource) -> Option[_TSource]: """ return Some(x) - async def return_from(self, xs: Option[_TSource]) -> Option[_TSource]: + async def return_from(self, xs: Option[TSource]) -> Option[TSource]: """Return an async option value directly. In F# computation expressions, this corresponds to ``return!`` and allows @@ -75,7 +70,7 @@ async def return_from(self, xs: Option[_TSource]) -> Option[_TSource]: """ return xs - async def combine(self, xs: Option[_TSource], ys: Option[_TSource]) -> Option[_TSource]: + async def combine(self, xs: Option[TSource], ys: Option[TSource]) -> Option[TSource]: """Combine two async option computations. In F# computation expressions, this enables sequencing multiple @@ -105,31 +100,31 @@ async def zero(self) -> Option[Any]: """ return NOTHING - async def delay(self, fn: Callable[[], Option[_TSource]]) -> Option[_TSource]: + async def delay(self, fn: Callable[[], Option[TSource]]) -> Option[TSource]: """Delay the computation. Default implementation is to return the result of the function. """ return fn() - async def run(self, computation: Option[_TSource]) -> Option[_TSource]: + async def run(self, computation: Option[TSource]) -> Option[TSource]: """Run a computation. Default implementation is to return the computation as is. """ return computation - def __call__( + def __call__[**P]( self, fn: Callable[ - _P, - AsyncGenerator[_TSource, _TSource] - | AsyncGenerator[_TSource, None] - | Awaitable[_TSource | None] - | _TSource + P, + AsyncGenerator[TSource, TSource] + | AsyncGenerator[TSource, None] + | Awaitable[TSource | None] + | TSource | None, ], - ) -> Callable[_P, Awaitable[Option[_TSource]]]: + ) -> Callable[P, Awaitable[Option[TSource]]]: """The builder decorator.""" return super().__call__(fn) diff --git a/expression/effect/async_result.py b/expression/effect/async_result.py index 8db9e3e0..b90b765e 100644 --- a/expression/effect/async_result.py +++ b/expression/effect/async_result.py @@ -6,30 +6,24 @@ """ from collections.abc import AsyncGenerator, Awaitable, Callable -from typing import Any, ParamSpec, TypeVar +from typing import Any from expression.core import Error, Ok, Result from expression.core.async_builder import AsyncBuilder -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") -_TError = TypeVar("_TError") -_P = ParamSpec("_P") - - -class AsyncResultBuilder(AsyncBuilder[_TSource, Result[Any, _TError]]): +class AsyncResultBuilder[TSource, TError](AsyncBuilder[TSource, Result[Any, TError]]): """AsyncResult builder. The AsyncResult builder allows for composing asynchronous operations that may fail, using the Result type. """ - async def bind( + async def bind[TResult]( self, - xs: Result[_TSource, _TError], - fn: Callable[[Any], Awaitable[Result[_TResult, _TError]]], - ) -> Result[_TResult, _TError]: + xs: Result[TSource, TError], + fn: Callable[[Any], Awaitable[Result[TResult, TError]]], + ) -> Result[TResult, TError]: """Bind a function to an async result value. In F# computation expressions, this corresponds to ``let!`` and enables @@ -48,7 +42,7 @@ async def bind( case Error(error): return Error(error) - async def return_(self, x: _TSource) -> Result[_TSource, _TError]: + async def return_(self, x: TSource) -> Result[TSource, TError]: """Wrap a value in an async result. In F# computation expressions, this corresponds to ``return`` and lifts @@ -62,7 +56,7 @@ async def return_(self, x: _TSource) -> Result[_TSource, _TError]: """ return Ok(x) - async def return_from(self, xs: Result[_TSource, _TError]) -> Result[_TSource, _TError]: + async def return_from(self, xs: Result[TSource, TError]) -> Result[TSource, TError]: """Return an async result value directly. In F# computation expressions, this corresponds to ``return!`` and allows @@ -76,7 +70,7 @@ async def return_from(self, xs: Result[_TSource, _TError]) -> Result[_TSource, _ """ return xs - async def combine(self, xs: Result[_TSource, _TError], ys: Result[_TSource, _TError]) -> Result[_TSource, _TError]: + async def combine(self, xs: Result[TSource, TError], ys: Result[TSource, TError]) -> Result[TSource, TError]: """Combine two async result computations. In F# computation expressions, this enables sequencing multiple @@ -95,7 +89,7 @@ async def combine(self, xs: Result[_TSource, _TError], ys: Result[_TSource, _TEr case Error(error): return Error(error) - async def zero(self) -> Result[Any, _TError]: + async def zero(self) -> Result[Any, TError]: """Return the zero value for async results. In F# computation expressions, this is used when no value is returned, @@ -106,31 +100,31 @@ async def zero(self) -> Result[Any, _TError]: """ return Ok(None) - async def delay(self, fn: Callable[[], Result[_TSource, _TError]]) -> Result[_TSource, _TError]: + async def delay(self, fn: Callable[[], Result[TSource, TError]]) -> Result[TSource, TError]: """Delay the computation. Default implementation is to return the result of the function. """ return fn() - async def run(self, computation: Result[_TSource, _TError]) -> Result[_TSource, _TError]: + async def run(self, computation: Result[TSource, TError]) -> Result[TSource, TError]: """Run a computation. Default implementation is to return the computation as is. """ return computation - def __call__( + def __call__[**P]( self, fn: Callable[ - _P, - AsyncGenerator[_TSource, _TSource] - | AsyncGenerator[_TSource, None] - | Awaitable[_TSource | None] - | _TSource + P, + AsyncGenerator[TSource, TSource] + | AsyncGenerator[TSource, None] + | Awaitable[TSource | None] + | TSource | None, ], - ) -> Callable[_P, Awaitable[Result[_TSource, _TError]]]: + ) -> Callable[P, Awaitable[Result[TSource, TError]]]: """The builder decorator.""" return super().__call__(fn) @@ -139,7 +133,7 @@ def __call__( async_result: AsyncResultBuilder[Any, Any] = AsyncResultBuilder() -class AsyncTryBuilder(AsyncResultBuilder[_TSource, Exception]): +class AsyncTryBuilder[TSource](AsyncResultBuilder[TSource, Exception]): """AsyncTry builder. The AsyncTry builder allows for composing asynchronous operations that diff --git a/expression/effect/option.py b/expression/effect/option.py index a3d6cc79..75028c81 100644 --- a/expression/effect/option.py +++ b/expression/effect/option.py @@ -1,18 +1,11 @@ from collections.abc import Callable, Generator -from typing import Any, TypeVar - -from typing_extensions import ParamSpec +from typing import Any from expression.core import NOTHING, Builder, Option, Some, option -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") -_P = ParamSpec("_P") - - -class OptionBuilder(Builder[_TSource, Option[Any]]): - def bind(self, xs: Option[_TSource], fn: Callable[[_TSource], Option[_TResult]]) -> Option[_TResult]: +class OptionBuilder[TSource](Builder[TSource, Option[Any]]): + def bind[TResult](self, xs: Option[TSource], fn: Callable[[TSource], Option[TResult]]) -> Option[TResult]: """Bind a function to an option value. In F# computation expressions, this corresponds to let! and enables @@ -27,7 +20,7 @@ def bind(self, xs: Option[_TSource], fn: Callable[[_TSource], Option[_TResult]]) """ return option.bind(fn)(xs) - def return_(self, x: _TSource) -> Option[_TSource]: + def return_(self, x: TSource) -> Option[TSource]: """Wrap a value in an option. In F# computation expressions, this corresponds to return and lifts @@ -41,7 +34,7 @@ def return_(self, x: _TSource) -> Option[_TSource]: """ return Some(x) - def return_from(self, xs: Option[_TSource]) -> Option[_TSource]: + def return_from(self, xs: Option[TSource]) -> Option[TSource]: """Return an option value directly. In F# computation expressions, this corresponds to return! and allows @@ -55,7 +48,7 @@ def return_from(self, xs: Option[_TSource]) -> Option[_TSource]: """ return xs - def combine(self, xs: Option[_TSource], ys: Option[_TSource]) -> Option[_TSource]: + def combine(self, xs: Option[TSource], ys: Option[TSource]) -> Option[TSource]: """Combine two option computations. In F# computation expressions, this enables sequencing multiple @@ -70,7 +63,7 @@ def combine(self, xs: Option[_TSource], ys: Option[_TSource]) -> Option[_TSource """ return xs.bind(lambda _: ys) - def zero(self) -> Option[_TSource]: + def zero(self) -> Option[TSource]: """Return the zero value for options. In F# computation expressions, this is used when no value is returned, @@ -81,7 +74,7 @@ def zero(self) -> Option[_TSource]: """ return NOTHING - def delay(self, fn: Callable[[], Option[_TSource]]) -> Option[_TSource]: + def delay(self, fn: Callable[[], Option[TSource]]) -> Option[TSource]: """Delay an option computation. In F# computation expressions, delay ensures proper sequencing of effects @@ -95,16 +88,16 @@ def delay(self, fn: Callable[[], Option[_TSource]]) -> Option[_TSource]: """ return fn() - def __call__( + def __call__[**P]( self, # Ignored self parameter fn: Callable[ - _P, - Generator[_TSource | None, _TSource, _TSource | None] - | Generator[_TSource | None, None, _TSource | None] - | _TSource + P, + Generator[TSource | None, TSource, TSource | None] + | Generator[TSource | None, None, TSource | None] + | TSource | None, ], - ) -> Callable[_P, Option[_TSource]]: + ) -> Callable[P, Option[TSource]]: return super().__call__(fn) diff --git a/expression/effect/result.py b/expression/effect/result.py index 2e83b854..fe3f3e8b 100644 --- a/expression/effect/result.py +++ b/expression/effect/result.py @@ -1,23 +1,15 @@ from collections.abc import Callable, Generator -from typing import Any, TypeVar - -from typing_extensions import ParamSpec +from typing import Any from expression.core import Builder, Ok, Result -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") -_TError = TypeVar("_TError") -_P = ParamSpec("_P") - - -class ResultBuilder(Builder[_TSource, Result[Any, _TError]]): - def bind( +class ResultBuilder[TSource, TError](Builder[TSource, Result[Any, TError]]): + def bind[TResult]( self, - xs: Result[_TSource, _TError], - fn: Callable[[Any], Result[_TResult, _TError]], - ) -> Result[_TResult, _TError]: + xs: Result[TSource, TError], + fn: Callable[[Any], Result[TResult, TError]], + ) -> Result[TResult, TError]: """Bind a function to a result value. In F# computation expressions, this corresponds to ``let!`` and enables @@ -32,7 +24,7 @@ def bind( """ return xs.bind(fn) - def return_(self, x: _TSource) -> Result[_TSource, _TError]: # Use Any for return_ type + def return_(self, x: TSource) -> Result[TSource, TError]: # Use Any for return_ type """Wrap a value in a result. In F# computation expressions, this corresponds to ``return`` and lifts @@ -46,7 +38,7 @@ def return_(self, x: _TSource) -> Result[_TSource, _TError]: # Use Any for retu """ return Ok(x) - def return_from(self, xs: Result[_TSource, _TError]) -> Result[_TSource, _TError]: + def return_from(self, xs: Result[TSource, TError]) -> Result[TSource, TError]: """Return a result value directly. In F# computation expressions, this corresponds to ``return!`` and allows @@ -60,7 +52,7 @@ def return_from(self, xs: Result[_TSource, _TError]) -> Result[_TSource, _TError """ return xs - def combine(self, xs: Result[_TSource, _TError], ys: Result[_TSource, _TError]) -> Result[_TSource, _TError]: + def combine(self, xs: Result[TSource, TError], ys: Result[TSource, TError]) -> Result[TSource, TError]: """Combine two result computations. In F# computation expressions, this enables sequencing multiple @@ -75,7 +67,7 @@ def combine(self, xs: Result[_TSource, _TError], ys: Result[_TSource, _TError]) """ return xs.bind(lambda _: ys) - def zero(self) -> Result[Any, _TError]: # Use Any for zero return type + def zero(self) -> Result[Any, TError]: # Use Any for zero return type """Return the zero value for results. In F# computation expressions, this is used when no value is returned, @@ -86,20 +78,20 @@ def zero(self) -> Result[Any, _TError]: # Use Any for zero return type """ return Ok(None) - def __call__( + def __call__[**P]( self, # Ignored self parameter fn: Callable[ - _P, - Generator[_TSource | None, _TSource, _TSource | None] - | Generator[_TSource | None, None, _TSource | None] - | _TSource + P, + Generator[TSource | None, TSource, TSource | None] + | Generator[TSource | None, None, TSource | None] + | TSource | None, ], - ) -> Callable[_P, Result[_TSource, _TError]]: + ) -> Callable[P, Result[TSource, TError]]: return super().__call__(fn) -class TryBuilder(ResultBuilder[_TSource, Exception]): ... +class TryBuilder[TSource](ResultBuilder[TSource, Exception]): ... __all__ = ["ResultBuilder", "TryBuilder"] diff --git a/expression/effect/seq.py b/expression/effect/seq.py index 7bf3105e..5f1224cc 100644 --- a/expression/effect/seq.py +++ b/expression/effect/seq.py @@ -1,16 +1,12 @@ from collections.abc import Callable, Generator, Iterable -from typing import Any, TypeVar +from typing import Any from expression.collections import seq from expression.core import Builder -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") - - -class SeqBuilder(Builder[_TSource, Iterable[Any]]): - def bind(self, xs: Iterable[_TSource], fn: Callable[[_TSource], Iterable[_TResult]]) -> Iterable[_TResult]: +class SeqBuilder[TSource](Builder[TSource, Iterable[Any]]): + def bind[TResult](self, xs: Iterable[TSource], fn: Callable[[TSource], Iterable[TResult]]) -> Iterable[TResult]: """Bind a function to a sequence value. In F# computation expressions, this corresponds to let! and enables @@ -26,7 +22,7 @@ def bind(self, xs: Iterable[_TSource], fn: Callable[[_TSource], Iterable[_TResul # We do this eagerly to have progress in the sequence return [y for x in xs for y in fn(x)] - def return_(self, x: _TSource) -> Iterable[_TSource]: + def return_(self, x: TSource) -> Iterable[TSource]: """Wrap a value in a sequence. Args: @@ -37,7 +33,7 @@ def return_(self, x: _TSource) -> Iterable[_TSource]: """ return seq.singleton(x) - def return_from(self, xs: Iterable[_TSource]) -> Iterable[_TSource]: + def return_from(self, xs: Iterable[TSource]) -> Iterable[TSource]: """Return a sequence value directly. Args: @@ -48,7 +44,7 @@ def return_from(self, xs: Iterable[_TSource]) -> Iterable[_TSource]: """ return xs - def combine(self, xs: Iterable[_TSource], ys: Iterable[_TSource]) -> Iterable[_TSource]: + def combine(self, xs: Iterable[TSource], ys: Iterable[TSource]) -> Iterable[TSource]: """Combine two sequence computations. Args: @@ -60,7 +56,7 @@ def combine(self, xs: Iterable[_TSource], ys: Iterable[_TSource]) -> Iterable[_T """ return seq.concat(xs, ys) - def zero(self) -> Iterable[_TSource]: + def zero(self) -> Iterable[TSource]: """Return the zero value for sequences. Returns: @@ -68,7 +64,7 @@ def zero(self) -> Iterable[_TSource]: """ return seq.empty - def delay(self, fn: Callable[[], Iterable[_TSource]]) -> Iterable[_TSource]: + def delay(self, fn: Callable[[], Iterable[TSource]]) -> Iterable[TSource]: """Delay the computation. Returns a sequence that is built from the given delayed specification of a @@ -83,7 +79,7 @@ def delay(self, fn: Callable[[], Iterable[_TSource]]) -> Iterable[_TSource]: """ return fn() - def run(self, computation: Iterable[_TSource]) -> Iterable[_TSource]: + def run(self, computation: Iterable[TSource]) -> Iterable[TSource]: """Run a computation. In Python, the return value should be included in the sequence @@ -102,12 +98,12 @@ def __call__( self, fn: Callable[ ..., - Generator[_TSource | None, _TSource, _TSource | None] - | Generator[_TSource | None, None, _TSource | None] - | _TSource + Generator[TSource | None, TSource, TSource | None] + | Generator[TSource | None, None, TSource | None] + | TSource | None, ], - ) -> Callable[..., Iterable[_TSource]]: + ) -> Callable[..., Iterable[TSource]]: return super().__call__(fn) diff --git a/expression/extra/async_result/async_result.py b/expression/extra/async_result/async_result.py index 696d0f86..395286a0 100644 --- a/expression/extra/async_result/async_result.py +++ b/expression/extra/async_result/async_result.py @@ -1,21 +1,16 @@ from collections.abc import Awaitable, Callable, Coroutine -from typing import Any, TypeVar +from typing import Any from expression import Result from expression.effect.async_result import async_result -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") -_TError = TypeVar("_TError") - - -def bind( - mapper: Callable[[_TSource], Awaitable[Result[_TResult, _TError]]], -) -> Callable[[Result[_TSource, _TError]], Coroutine[Any, Any, Result[_TResult, _TError]]]: +def bind[TSource, TResult, TError]( + mapper: Callable[[TSource], Awaitable[Result[TResult, TError]]], +) -> Callable[[Result[TSource, TError]], Coroutine[Any, Any, Result[TResult, TError]]]: """Apply an asynchronous mapper to Ok, preserving Error without calling it.""" - async def wrapped(result: Result[_TSource, _TError]) -> Result[_TResult, _TError]: + async def wrapped(result: Result[TSource, TError]) -> Result[TResult, TError]: return await async_result.bind(result, mapper) return wrapped diff --git a/expression/extra/option/pipeline.py b/expression/extra/option/pipeline.py index a1bd135f..47fb85fd 100644 --- a/expression/extra/option/pipeline.py +++ b/expression/extra/option/pipeline.py @@ -1,68 +1,58 @@ from collections.abc import Callable from functools import reduce -from typing import Any, TypeVar, overload +from typing import Any, overload from expression.core import Option, Some -_A = TypeVar("_A") -_B = TypeVar("_B") -_C = TypeVar("_C") -_D = TypeVar("_D") -_E = TypeVar("_E") -_F = TypeVar("_F") -_G = TypeVar("_G") -_TError = TypeVar("_TError") - - @overload -def pipeline() -> Callable[[_A], Option[_A]]: ... +def pipeline[A]() -> Callable[[A], Option[A]]: ... @overload -def pipeline(__fn: Callable[[_A], Option[_B]]) -> Callable[[_A], Option[_B]]: ... +def pipeline[A, B](__fn: Callable[[A], Option[B]]) -> Callable[[A], Option[B]]: ... @overload -def pipeline(__fn1: Callable[[_A], Option[_B]], __fn2: Callable[[_B], Option[_C]]) -> Callable[[_A], Option[_C]]: ... +def pipeline[A, B, C](__fn1: Callable[[A], Option[B]], __fn2: Callable[[B], Option[C]]) -> Callable[[A], Option[C]]: ... @overload -def pipeline( - __fn1: Callable[[_A], Option[_B]], - __fn2: Callable[[_B], Option[_C]], - __fn3: Callable[[_C], Option[_D]], -) -> Callable[[_A], Option[_D]]: ... +def pipeline[A, B, C, D]( + __fn1: Callable[[A], Option[B]], + __fn2: Callable[[B], Option[C]], + __fn3: Callable[[C], Option[D]], +) -> Callable[[A], Option[D]]: ... @overload -def pipeline( - __fn1: Callable[[_A], Option[_B]], - __fn2: Callable[[_B], Option[_C]], - __fn3: Callable[[_C], Option[_D]], - __fn4: Callable[[_D], Option[_E]], -) -> Callable[[_A], Option[_E]]: ... +def pipeline[A, B, C, D, E]( + __fn1: Callable[[A], Option[B]], + __fn2: Callable[[B], Option[C]], + __fn3: Callable[[C], Option[D]], + __fn4: Callable[[D], Option[E]], +) -> Callable[[A], Option[E]]: ... @overload -def pipeline( - __fn1: Callable[[_A], Option[_B]], - __fn2: Callable[[_B], Option[_C]], - __fn3: Callable[[_C], Option[_D]], - __fn4: Callable[[_D], Option[_E]], - __fn5: Callable[[_E], Option[_F]], -) -> Callable[[_A], Option[_F]]: ... +def pipeline[A, B, C, D, E, F]( + __fn1: Callable[[A], Option[B]], + __fn2: Callable[[B], Option[C]], + __fn3: Callable[[C], Option[D]], + __fn4: Callable[[D], Option[E]], + __fn5: Callable[[E], Option[F]], +) -> Callable[[A], Option[F]]: ... @overload -def pipeline( - __fn1: Callable[[_A], Option[_B]], - __fn2: Callable[[_B], Option[_C]], - __fn3: Callable[[_C], Option[_D]], - __fn4: Callable[[_D], Option[_E]], - __fn5: Callable[[_E], Option[_F]], - __fn6: Callable[[_F], Option[_G]], -) -> Callable[[_A], Option[_G]]: ... +def pipeline[A, B, C, D, E, F, G]( + __fn1: Callable[[A], Option[B]], + __fn2: Callable[[B], Option[C]], + __fn3: Callable[[C], Option[D]], + __fn4: Callable[[D], Option[E]], + __fn5: Callable[[E], Option[F]], + __fn6: Callable[[F], Option[G]], +) -> Callable[[A], Option[G]]: ... def pipeline(*fns: Callable[[Any], Option[Any]]) -> Callable[[Any], Option[Any]]: diff --git a/expression/extra/parser.py b/expression/extra/parser.py index 13b9fca0..d724befe 100644 --- a/expression/extra/parser.py +++ b/expression/extra/parser.py @@ -2,36 +2,30 @@ import string from collections.abc import Callable -from typing import Any, Generic, TypeVar, overload +from typing import Any, overload from expression.collections import Block, block from expression.core import NOTHING, Error, Ok, Option, Result, Some, curry, fst, pipe -_A = TypeVar("_A") -_B = TypeVar("_B") -_C = TypeVar("_C") -_D = TypeVar("_D") -_E = TypeVar("_E") +type Remaining = tuple[str, int] +type ParseResult[A] = Result[tuple[A, Remaining], str] -Remaining = tuple[str, int] -ParseResult = Result[tuple[_A, Remaining], str] - -class Parser(Generic[_A]): +class Parser[A]: """The Parser class.""" __slots__ = ["_name", "_run"] - def __init__(self, run: Callable[[Remaining], ParseResult[_A]], name: str | None = None) -> None: + def __init__(self, run: Callable[[Remaining], ParseResult[A]], name: str | None = None) -> None: self._run = run self._name = name or "parser" - def __call__(self, input: str) -> Result[_A, str]: + def __call__(self, input: str) -> Result[A, str]: """Returns result without the remaining string.""" return self._run((input, 0)).map(fst) - def run(self, input: Remaining) -> ParseResult[_A]: + def run(self, input: Remaining) -> ParseResult[A]: """Returns parser result and the remaining string.""" return self._run(input) @@ -47,42 +41,42 @@ def pchar(char: str) -> Parser[str]: def any_of(list_of_chars: str) -> Parser[str]: return any_of(list_of_chars) - def and_then(self, p2: Parser[_B]) -> Parser[tuple[_A, _B]]: + def and_then[B](self, p2: Parser[B]) -> Parser[tuple[A, B]]: return pipe(self, and_then(p2)) - def ignore_then(self, p2: Parser[_B]) -> Parser[_B]: + def ignore_then[B](self, p2: Parser[B]) -> Parser[B]: return pipe(self, ignore_then(p2)) - def then_ignore(self, p2: Parser[Any]) -> Parser[_A]: + def then_ignore(self, p2: Parser[Any]) -> Parser[A]: return pipe(self, then_ignore(p2)) - def or_else(self, parser2: Parser[_A]) -> Parser[_A]: + def or_else(self, parser2: Parser[A]) -> Parser[A]: return or_else(self)(parser2) - def map(self, mapper: Callable[[_A], _B]) -> Parser[_B]: + def map[B](self, mapper: Callable[[A], B]) -> Parser[B]: mapped = map(mapper) return pipe(self, mapped) @overload - def starmap(self: Parser[tuple[_B, _C]], mapper: Callable[[_B, _C], _D]) -> Parser[_D]: ... + def starmap[B, C, D](self: Parser[tuple[B, C]], mapper: Callable[[B, C], D]) -> Parser[D]: ... @overload - def starmap(self: Parser[tuple[_B, _C, _D]], mapper: Callable[[_B, _C, _D], _E]) -> Parser[_E]: ... + def starmap[B, C, D, E](self: Parser[tuple[B, C, D]], mapper: Callable[[B, C, D], E]) -> Parser[E]: ... def starmap(self: Parser[Any], mapper: Callable[..., Any]) -> Parser[Any]: return pipe(self, starmap(mapper)) - def opt(self) -> Parser[Option[_A]]: + def opt(self) -> Parser[Option[A]]: return opt(self) def ignore(self) -> Parser[None]: return ignore(self) - def bind(self, binder: Callable[[_A], Parser[_B]]) -> Parser[_B]: + def bind[B](self, binder: Callable[[A], Parser[B]]) -> Parser[B]: bound = bind(binder) return pipe(self, bound) - def between(self, p2: Parser[_A], p3: Parser[Any]) -> Parser[_A]: + def between(self, p2: Parser[A], p3: Parser[Any]) -> Parser[A]: return between(p2)(p3)(self) def __repr__(self) -> str: @@ -111,21 +105,21 @@ def run(input: Remaining) -> ParseResult[str]: @curry(1) -def and_then(p2: Parser[_B], p1: Parser[_A]) -> Parser[tuple[_A, _B]]: +def and_then[B, A](p2: Parser[B], p1: Parser[A]) -> Parser[tuple[A, B]]: """And then. The parser p1 .>>. p2 applies the parsers p1 and p2 in sequence and returns the results in a tuple. Args: - p2 (Parser[_B]): Second parser. - p1 (Parser[_A]): First parser. + p2 (Parser[B]): Second parser. + p1 (Parser[A]): First parser. Returns: - Parser[Tuple[_A, _B]]: Result parser. + Parser[Tuple[A, B]]: Result parser. """ - def run(input: Remaining) -> ParseResult[tuple[_A, _B]]: + def run(input: Remaining) -> ParseResult[tuple[A, B]]: result1 = p1.run(input) match result1: case Error(error): @@ -143,8 +137,8 @@ def run(input: Remaining) -> ParseResult[tuple[_A, _B]]: @curry(1) -def or_else(p1: Parser[_A], p2: Parser[_A]) -> Parser[_A]: - def run(input: Remaining) -> ParseResult[_A]: +def or_else[A](p1: Parser[A], p2: Parser[A]) -> Parser[A]: + def run(input: Remaining) -> ParseResult[A]: result1 = p1.run(input) match result1: case Ok(): @@ -156,7 +150,7 @@ def run(input: Remaining) -> ParseResult[_A]: return Parser(run, f"or_else({p2}, {p1}") -def choice(list_of_parsers: Block[Parser[_A]]) -> Parser[_A]: +def choice[A](list_of_parsers: Block[Parser[A]]) -> Parser[A]: return list_of_parsers.reduce(lambda a, b: or_else(a)(b)) @@ -175,8 +169,8 @@ def any_of(list_of_chars: str) -> Parser[str]: @curry(1) -def map(mapper: Callable[[_A], _B], parser: Parser[_A]) -> Parser[_B]: - def run(input: Remaining) -> ParseResult[_B]: +def map[B, A](mapper: Callable[[A], B], parser: Parser[A]) -> Parser[B]: + def run(input: Remaining) -> ParseResult[B]: # run parser with the input result = parser.run(input) @@ -196,12 +190,12 @@ def run(input: Remaining) -> ParseResult[_B]: @curry(1) @overload -def starmap(mapper: Callable[[_A, _B], _C], parser: Parser[tuple[_A, _B]]) -> Parser[_C]: ... +def starmap[C, A, B](mapper: Callable[[A, B], C], parser: Parser[tuple[A, B]]) -> Parser[C]: ... @curry(1) @overload -def starmap(mapper: Callable[[_A, _B, _C], _D], parser: Parser[tuple[_A, _B, _C]]) -> Parser[_D]: ... +def starmap[D, A, B, C](mapper: Callable[[A, B, C], D], parser: Parser[tuple[A, B, C]]) -> Parser[D]: ... @curry(1) @@ -215,8 +209,8 @@ def mapper_(values: tuple[Any, ...]) -> Any: ) -def preturn(x: _A) -> Parser[_A]: - def run(input: Remaining) -> ParseResult[_A]: +def preturn[A](x: A) -> Parser[A]: + def run(input: Remaining) -> ParseResult[A]: return Ok((x, input)) return Parser(run, f"preturn({x})") @@ -229,8 +223,8 @@ def run(input: Remaining) -> ParseResult[Any]: return Parser(run, f'fail("{error}")') -def apply(f_p: Parser[Callable[[_A], _B]], x_p: Parser[_A]) -> Parser[_B]: - def mapper(fx: tuple[Callable[[_A], _B], _A]) -> _B: +def apply[B, A](f_p: Parser[Callable[[A], B]], x_p: Parser[A]) -> Parser[B]: + def mapper(fx: tuple[Callable[[A], B], A]) -> B: return fx[0](fx[1]) # create a Parser containing a pair (f,x) @@ -243,14 +237,14 @@ def mapper(fx: tuple[Callable[[_A], _B], _A]) -> _B: @curry(2) -def lift2(fn: Callable[[_A], Callable[[_B], _C]], xP: Parser[_A], yP: Parser[_B]) -> Parser[_C]: +def lift2[A, C, B](fn: Callable[[A], Callable[[B], C]], xP: Parser[A], yP: Parser[B]) -> Parser[C]: return apply(apply(preturn(fn), xP), yP) -def sequence(parser_list: Block[Parser[_A]]) -> Parser[Block[_A]]: +def sequence[A](parser_list: Block[Parser[A]]) -> Parser[Block[A]]: # define the "cons" function, which is a two parameter function @curry(1) - def cons(head: _A, tail: Block[_A]) -> Block[_A]: + def cons(head: A, tail: Block[A]) -> Block[A]: return tail.cons(head) # lift it to Parser World @@ -277,8 +271,8 @@ def pstring(string_input: str) -> Parser[str]: ) -def parse_zero_or_more(parser: Parser[_A], input: Remaining) -> tuple[Block[_A], Remaining]: - values: list[_A] = [] +def parse_zero_or_more[A](parser: Parser[A], input: Remaining) -> tuple[Block[A], Remaining]: + values: list[A] = [] remaining = input while True: match parser.run(remaining): @@ -291,10 +285,10 @@ def parse_zero_or_more(parser: Parser[_A], input: Remaining) -> tuple[Block[_A], return Block(values), remaining -def many(parser: Parser[_A]) -> Parser[Block[_A]]: +def many[A](parser: Parser[A]) -> Parser[Block[A]]: """Parse zero or more occurrences, rejecting success without input consumption.""" - def run(input: Remaining) -> ParseResult[Block[_A]]: + def run(input: Remaining) -> ParseResult[Block[A]]: # parse the input -- wrap in Success as it always succeeds ok = parse_zero_or_more(parser, input) return Ok(ok) @@ -302,10 +296,10 @@ def run(input: Remaining) -> ParseResult[Block[_A]]: return Parser(run, f"many({parser})") -def many1(parser: Parser[_A]) -> Parser[Block[_A]]: +def many1[A](parser: Parser[A]) -> Parser[Block[A]]: """Parse one or more occurrences, rejecting success without input consumption.""" - def run(input: Remaining) -> ParseResult[Block[_A]]: + def run(input: Remaining) -> ParseResult[Block[A]]: # run parser with the input firstResult = parser.run(input) # test the result for Failure/Success @@ -322,17 +316,17 @@ def run(input: Remaining) -> ParseResult[Block[_A]]: return Parser(run, f"many({parser})") -def sep_by1(p: Parser[_A], sep: Parser[Any]) -> Parser[Block[_A]]: +def sep_by1[A](p: Parser[A], sep: Parser[Any]) -> Parser[Block[A]]: """Parses one or more occurrences of p separated by sep.""" sep_then_p = sep.ignore_then(p) - def mapper(p: _A, plist: Block[_A]) -> Block[_A]: + def mapper(p: A, plist: Block[A]) -> Block[A]: return plist.cons(p) return p.and_then(many(sep_then_p)).starmap(mapper) -def sep_by(p: Parser[_A], sep: Parser[Any]) -> Parser[Block[_A]]: +def sep_by[A](p: Parser[A], sep: Parser[Any]) -> Parser[Block[A]]: """Parses zero or more occurrences of p separated by sep.""" return sep_by1(p, sep).or_else(preturn(block.empty)) @@ -341,36 +335,36 @@ def sep_by(p: Parser[_A], sep: Parser[Any]) -> Parser[Block[_A]]: digits = many1(parse_digit) -def opt(p: Parser[_A]) -> Parser[Option[_A]]: - nothing: Option[_A] = NOTHING +def opt[A](p: Parser[A]) -> Parser[Option[A]]: + nothing: Option[A] = NOTHING - def mapper(a: _A) -> Option[_A]: + def mapper(a: A) -> Option[A]: return Some(a) - some: Parser[Option[_A]] = pipe(p, map(mapper)) - none: Parser[Option[_A]] = preturn(nothing) + some: Parser[Option[A]] = pipe(p, map(mapper)) + none: Parser[Option[A]] = preturn(nothing) return or_else(some)(none) @curry(1) -def then_ignore( +def then_ignore[A]( p2: Parser[Any], - p1: Parser[_A], -) -> Parser[_A]: + p1: Parser[A], +) -> Parser[A]: """Then ignore. The parser p1 .>> p2 applies the parsers p1 and p2 in sequence and returns the result of p1. Args: - p2 (Parser[_B]): Second parser. - p1 (Parser[_A]): First parser. + p2 (Parser[B]): Second parser. + p1 (Parser[A]): First parser. Returns: - Parser[_A]: Result parser. + Parser[A]: Result parser. """ - def mapper(value: tuple[_A, Any]) -> _A: + def mapper(value: tuple[A, Any]) -> A: return value[0] return pipe( @@ -381,21 +375,21 @@ def mapper(value: tuple[_A, Any]) -> _A: @curry(1) -def ignore_then(p2: Parser[_B], p1: Parser[Any]) -> Parser[_B]: +def ignore_then[B](p2: Parser[B], p1: Parser[Any]) -> Parser[B]: """Ignore then. The parser p1 >>. p2 applies the parsers p1 and p2 in sequence and returns the result of p2. Args: - p2 (Parser[_B]): Second parser - p1 (Parser[_A]): First parser. + p2 (Parser[B]): Second parser + p1 (Parser[A]): First parser. Returns: - Parser[_B]: Result parser. + Parser[B]: Result parser. """ - def mapper(value: tuple[Any, _B]) -> _B: + def mapper(value: tuple[Any, B]) -> B: return value[1] return pipe( @@ -473,7 +467,7 @@ def result_to_float(sd: tuple[Option[str], Block[str]], digits2: Option[Block[st @curry(2) -def between(popen: Parser[Any], pclose: Parser[Any], p: Parser[_A]) -> Parser[_A]: +def between[A](popen: Parser[Any], pclose: Parser[Any], p: Parser[A]) -> Parser[A]: """Parse between. The parser between popen pclose p applies the parsers popen, p and @@ -482,10 +476,10 @@ def between(popen: Parser[Any], pclose: Parser[Any], p: Parser[_A]) -> Parser[_A Args: popen (Parser[Any]): First parser pclose (Parser[Any]): Last parser - p (Parser[_A]): Parser in between. + p (Parser[A]): Parser in between. Returns: - Parser[_A]: Result of the middle (p) parser. + Parser[A]: Result of the middle (p) parser. """ return pipe( popen, @@ -503,8 +497,8 @@ def _starts_with(string: str, prefix: str) -> bool: @curry(1) -def bind(f: Callable[[_A], Parser[_B]], p: Parser[_A]) -> Parser[_B]: - def run(input: Remaining) -> ParseResult[_B]: +def bind[A, B](f: Callable[[A], Parser[B]], p: Parser[A]) -> Parser[B]: + def run(input: Remaining) -> ParseResult[B]: result1 = p.run(input) match result1: case Ok((value1, remaning_input)): diff --git a/expression/extra/result/catch.py b/expression/extra/result/catch.py index b6ccb5c6..ae0c43ee 100644 --- a/expression/extra/result/catch.py +++ b/expression/extra/result/catch.py @@ -2,45 +2,42 @@ from collections.abc import Callable from functools import wraps -from typing import Any, TypeVar, cast, overload +from typing import Any, cast, overload from expression.core import Error, Ok, Result -_TSource = TypeVar("_TSource") -_TError = TypeVar("_TError", bound=Exception) -_TError_ = TypeVar("_TError_", bound=Exception) - - @overload -def catch( - exception: type[_TError_], +def catch[TError_: Exception, TSource, TError: Exception]( + exception: type[TError_], ) -> Callable[ - [Callable[..., _TSource | Result[_TSource, _TError]]], - Callable[..., Result[_TSource, _TError | _TError_]], + [Callable[..., TSource | Result[TSource, TError]]], + Callable[..., Result[TSource, TError | TError_]], ]: ... @overload -def catch(f: Callable[..., _TSource], *, exception: type[_TError]) -> Callable[..., Result[_TSource, _TError]]: ... +def catch[TSource, TError: Exception]( + f: Callable[..., TSource], *, exception: type[TError] +) -> Callable[..., Result[TSource, TError]]: ... -def catch( # type: ignore - f: Callable[..., _TSource] | None = None, *, exception: type[_TError] +def catch[TSource, TError: Exception]( # type: ignore + f: Callable[..., TSource] | None = None, *, exception: type[TError] ) -> Callable[ - [Callable[..., _TSource]], - Callable[..., Result[_TSource, _TError]] | Result[_TSource, _TError], + [Callable[..., TSource]], + Callable[..., Result[TSource, TError]] | Result[TSource, TError], ]: - def decorator(fn: Callable[..., _TSource]) -> Callable[..., Result[_TSource, _TError]]: + def decorator(fn: Callable[..., TSource]) -> Callable[..., Result[TSource, TError]]: @wraps(fn) - def wrapper(*args: Any, **kwargs: Any) -> Result[_TSource, _TError]: + def wrapper(*args: Any, **kwargs: Any) -> Result[TSource, TError]: try: out = fn(*args, **kwargs) except exception as exn: - return Error(cast(_TError, exn)) + return Error(cast(TError, exn)) else: if isinstance(out, (Ok, Error)): - return cast(Result[_TSource, _TError], out) + return cast(Result[TSource, TError], out) return Ok(out) diff --git a/expression/extra/result/pipeline.py b/expression/extra/result/pipeline.py index fb7e9d51..ca259142 100644 --- a/expression/extra/result/pipeline.py +++ b/expression/extra/result/pipeline.py @@ -1,71 +1,61 @@ from collections.abc import Callable from functools import reduce -from typing import Any, TypeVar, overload +from typing import Any, overload from expression.core.result import Ok, Result -_A = TypeVar("_A") -_B = TypeVar("_B") -_C = TypeVar("_C") -_D = TypeVar("_D") -_E = TypeVar("_E") -_F = TypeVar("_F") -_G = TypeVar("_G") -_TError = TypeVar("_TError") - - @overload def pipeline() -> Callable[[Any], Result[Any, Any]]: ... @overload -def pipeline(__fn: Callable[[_A], Result[_B, _TError]]) -> Callable[[_A], Result[_B, _TError]]: ... +def pipeline[A, B, TError](__fn: Callable[[A], Result[B, TError]]) -> Callable[[A], Result[B, TError]]: ... @overload -def pipeline( - __fn1: Callable[[_A], Result[_B, _TError]], - __fn2: Callable[[_B], Result[_C, _TError]], -) -> Callable[[_A], Result[_C, _TError]]: ... +def pipeline[A, B, TError, C]( + __fn1: Callable[[A], Result[B, TError]], + __fn2: Callable[[B], Result[C, TError]], +) -> Callable[[A], Result[C, TError]]: ... @overload -def pipeline( - __fn1: Callable[[_A], Result[_B, _TError]], - __fn2: Callable[[_B], Result[_C, _TError]], - __fn3: Callable[[_C], Result[_D, _TError]], -) -> Callable[[_A], Result[_D, _TError]]: ... +def pipeline[A, B, TError, C, D]( + __fn1: Callable[[A], Result[B, TError]], + __fn2: Callable[[B], Result[C, TError]], + __fn3: Callable[[C], Result[D, TError]], +) -> Callable[[A], Result[D, TError]]: ... @overload -def pipeline( - __fn1: Callable[[_A], Result[_B, _TError]], - __fn2: Callable[[_B], Result[_C, _TError]], - __fn3: Callable[[_C], Result[_D, _TError]], - __fn4: Callable[[_D], Result[_E, _TError]], -) -> Callable[[_A], Result[_E, _TError]]: ... +def pipeline[A, B, TError, C, D, E]( + __fn1: Callable[[A], Result[B, TError]], + __fn2: Callable[[B], Result[C, TError]], + __fn3: Callable[[C], Result[D, TError]], + __fn4: Callable[[D], Result[E, TError]], +) -> Callable[[A], Result[E, TError]]: ... @overload -def pipeline( - __fn1: Callable[[_A], Result[_B, _TError]], - __fn2: Callable[[_B], Result[_C, _TError]], - __fn3: Callable[[_C], Result[_D, _TError]], - __fn4: Callable[[_D], Result[_E, _TError]], - __fn5: Callable[[_E], Result[_F, _TError]], -) -> Callable[[_A], Result[_F, _TError]]: ... +def pipeline[A, B, TError, C, D, E, F]( + __fn1: Callable[[A], Result[B, TError]], + __fn2: Callable[[B], Result[C, TError]], + __fn3: Callable[[C], Result[D, TError]], + __fn4: Callable[[D], Result[E, TError]], + __fn5: Callable[[E], Result[F, TError]], +) -> Callable[[A], Result[F, TError]]: ... @overload -def pipeline( - __fn1: Callable[[_A], Result[_B, _TError]], - __fn2: Callable[[_B], Result[_C, _TError]], - __fn3: Callable[[_C], Result[_D, _TError]], - __fn4: Callable[[_D], Result[_E, _TError]], - __fn5: Callable[[_E], Result[_F, _TError]], - __fn6: Callable[[_F], Result[_G, _TError]], -) -> Callable[[_A], Result[_G, _TError]]: ... +def pipeline[A, B, TError, C, D, E, F, G]( + __fn1: Callable[[A], Result[B, TError]], + __fn2: Callable[[B], Result[C, TError]], + __fn3: Callable[[C], Result[D, TError]], + __fn4: Callable[[D], Result[E, TError]], + __fn5: Callable[[E], Result[F, TError]], + __fn6: Callable[[F], Result[G, TError]], +) -> Callable[[A], Result[G, TError]]: ... def pipeline(*fns: Callable[[Any], Result[Any, Any]]) -> Callable[[Any], Result[Any, Any]]: diff --git a/expression/extra/result/traversable.py b/expression/extra/result/traversable.py index d1a284f3..11839e43 100644 --- a/expression/extra/result/traversable.py +++ b/expression/extra/result/traversable.py @@ -1,40 +1,35 @@ """Data structures that can be traversed from left to right, performing an action on each element.""" from collections.abc import Callable -from typing import Any, TypeVar, cast +from typing import Any, cast from expression import effect from expression.collections import Block, block, seq from expression.core import Ok, Result, identity, pipe -_TSource = TypeVar("_TSource") -_TResult = TypeVar("_TResult") -_TError = TypeVar("_TError") - - -def traverse( - fn: Callable[[_TSource], Result[_TResult, _TError]], lst: Block[_TSource] -) -> Result[Block[_TResult], _TError]: +def traverse[TSource, TResult, TError]( + fn: Callable[[TSource], Result[TResult, TError]], lst: Block[TSource] +) -> Result[Block[TResult], TError]: """Traverses a list of items. Threads an applicative computation though a list of items. """ - @effect.result[Block[_TResult], _TError]() - def folder(head: _TSource, tail: Result[Block[_TResult], _TError]) -> Any: + @effect.result[Block[TResult], TError]() + def folder(head: TSource, tail: Result[Block[TResult], TError]) -> Any: """Fold back function. Same as: >>> fn(head).bind(lambda head: tail.bind(lambda tail: Ok([head] + tail))). """ # Pyright #11881 loses the return type for a union of iterable cases. - h = cast(_TResult, (yield from fn(head))) - t = cast(Block[_TResult], (yield from tail)) + h = cast(TResult, (yield from fn(head))) + t = cast(Block[TResult], (yield from tail)) return Block([h]) + t - state: Result[Block[_TResult], _TError] = Ok(block.empty) + state: Result[Block[TResult], TError] = Ok(block.empty) ret = pipe( state, seq.fold_back(folder, lst), @@ -42,7 +37,7 @@ def folder(head: _TSource, tail: Result[Block[_TResult], _TError]) -> Any: return ret -def sequence(lst: Block[Result[_TSource, _TError]]) -> Result[Block[_TSource], _TError]: +def sequence[TSource, TError](lst: Block[Result[TSource, TError]]) -> Result[Block[TSource], TError]: """Sequence block. Execute a sequence of result returning commands and collect the diff --git a/pyproject.toml b/pyproject.toml index b2c709ee..c0216335 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,9 @@ [project] name = "Expression" dynamic = ["version"] -description = "Practical functional programming for Python 3.11+" +description = "Practical functional programming for Python 3.12+" readme = "README.md" -requires-python = ">=3.11,<4" +requires-python = ">=3.12,<4" authors = [ { name = "Dag Brattli", email = "dag.brattli@cognite.com" }, ] @@ -14,10 +14,10 @@ classifiers = [ "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.14", + "Programming Language :: Python :: 3.15", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development :: Libraries :: Python Modules", ] @@ -52,7 +52,7 @@ dev = [ [tool.ruff] # Keep in sync with .pre-commit-config.yaml line-length = 120 -target-version = "py311" +target-version = "py312" # D100: Missing docstring in public module # D104: Missing docstring in public package # D105: Missing docstring in magic method @@ -61,6 +61,8 @@ lint.select = ["D", "E", "W", "F", "I", "T", "RUF", "TID", "UP"] exclude = ["tests", "docs"] [tool.ruff.lint.per-file-ignores] +# Keep legacy consumer syntax covered by the negative typing fixtures. +"typing_tests/negative.py" = ["UP040", "UP046"] "docs/guides/*.py" = ["D212", "D415", "E402", "E501", "I001"] "docs/tutorial/*.py" = ["D212", "D415", "E402", "E501", "I001"] diff --git a/pyrightconfig.json b/pyrightconfig.json index 1bf2fa79..4dcff005 100644 --- a/pyrightconfig.json +++ b/pyrightconfig.json @@ -2,12 +2,13 @@ "include": [ "expression", "tests", - "README.py" + "README.py", + "docs/guides/getting-started.py" ], "reportImportCycles": false, "reportMissingImports": false, "venvPath": ".", "venv": ".venv", - "pythonVersion": "3.11", + "pythonVersion": "3.12", "typeCheckingMode": "strict" } diff --git a/tests/test_union_schema.py b/tests/test_union_schema.py index 088be506..d9d21681 100644 --- a/tests/test_union_schema.py +++ b/tests/test_union_schema.py @@ -147,6 +147,22 @@ class SchemaBox(Generic[_SchemaValue]): tag: Literal["box"] = tag() +@final +@case +class ModernSchemaBox[T]: + value: T + tag: Literal["modern_box"] = tag() + + +def test_python312_type_parameters_preserve_payload_validation(): + adapter = TypeAdapter(TaggedUnion[ModernSchemaBox[Option[int]]]) + value = adapter.validate_python({"tag": "modern_box", "value": {"tag": "some", "some": 42}}) + assert value == ModernSchemaBox(Some(42)) + assert adapter.validate_json(adapter.dump_json(value)) == value + with pytest.raises(ValidationError): + adapter.validate_python({"tag": "modern_box", "value": {"tag": "some", "some": "invalid"}}) + + @final @case class SchemaUnit: diff --git a/tests/typing_contracts.py b/tests/typing_contracts.py index 3eff5671..946a8c9b 100644 --- a/tests/typing_contracts.py +++ b/tests/typing_contracts.py @@ -45,6 +45,19 @@ def option_contract(value: Option[int]) -> None: assert_never(value) +def modern_generic_option_contract[T](value: T) -> Option[T]: + present = Some(value) + widened: Option[object] = present + assert_type(widened, Some[T]) + assert_type(present.map(lambda item: (item,)), Some[tuple[T]]) + + def wrap(item: T) -> tuple[T]: + return (item,) + + assert_type(present.pipe(option.map(wrap)), Option[tuple[T]]) + return present + + def result_contract(value: Result[int, str]) -> None: assert_type(Ok(42), Ok[int]) assert_type(Error("failure"), Error[str]) diff --git a/typing_tests/pyrightconfig.json b/typing_tests/pyrightconfig.json index 9a186f48..790a4aa7 100644 --- a/typing_tests/pyrightconfig.json +++ b/typing_tests/pyrightconfig.json @@ -4,6 +4,6 @@ "venvPath": "..", "venv": ".venv", "typeCheckingMode": "strict", - "pythonVersion": "3.11", + "pythonVersion": "3.12", "reportMissingImports": false } diff --git a/uv.lock b/uv.lock index 8fe4a01b..91ca10d5 100644 --- a/uv.lock +++ b/uv.lock @@ -1,6 +1,6 @@ version = 1 revision = 5 -requires-python = ">=3.11, <4" +requires-python = ">=3.12, <4" [[package]] name = "annotated-doc" @@ -53,22 +53,6 @@ version = "3.5.0" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/cb/31/4971872b3ed8715346231fb6eb4da8fcba65a4143c189db151ee28a2812b/charset_normalizer-3.5.0.tar.gz", hash = "sha256:49bd5feb59b0bf3cbf6ebcf4352e371c95b9da9bacd4449f8b64d0ad2c10a26e", size = 169295, upload-time = "2026-08-12T14:35:31.624Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/50/42/71e4e3bfe59202feef062c68487f54c6adf501cfbe087ecd93e3cd597fea/charset_normalizer-3.5.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:e46a37ea7fcf9ae01d71b2e5ece19f1565987f3e308394b829197cbefc061f92", size = 349110, upload-time = "2026-08-12T14:32:07.832Z" }, - { url = "https://files.pythonhosted.org/packages/0f/dd/fd3386d0fbd358d3b5c7a2fa5bf312afe6159b04fafeb67d39fa971d7448/charset_normalizer-3.5.0-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1cdfed4d7a59333c8220c67dd3be4e7a6c887b67453a64394022dcc919570add", size = 250773, upload-time = "2026-08-12T14:32:09.113Z" }, - { url = "https://files.pythonhosted.org/packages/17/ad/4901a66d6d3b17f1096725d7e50266132c16555aa6a70047fe1cf262b4b2/charset_normalizer-3.5.0-cp311-cp311-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:9491f594859b68052edebd69e05fb045055a713b57a67974e6c1553b4e503c39", size = 240229, upload-time = "2026-08-12T14:32:10.43Z" }, - { url = "https://files.pythonhosted.org/packages/43/b7/1d790e0425e0f4c99e9b89a3956a94a6d2d0c6f01b2a5eca93d8f082d5ac/charset_normalizer-3.5.0-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:420b19411959eec115063229536788e6b32d0a7fa907d6b940317919120d702d", size = 280757, upload-time = "2026-08-12T14:32:11.628Z" }, - { url = "https://files.pythonhosted.org/packages/44/bb/4b8c8086c67636e52d6354ad17697f54a00b40041ca53dc765737e21709b/charset_normalizer-3.5.0-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:a565303d118ea3b94a4b6c076bf568069726be414e43b06d58f7070b076ce11d", size = 276174, upload-time = "2026-08-12T14:32:12.808Z" }, - { url = "https://files.pythonhosted.org/packages/25/fa/690a11924c40c766d258d2b74d817cc5efe7bbcfceeedc5c0f35256d7524/charset_normalizer-3.5.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:815f143a91983ba3041bba066e492ae3c42de523fb1c699685a1abf3313b7d1b", size = 261808, upload-time = "2026-08-12T14:32:14.138Z" }, - { url = "https://files.pythonhosted.org/packages/53/2d/4a6945eff0c8f684e3f5b7b978644ab18ba9198da060dbaa1d9206bc6cc9/charset_normalizer-3.5.0-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:c5e981a5ac8641381efe6f0029467500661616a530d27bc6eedfe45f840599f8", size = 259922, upload-time = "2026-08-12T14:32:15.485Z" }, - { url = "https://files.pythonhosted.org/packages/60/4d/10ac7e07bbf7ea569effeb9524e32f345f7e643800b20d538fb4706eab4e/charset_normalizer-3.5.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1a573e1e428f93908e79e04b349717f400e720f2f82285f0aaaf3ee0ff7f4c79", size = 252315, upload-time = "2026-08-12T14:32:16.764Z" }, - { url = "https://files.pythonhosted.org/packages/13/bf/1ddacf7aa7da12097f229a6a4e71a70200937a621b3617f6dc819fb99a66/charset_normalizer-3.5.0-cp311-cp311-musllinux_1_2_armv7l.whl", hash = "sha256:32e6d56dd825205f81e5c45bcebb4df6a11fb2bbf4969a01ef156d6ced90c224", size = 240600, upload-time = "2026-08-12T14:32:17.956Z" }, - { url = "https://files.pythonhosted.org/packages/c2/88/293444d48c8d86fe51552262117134a9fc666d68cbbbc9b8c1b2b35a29be/charset_normalizer-3.5.0-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:30ae26a1adcd943690dcbbc47f28be762bae9e08ad7442b78c86b1c0dd5a626c", size = 280788, upload-time = "2026-08-12T14:32:19.1Z" }, - { url = "https://files.pythonhosted.org/packages/12/ed/0e34e40584f51eda38d4a5daf25fd8586366347efd4b2470dbf64710e778/charset_normalizer-3.5.0-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:5f51a19dc52197a20218b05ec5336d0c6b3b09935f838724722032c8d45dc91a", size = 258425, upload-time = "2026-08-12T14:32:20.207Z" }, - { url = "https://files.pythonhosted.org/packages/72/b2/c1b1c27f6f0ef35b21a8bdb592854bbf7f219629db3477f74c0b1380e0ed/charset_normalizer-3.5.0-cp311-cp311-musllinux_1_2_s390x.whl", hash = "sha256:6e44bc2780516b3df986d6fe33103c7080cd9dcd5576fe3cb4b0f64309c8f22b", size = 277437, upload-time = "2026-08-12T14:32:21.345Z" }, - { url = "https://files.pythonhosted.org/packages/b2/bd/a1b7d959a37847675adb2f5978f81703306dd78df4fefb82ee5a1cc5e37f/charset_normalizer-3.5.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:7faa47b56070b3dd6f4898ed28528843ab130d53266cb9948d9b1f3bb1a5c5e8", size = 262947, upload-time = "2026-08-12T14:32:22.613Z" }, - { url = "https://files.pythonhosted.org/packages/c1/fd/a76a2d7e639bfc6a9c869371e34f28231eaca7d7126ec19895aa38eedb51/charset_normalizer-3.5.0-cp311-cp311-win32.whl", hash = "sha256:830c04a49998b5ed58c8b642c65b7b26419397f52392a64121ba9fd0e95e7f9f", size = 181313, upload-time = "2026-08-12T14:32:23.736Z" }, - { url = "https://files.pythonhosted.org/packages/97/84/6fc03e802578df41a2ab9b6a1f26657fb92e32285a603ad5852a4a4f68c1/charset_normalizer-3.5.0-cp311-cp311-win_amd64.whl", hash = "sha256:8cb9b6892b53bd6d11fa4cde3dbee020b1f0b6656be1fbaa1ec0d4324a7839db", size = 206197, upload-time = "2026-08-12T14:32:24.938Z" }, - { url = "https://files.pythonhosted.org/packages/0a/27/7208360ff1901607359869fcc45ca0989d597f3e30777ba30c7254170587/charset_normalizer-3.5.0-cp311-cp311-win_arm64.whl", hash = "sha256:2403b489c103e9a18c835863fc6dd54361355c8291d4cafdb37492b683440b9b", size = 184925, upload-time = "2026-08-12T14:32:26.123Z" }, { url = "https://files.pythonhosted.org/packages/6d/3c/045ea64ea5a550870dd8ab60b2242870328d53f17d2be593b4f9f3121474/charset_normalizer-3.5.0-cp312-cp312-macosx_10_13_universal2.whl", hash = "sha256:98820e1ceb25c6df7a80c4fd8efa59cb121f99bc7c4c1693ad94a2caff5b311d", size = 343861, upload-time = "2026-08-12T14:32:27.254Z" }, { url = "https://files.pythonhosted.org/packages/fc/1b/7502be709db899d5b4801509829188b3a5a10969411da9c846115a5f1b70/charset_normalizer-3.5.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:608553f476fca509537e804c4a71f5eb166ce63b75141f89c2c686ce1aa36956", size = 237550, upload-time = "2026-08-12T14:32:28.385Z" }, { url = "https://files.pythonhosted.org/packages/ca/ce/66392661375148d9455c17bee25509a54e28c39969e34befa48ec8777936/charset_normalizer-3.5.0-cp312-cp312-manylinux2014_armv7l.manylinux_2_17_armv7l.manylinux_2_31_armv7l.whl", hash = "sha256:6753de11eef42f1c321b26d682957d92c7f7bbce6530f34bbe0f9291dd37cc6f", size = 229673, upload-time = "2026-08-12T14:32:29.668Z" }, @@ -209,21 +193,6 @@ version = "7.15.4" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/be/c3/4f2195f512fb172aa425a8803a874b2baa9ba7f80ff7b6080998761fc701/coverage-7.15.4.tar.gz", hash = "sha256:0548198fff07ccf4faf469520bce1c2eceb1ce3e62891921138dec10907f9d00", size = 936952, upload-time = "2026-08-06T13:50:24.442Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/2a/66/edcec7d7a0b524aa8923e22925fde6fe50ce005a113dca13ae1581455c4c/coverage-7.15.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:bbac5abad70df71019988f83f26ac7092ff2642975def4429e98dc7585ef3490", size = 222367, upload-time = "2026-08-06T13:47:15.578Z" }, - { url = "https://files.pythonhosted.org/packages/e6/c6/ab8de429e2e8548faf58ec7e1674a4ce00414b4113942d3fe87109cf0f68/coverage-7.15.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:357a173465c7ce028d07a95cc2b63b5bf59f50ecdd5ad75c5cbb78ada984048e", size = 222874, upload-time = "2026-08-06T13:47:16.961Z" }, - { url = "https://files.pythonhosted.org/packages/be/c4/3b7b49587e8a6b9af79b3eb468d443d6042b6d65b47aa26586846a0d6566/coverage-7.15.4-cp311-cp311-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:21b803935e2efc3acebe9697197a294fccf5dc4e5382bd6369542ff7a7d2a1d7", size = 253287, upload-time = "2026-08-06T13:47:18.291Z" }, - { url = "https://files.pythonhosted.org/packages/fb/65/ec03b743a2a229c72cc1eff3e57be9d3564e9c6b4d5aba2d70744a3fc0d8/coverage-7.15.4-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:7a2b580774a4786c1053157c0165e04476e03ff293993d7c148eee784a94bae6", size = 255199, upload-time = "2026-08-06T13:47:19.765Z" }, - { url = "https://files.pythonhosted.org/packages/41/4b/5163729e4b6582d61975cfd3ccab45b4ec53e21cf156d9941cb025188468/coverage-7.15.4-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:a9464451c4efffe8d47ace5a540b10b0dc10e879066290f8600872b7f54a419d", size = 257308, upload-time = "2026-08-06T13:47:21.206Z" }, - { url = "https://files.pythonhosted.org/packages/86/08/2167a0f08fb87d702fa423a48578a32865464b7c9e1db3911ad7812ab414/coverage-7.15.4-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl", hash = "sha256:de602f34123c2f4af1c1869c6dbbbd60da6d5983bf01937367295d135cccbfce", size = 259268, upload-time = "2026-08-06T13:47:22.503Z" }, - { url = "https://files.pythonhosted.org/packages/1e/e5/68eebae3053dbd48508edea559c21b23fbdf3460784f91370c83a86a6acd/coverage-7.15.4-cp311-cp311-manylinux_2_31_riscv64.manylinux_2_39_riscv64.whl", hash = "sha256:6879ded16a27f3eeca19b900c147e81616e7054db451471a611b2755ee5249f7", size = 253392, upload-time = "2026-08-06T13:47:23.88Z" }, - { url = "https://files.pythonhosted.org/packages/1a/46/fd4ced40a2b691c774e515c9b69500bfa64c7960b67fcee4b2f6fad97fc3/coverage-7.15.4-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:986be58c3ab54aae8d3496a6225eea74f760fdbe739b38bd442c7e8d133aa53b", size = 255001, upload-time = "2026-08-06T13:47:25.469Z" }, - { url = "https://files.pythonhosted.org/packages/53/25/ae2e5fa710bb6957a9aadeb9e3598d3b3e4af6587ce857ad42e8639a3f30/coverage-7.15.4-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:c6103639613fe6c1e989082948419bc77a2d26b6c825c99d7fad25f7d3d87afc", size = 253061, upload-time = "2026-08-06T13:47:26.845Z" }, - { url = "https://files.pythonhosted.org/packages/d7/31/67ddc0365db2c6e93ac8580bc4bbc50f65273262f973f63ebcdbc15c0495/coverage-7.15.4-cp311-cp311-musllinux_1_2_ppc64le.whl", hash = "sha256:d3af93dddb5659276c63bc16ac6466ac2033a70ca816097bbc06345b8ccdf571", size = 256831, upload-time = "2026-08-06T13:47:28.217Z" }, - { url = "https://files.pythonhosted.org/packages/f6/78/82b8fd18f57fb13f12d98fe874995bb2c4f9f17be8aff762c426323fdb96/coverage-7.15.4-cp311-cp311-musllinux_1_2_riscv64.whl", hash = "sha256:b10075e5421d04265766a6d1dac809bbeb8a946fbb23c8f82c227409b2190719", size = 252781, upload-time = "2026-08-06T13:47:29.712Z" }, - { url = "https://files.pythonhosted.org/packages/0a/eb/6c74ef4dd12b252e573c49bdef9e2ac265bf3dbb79b8d7feb3266e084e9e/coverage-7.15.4-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:a67a9f78b2942d87ba8ce3059c642164d2aedd65337377fb52fe9803656bc5c7", size = 253692, upload-time = "2026-08-06T13:47:31.192Z" }, - { url = "https://files.pythonhosted.org/packages/5a/66/eb9aed1c3fd2d36ee00eb173f434b14fa607fc056739c9a89ff4244010ea/coverage-7.15.4-cp311-cp311-win32.whl", hash = "sha256:69484d1aca26e322e1c3ce03f09341e84524ababad2d7202161738d83cc9f82e", size = 224461, upload-time = "2026-08-06T13:47:32.572Z" }, - { url = "https://files.pythonhosted.org/packages/e2/6d/81fa4161dfb3ed9d74e40d58647eff83a56b7612e78352581280fce2f477/coverage-7.15.4-cp311-cp311-win_amd64.whl", hash = "sha256:63fd6fcd1dd6e158f7eb78606e72933b3f6d01e7b747f99c6c12d764307a0fdc", size = 224937, upload-time = "2026-08-06T13:47:34.205Z" }, - { url = "https://files.pythonhosted.org/packages/5b/c1/d8dacf683c6cad3cf85ce68fd3774a6774ec402128822fdfaed920f11e6a/coverage-7.15.4-cp311-cp311-win_arm64.whl", hash = "sha256:ea82116c9893fa89e929b7f197ee5a1950a76e91cc5c85ba503fc02379d04890", size = 224479, upload-time = "2026-08-06T13:47:36.118Z" }, { url = "https://files.pythonhosted.org/packages/1d/48/bc8d4ba7b37551a767bd863f15b3f80182b271c2f55975356f5f7dbe94c2/coverage-7.15.4-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:d4fedd1f7f428f9fe83b1ead5e7cc87a43427be31aadafbac3ac0636dc7abb22", size = 222543, upload-time = "2026-08-06T13:47:37.562Z" }, { url = "https://files.pythonhosted.org/packages/20/dd/88d6f83f1fffc974a3691a34a97951c5b12df7512a6782c5963883cbc058/coverage-7.15.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:37e2f0cdf58e2e1fed4e4d5a8f8786ae2f7eb80b478016876667dc4a01d60a97", size = 222905, upload-time = "2026-08-06T13:47:38.927Z" }, { url = "https://files.pythonhosted.org/packages/bd/5c/54ee0d4748585bb0acab9891cd8d92f2d3593165b4e59fc9de113bfb3140/coverage-7.15.4-cp312-cp312-manylinux1_i686.manylinux_2_28_i686.manylinux_2_5_i686.whl", hash = "sha256:fb55d0e70bb15f2e81477613627286581414693d74ac7963c93a790dd453ca9d", size = 254407, upload-time = "2026-08-06T13:47:40.488Z" }, @@ -317,17 +286,12 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/b4/d9/e70c286c979378f061d8266e279b686ab0b0b688e1fe0af864684f23a77d/coverage-7.15.4-py3-none-any.whl", hash = "sha256:964730a1e9de9c0cf11be6a1a3c79ce419c34882842abd256086ba4698705e84", size = 214332, upload-time = "2026-08-06T13:50:22.192Z" }, ] -[package.optional-dependencies] -toml = [ - { name = "tomli", marker = "python_full_version <= '3.11'" }, -] - [[package]] name = "coveralls" version = "4.1.0" source = { registry = "https://pypi.org/simple" } dependencies = [ - { name = "coverage", extra = ["toml"] }, + { name = "coverage" }, { name = "requests" }, { name = "typer" }, ] @@ -449,13 +413,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/3a/b2/6ef8eac3b30d6c8225fc405be3b99790701a942706ec93a3bd638a0b614a/hypothesis-6.165.9-cp310-abi3-win32.whl", hash = "sha256:5d40a92c6d025725da7827431a71b7657ce2e3923ff8f1773d6b15d717f77ea0", size = 668903, upload-time = "2026-08-15T02:48:34.033Z" }, { url = "https://files.pythonhosted.org/packages/f0/7f/b9514f65d2cc97277f6442e3b05164177a742489940efa53e794a54b62f6/hypothesis-6.165.9-cp310-abi3-win_amd64.whl", hash = "sha256:59f29ef2965caf1ae367ee0598ac0d293551b95744a5d49888737a3b3d9dd944", size = 675051, upload-time = "2026-08-15T02:47:49.697Z" }, { url = "https://files.pythonhosted.org/packages/96/01/110123106a3702d2f3ffc47b9bc6a1a29c19cd2d15fcf356430777a4883a/hypothesis-6.165.9-cp310-abi3-win_arm64.whl", hash = "sha256:f52fd4f1b95f614c3fec53840d603f0a3b19e68eaa91c8d609222999c3ee5506", size = 673402, upload-time = "2026-08-15T02:47:48.364Z" }, - { url = "https://files.pythonhosted.org/packages/de/1d/1c2dea64a3b00b9f83ca57bacaf4982255da7797d6c65fc0301f21a0ca94/hypothesis-6.165.9-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:a9995cbf91e0b22cb8d9aaaf6b10994b2ac1ebc3b01b4a91d3e82761a2737043", size = 783582, upload-time = "2026-08-15T02:49:29.881Z" }, - { url = "https://files.pythonhosted.org/packages/aa/8c/d8f51166ef9feaeb08d33737b2874d1effca4ada8bf6598e6f2a634a3ca1/hypothesis-6.165.9-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:f94e4456f7b0dd04f4f80f26a2c499370f6048f393ff61436de4e192e278e2df", size = 779367, upload-time = "2026-08-15T02:48:47.639Z" }, - { url = "https://files.pythonhosted.org/packages/8c/27/749aa12ec03fdcec1e4fa7289145f03ded46e892ae89613e333dd7090a7e/hypothesis-6.165.9-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bab95b4ef980cbc2b4632e49057588766cda930ffbd727d70edfea289da98dd3", size = 1108251, upload-time = "2026-08-15T02:47:59.983Z" }, - { url = "https://files.pythonhosted.org/packages/2b/cb/a1c417cd39f87ca11e2b5b4a7da0446ae316b43b9baee23e113a59113759/hypothesis-6.165.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8795161db0a7c270c4f3e0eb754bd0ed96b17133d6f851c7444f9733c4c9d37f", size = 1157689, upload-time = "2026-08-15T02:49:40.288Z" }, - { url = "https://files.pythonhosted.org/packages/5d/d5/82abf4d3b171f087d323b179a422472e1c1621ed47adf88f0fcdf7be7e35/hypothesis-6.165.9-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:8c7dcb0a21dab077e65bcb082ee321b7e31402cf980da648b4369c71086ad53c", size = 1283592, upload-time = "2026-08-15T02:48:04.698Z" }, - { url = "https://files.pythonhosted.org/packages/0b/ee/f156d374fd7f49220a789a231cd980ffe53bf1eec11a75306ded76265306/hypothesis-6.165.9-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:92b264bef7860bf37b5f22b5949083d26f113351da8b99e93adb0554d3e2c110", size = 1324910, upload-time = "2026-08-15T02:48:11.037Z" }, - { url = "https://files.pythonhosted.org/packages/23/57/d14969c84e59356103c0b5e1a27623a4149d5d371799757552b2ec344da2/hypothesis-6.165.9-cp311-cp311-win_amd64.whl", hash = "sha256:ae34d13d8438ea7f3ee18292290b9f608de6070309f3c5826644a88d197c319d", size = 674776, upload-time = "2026-08-15T02:48:59.008Z" }, { url = "https://files.pythonhosted.org/packages/dc/7e/03a84262b74300714af486e037403db8f5e19170f01bc32605300896b19d/hypothesis-6.165.9-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:41082aff3e438ac1eeb86002c269b9b5d86bab563e911614c2c8d34f405e02db", size = 784696, upload-time = "2026-08-15T02:48:09.314Z" }, { url = "https://files.pythonhosted.org/packages/49/50/c77dca38074e38e99373ccd5f361bb5ad251e8f2de92dff4d7035111595d/hypothesis-6.165.9-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:67a0c0346ac0e8e106fad0224269a87c665768cc8d45de6e367e9b260ef36d5a", size = 776265, upload-time = "2026-08-15T02:49:36.232Z" }, { url = "https://files.pythonhosted.org/packages/1b/80/9de2e558cd966ab1b1d014718c7aaab7d2d8f2d591ccadb27c1ffe639f6d/hypothesis-6.165.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:10e826a708456c965e125f15dbf5a6f463e41dcf230a930b7a3e0ce7036f5176", size = 1106706, upload-time = "2026-08-15T02:49:12.466Z" }, @@ -501,11 +458,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/24/ec/e70e440805820cfd662d04d05aa34b5d29e46d5a49ee871d6937721b2c17/hypothesis-6.165.9-cp315-abi3.abi3t-win32.whl", hash = "sha256:4a2081699e0b16b35c7b34cf0ff01997e8fc6038b520b9f29c106764158c411a", size = 665906, upload-time = "2026-08-15T02:49:53.901Z" }, { url = "https://files.pythonhosted.org/packages/23/79/968b149b572e1d4284b04280cc181449090c8bd03e55b24d57b64443978e/hypothesis-6.165.9-cp315-abi3.abi3t-win_amd64.whl", hash = "sha256:e1d9492193b52087df4d264edd77618869d447b5c7f6a022c7bb11b88d577cb8", size = 671817, upload-time = "2026-08-15T02:49:46.053Z" }, { url = "https://files.pythonhosted.org/packages/c2/72/0f951d4f0e07720583e4773638cd556d2b6585605f8a3df54d2fecf2e2ff/hypothesis-6.165.9-cp315-abi3.abi3t-win_arm64.whl", hash = "sha256:f67414675f2263948e5a5977b636b5cb1cc5f33b82a9be34f8a6b9a8293d4707", size = 669795, upload-time = "2026-08-15T02:48:03.176Z" }, - { url = "https://files.pythonhosted.org/packages/43/7d/1b6b48629032b22960a5b010a791467670c08d9413a3c6c15a72f7c1da09/hypothesis-6.165.9-pp311-pypy311_pp73-macosx_10_12_x86_64.whl", hash = "sha256:f6caa4194f37a02232ecb964600d17facc23a6aa5b0295008989f31e329eb837", size = 784507, upload-time = "2026-08-15T02:48:45.961Z" }, - { url = "https://files.pythonhosted.org/packages/95/a6/c29939a55cde73886cee7a3975148e132a9ed6881d39b7c9b8c19e3a854b/hypothesis-6.165.9-pp311-pypy311_pp73-macosx_11_0_arm64.whl", hash = "sha256:0a4a32dc8e8728417aa13055903dbf742dd0b5cedda7c2031b4b2a0bcc1d463d", size = 780353, upload-time = "2026-08-15T02:49:14.307Z" }, - { url = "https://files.pythonhosted.org/packages/8c/f9/ac8cd423b1c7506dae01c4a9295c434b53525401a182a116aecaa27332cf/hypothesis-6.165.9-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2f255b389364f71e6e9305ba99bf13733354cb0dc4a97d07db8aef76278a345e", size = 1109224, upload-time = "2026-08-15T02:48:15.557Z" }, - { url = "https://files.pythonhosted.org/packages/f2/26/64c4dfa2836ec421e35a167a3fba92018950a8c7551a268a5fc799329455/hypothesis-6.165.9-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0c7f0507d8224e5b44c2651d7ef8df15ac6d38eb56c98e7f451c3090804ce109", size = 1158929, upload-time = "2026-08-15T02:49:21.922Z" }, - { url = "https://files.pythonhosted.org/packages/88/8e/fccbea8a0a03532762fdd56d3809fd8398f46af1ec9018f694d4ec5c22cf/hypothesis-6.165.9-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:fd9e242fabb05715ec2d3b9b96dcddf683fc3891a04b6685b79e400e35ccbe18", size = 675885, upload-time = "2026-08-15T02:47:50.986Z" }, ] [[package]] @@ -715,21 +667,6 @@ dependencies = [ ] sdist = { url = "https://files.pythonhosted.org/packages/9d/56/921726b776ace8d8f5db44c4ef961006580d91dc52b803c489fafd1aa249/pydantic_core-2.46.4.tar.gz", hash = "sha256:62f875393d7f270851f20523dd2e29f082bcc82292d66db2b64ea71f64b6e1c1", size = 471464, upload-time = "2026-05-06T13:37:06.98Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/5c/fa/6d7708d2cfc1a832acb6aeb0cd16e801902df8a0f583bb3b4b527fde022e/pydantic_core-2.46.4-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:0e96592440881c74a213e5ad528e2b24d3d4f940de2766bed9010ab1d9e51594", size = 2111872, upload-time = "2026-05-06T13:40:27.596Z" }, - { url = "https://files.pythonhosted.org/packages/ae/6f/aa064a3e74b5745afbdf250594f38e7ead05e2d651bcb35994b9417a0d4d/pydantic_core-2.46.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:e0d65b8c354be7fb5f720c3caa8bc940bc2d20ce749c8e06135f07f8ed95dd7c", size = 1948255, upload-time = "2026-05-06T13:39:12.574Z" }, - { url = "https://files.pythonhosted.org/packages/43/3a/41114a9f7569b84b4d84e7a018c57c56347dac30c0d4a872946ec4e36c46/pydantic_core-2.46.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7bfb192b3f4b9e8a89b6277b6ce787564f62cfd272055f6e685726b111dc7826", size = 1972827, upload-time = "2026-05-06T13:38:19.841Z" }, - { url = "https://files.pythonhosted.org/packages/ef/25/1ab42e8048fe551934d9884e8d64daa7e990ad386f310a15981aeb6a5b08/pydantic_core-2.46.4-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:9037063db01f09b09e237c282b6792bd4da634b5402c4e7f0c61effed7701a04", size = 2041051, upload-time = "2026-05-06T13:38:10.447Z" }, - { url = "https://files.pythonhosted.org/packages/94/c2/1a934597ddf08da410385b3b7aae91956a5a76c635effef456074fad7e88/pydantic_core-2.46.4-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:fc010ab034c8c7452522748bf937df58020d256ccae0874463d1f4d01758af8e", size = 2221314, upload-time = "2026-05-06T13:40:13.089Z" }, - { url = "https://files.pythonhosted.org/packages/02/6d/9e8ad178c9c4df27ad3c8f25d1fe2a7ab0d2ba0559fad4aee5d3d1f16771/pydantic_core-2.46.4-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8c5dac79fa1614d1e06ca695109c6105923bd9c7d1d6c918d4e637b7e6b32fd3", size = 2285146, upload-time = "2026-05-06T13:38:59.224Z" }, - { url = "https://files.pythonhosted.org/packages/80/50/540cd3aeefc041beb111125c4bff779831a2111fc6b15a9138cda277d32c/pydantic_core-2.46.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f9fa868638bf362d3d138ea55829cefb3d5f4b0d7f142234382a15e2485dbec4", size = 2089685, upload-time = "2026-05-06T13:38:17.762Z" }, - { url = "https://files.pythonhosted.org/packages/6b/a4/b440ad35f05f6a38f89fa0f149accb3f0e02be94ca5e15f3c449a61b4bc9/pydantic_core-2.46.4-cp311-cp311-manylinux_2_31_riscv64.whl", hash = "sha256:17299feefe090f2caa5b8e37222bb5f663e4935a8bfa6931d4102e5df1a9f398", size = 2115420, upload-time = "2026-05-06T13:37:58.195Z" }, - { url = "https://files.pythonhosted.org/packages/99/61/de4f55db8dfd57bfdfa9a12ec90fe1b57c4f41062f7ca86f08586b3e0ac0/pydantic_core-2.46.4-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:4c63ebc82684aa89d9a3bcbd13d515b3be44250dc68dd3bd81526c1cb31286c3", size = 2165122, upload-time = "2026-05-06T13:37:01.167Z" }, - { url = "https://files.pythonhosted.org/packages/f7/52/7c529d7bdb2d1068bd52f51fe32572c8301f9a4febf1948f10639f1436f5/pydantic_core-2.46.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:aaa2a54443eff1950ba5ddc6b6ccda0d9c84a364276a62f969bdf2a390650848", size = 2182573, upload-time = "2026-05-06T13:38:45.04Z" }, - { url = "https://files.pythonhosted.org/packages/37/b3/7c40325848ba78247f2812dcf9c7274e38cd801820ca6dd9fe63bcfb0eb4/pydantic_core-2.46.4-cp311-cp311-musllinux_1_1_armv7l.whl", hash = "sha256:18e5ceec2ab67e6d5f1a9085e5a24c9c4e2ac4545730bfe668680bca05e555f3", size = 2317139, upload-time = "2026-05-06T13:37:15.539Z" }, - { url = "https://files.pythonhosted.org/packages/d9/37/f913f81a657c865b75da6c0dbed79876073c2a43b5bd9edbe8da785e4d49/pydantic_core-2.46.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:a0f62d0a58f4e7da165457e995725421e0064f2255d8eccebc49f41bbc23b109", size = 2360433, upload-time = "2026-05-06T13:37:30.099Z" }, - { url = "https://files.pythonhosted.org/packages/c4/67/6acaa1be2567f9256b056d8477158cac7240813956ce86e49deae8e173b4/pydantic_core-2.46.4-cp311-cp311-win32.whl", hash = "sha256:041bde0a48fd37cf71cab1c9d56d3e8625a3793fef1f7dd232b3ff37e978ecda", size = 1985513, upload-time = "2026-05-06T13:38:15.669Z" }, - { url = "https://files.pythonhosted.org/packages/aa/e6/c505f83dfeda9a2e5c995cfd872949e4d05e12f7feb3dca72f633daefa94/pydantic_core-2.46.4-cp311-cp311-win_amd64.whl", hash = "sha256:6f2eeda33a839975441c86a4119e1383c50b47faf0cbb5176985565c6bb02c33", size = 2071114, upload-time = "2026-05-06T13:40:35.416Z" }, - { url = "https://files.pythonhosted.org/packages/0f/da/7a263a96d965d9d0df5e8de8a475f33495451117035b09acb110288c381f/pydantic_core-2.46.4-cp311-cp311-win_arm64.whl", hash = "sha256:14f4c5d6db102bd796a627bbb3a17b4cf4574b9ae861d8b7c9a9661c6dd3362d", size = 2044298, upload-time = "2026-05-06T13:38:29.754Z" }, { url = "https://files.pythonhosted.org/packages/ce/8c/af022f0af448d7747c5154288d46b5f2bc5f17366eaa0e23e9aa04d59f3b/pydantic_core-2.46.4-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:3245406455a5d98187ec35530fd772b1d799b26667980872c8d4614991e2c4a2", size = 2106158, upload-time = "2026-05-06T13:38:57.215Z" }, { url = "https://files.pythonhosted.org/packages/19/95/6195171e385007300f0f5574592e467c568becce2d937a0b6804f218bc49/pydantic_core-2.46.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:962ccbab7b642487b1d8b7df90ef677e03134cf1fd8880bf698649b22a69371f", size = 1951724, upload-time = "2026-05-06T13:37:02.697Z" }, { url = "https://files.pythonhosted.org/packages/8e/bc/f47d1ff9cbb1620e1b5b697eef06010035735f07820180e74178226b27b3/pydantic_core-2.46.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8233f2947cf85404441fd7e0085f53b10c93e0ee78611099b5c7237e36aacbf7", size = 1975742, upload-time = "2026-05-06T13:37:09.448Z" }, @@ -790,22 +727,10 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/30/a6/9f9f380dbb301f67023bf8f707aaa75daadf84f7152d95c410fd7e81d994/pydantic_core-2.46.4-cp314-cp314t-win32.whl", hash = "sha256:e846ae7835bf0703ae43f534ab79a867146dadd59dc9ca5c8b53d5c8f7c9ef02", size = 1955575, upload-time = "2026-05-06T13:38:51.116Z" }, { url = "https://files.pythonhosted.org/packages/40/1f/f1eb9eb350e795d1af8586289746f5c5677d16043040d63710e22abc43c9/pydantic_core-2.46.4-cp314-cp314t-win_amd64.whl", hash = "sha256:2108ba5c1c1eca18030634489dc544844144ee36357f2f9f780b93e7ddbb44b5", size = 2051624, upload-time = "2026-05-06T13:38:21.672Z" }, { url = "https://files.pythonhosted.org/packages/f6/d2/42dd53d0a85c27606f316d3aa5d2869c4e8470a5ed6dec30e4a1abe19192/pydantic_core-2.46.4-cp314-cp314t-win_arm64.whl", hash = "sha256:4fcbe087dbc2068af7eda3aa87634eba216dbda64d1ae73c8684b621d33f6596", size = 2017325, upload-time = "2026-05-06T13:40:52.723Z" }, - { url = "https://files.pythonhosted.org/packages/ee/a4/73995fd4ebbb46ba0ee51e6fa049b8f02c40daebb762208feda8a6b7894d/pydantic_core-2.46.4-graalpy311-graalpy242_311_native-macosx_10_12_x86_64.whl", hash = "sha256:14d4edf427bdcf950a8a02d7cb44a08614388dd6e1bdcbf4f67504fa7887da9c", size = 2111589, upload-time = "2026-05-06T13:37:10.817Z" }, - { url = "https://files.pythonhosted.org/packages/fb/7f/f37d3a5e8bfcc2e403f5c57a730f2d815693fb42119e8ea48b3789335af1/pydantic_core-2.46.4-graalpy311-graalpy242_311_native-macosx_11_0_arm64.whl", hash = "sha256:0ce40cd7b21210e99342afafbd4d0f76d784eb5b1d60f3bdc566be4983c6c73b", size = 1944552, upload-time = "2026-05-06T13:36:56.717Z" }, - { url = "https://files.pythonhosted.org/packages/15/3c/d7eb777b3ff43e8433a4efb39a17aa8fd98a4ee8561a24a67ef5db07b2d6/pydantic_core-2.46.4-graalpy311-graalpy242_311_native-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:90884113d8b48f760e9587002789ddd741e76ab9f89518cd1e43b1f1a52ec44b", size = 1982984, upload-time = "2026-05-06T13:39:06.207Z" }, - { url = "https://files.pythonhosted.org/packages/63/87/70b9f40170a81afd55ca26c9b2acb25c20d64bcfbf888fafecb3ba077d4c/pydantic_core-2.46.4-graalpy311-graalpy242_311_native-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:66ce7632c22d837c95301830e111ad0128a32b8207533b60896a96c4915192ea", size = 2138417, upload-time = "2026-05-06T13:39:45.476Z" }, { url = "https://files.pythonhosted.org/packages/9d/1d/8987ad40f65ae1432753072f214fb5c74fe47ffbd0698bb9cbbb585664f8/pydantic_core-2.46.4-graalpy312-graalpy250_312_native-macosx_10_12_x86_64.whl", hash = "sha256:1d8ba486450b14f3b1d63bc521d410ec7565e52f887b9fb671791886436a42f7", size = 2095527, upload-time = "2026-05-06T13:39:52.283Z" }, { url = "https://files.pythonhosted.org/packages/64/d3/84c282a7eee1d3ac4c0377546ef5a1ea436ce26840d9ac3b7ed54a377507/pydantic_core-2.46.4-graalpy312-graalpy250_312_native-macosx_11_0_arm64.whl", hash = "sha256:3009f12e4e90b7f88b4f9adb1b0c4a3d58fe7820f3238c190047209d148026df", size = 1936024, upload-time = "2026-05-06T13:40:15.671Z" }, { url = "https://files.pythonhosted.org/packages/d7/ca/eac61596cdeb4d7e174d3dc0bd8a6238f14f75f97a24e7b7db4c7e7340a0/pydantic_core-2.46.4-graalpy312-graalpy250_312_native-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ad785e92e6dc634c21555edc8bd6b64957ab844541bcb96a1366c202951ae526", size = 1990696, upload-time = "2026-05-06T13:38:34.717Z" }, { url = "https://files.pythonhosted.org/packages/fa/c3/7c8b240552251faf6b3a957db200fcfbbcec36763c050428b601e0c9b83b/pydantic_core-2.46.4-graalpy312-graalpy250_312_native-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:00c603d540afdd6b80eb39f078f33ebd46211f02f33e34a32d9f053bba711de0", size = 2147590, upload-time = "2026-05-06T13:39:29.883Z" }, - { url = "https://files.pythonhosted.org/packages/11/cb/428de0385b6c8d44b716feba566abfacfbd23ee3c4439faa789a1456242f/pydantic_core-2.46.4-pp311-pypy311_pp73-macosx_10_12_x86_64.whl", hash = "sha256:0c563b08bca408dc7f65f700633d8442fffb2421fc47b8101377e9fd65051ff0", size = 2112782, upload-time = "2026-05-06T13:37:04.016Z" }, - { url = "https://files.pythonhosted.org/packages/0b/b5/6a17bdadd0fc1f170adfd05a20d37c832f52b117b4d9131da1f41bb097ce/pydantic_core-2.46.4-pp311-pypy311_pp73-macosx_11_0_arm64.whl", hash = "sha256:db06ffe51636ffe9ca531fe9023dd64bdd794be8754cb5df57c5498ae5b518a7", size = 1952146, upload-time = "2026-05-06T13:39:43.092Z" }, - { url = "https://files.pythonhosted.org/packages/2a/dc/03734d80e362cd43ef65428e9de77c730ce7f2f11c60d2b1e1b39f0fbf99/pydantic_core-2.46.4-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:133878133d271ade3d41d1bfb2a45ec38dbdbda40bc065921c6b04e4630127e2", size = 2134492, upload-time = "2026-05-06T13:36:58.124Z" }, - { url = "https://files.pythonhosted.org/packages/de/df/5e5ffc085ed07cc22d298134d3d911c63e91f6a0eb91fe646750a3209910/pydantic_core-2.46.4-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:9bc519fbf2b7578398853d815009ae5e4d4603d12f4e3f91da8c06852d3da3e9", size = 2156604, upload-time = "2026-05-06T13:37:49.88Z" }, - { url = "https://files.pythonhosted.org/packages/81/44/6e112a4253e56f5705467cbab7ab5e91ee7398ba3d56d358635958893d3e/pydantic_core-2.46.4-pp311-pypy311_pp73-musllinux_1_1_aarch64.whl", hash = "sha256:c7a7bd4e39e8e4c12c39cd480356842b6a8a06e41b23a55a5e3e191718838ddf", size = 2183828, upload-time = "2026-05-06T13:37:43.053Z" }, - { url = "https://files.pythonhosted.org/packages/ac/ad/5565071e937d8e752842ac241463944c9eb14c87e2d269f2658a5bd05e98/pydantic_core-2.46.4-pp311-pypy311_pp73-musllinux_1_1_armv7l.whl", hash = "sha256:d396ec2b979760aaf3218e76c24e65bd0aca24983298653b3a9d7a45f9e47b30", size = 2310000, upload-time = "2026-05-06T13:37:56.694Z" }, - { url = "https://files.pythonhosted.org/packages/4f/c3/66883a5cec183e7fba4d024b4cbbe61851a63750ef606b0afecc46d1f2bf/pydantic_core-2.46.4-pp311-pypy311_pp73-musllinux_1_1_x86_64.whl", hash = "sha256:86e1a4418c6cd97d60c95c71164158eaf7324fae7b0923264016baa993eba6fc", size = 2361286, upload-time = "2026-05-06T13:40:05.667Z" }, - { url = "https://files.pythonhosted.org/packages/4b/2d/69abac8f838090bbecd5df894befb2c2619e7996a98ddb949db9f3b93225/pydantic_core-2.46.4-pp311-pypy311_pp73-win_amd64.whl", hash = "sha256:d51026d73fcfd93610abc7b27789c26b313920fcfb20e27462d74a7f8b06e983", size = 2193071, upload-time = "2026-05-06T13:38:08.682Z" }, ] [[package]] @@ -864,15 +789,6 @@ version = "6.0.3" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/05/8e/961c0007c59b8dd7729d542c61a4d537767a59645b82a0b521206e1e25c2/pyyaml-6.0.3.tar.gz", hash = "sha256:d76623373421df22fb4cf8817020cbb7ef15c725b9d5e45f17e189bfc384190f", size = 130960, upload-time = "2025-09-25T21:33:16.546Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/6d/16/a95b6757765b7b031c9374925bb718d55e0a9ba8a1b6a12d25962ea44347/pyyaml-6.0.3-cp311-cp311-macosx_10_13_x86_64.whl", hash = "sha256:44edc647873928551a01e7a563d7452ccdebee747728c1080d881d68af7b997e", size = 185826, upload-time = "2025-09-25T21:31:58.655Z" }, - { url = "https://files.pythonhosted.org/packages/16/19/13de8e4377ed53079ee996e1ab0a9c33ec2faf808a4647b7b4c0d46dd239/pyyaml-6.0.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:652cb6edd41e718550aad172851962662ff2681490a8a711af6a4d288dd96824", size = 175577, upload-time = "2025-09-25T21:32:00.088Z" }, - { url = "https://files.pythonhosted.org/packages/0c/62/d2eb46264d4b157dae1275b573017abec435397aa59cbcdab6fc978a8af4/pyyaml-6.0.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:10892704fc220243f5305762e276552a0395f7beb4dbf9b14ec8fd43b57f126c", size = 775556, upload-time = "2025-09-25T21:32:01.31Z" }, - { url = "https://files.pythonhosted.org/packages/10/cb/16c3f2cf3266edd25aaa00d6c4350381c8b012ed6f5276675b9eba8d9ff4/pyyaml-6.0.3-cp311-cp311-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:850774a7879607d3a6f50d36d04f00ee69e7fc816450e5f7e58d7f17f1ae5c00", size = 882114, upload-time = "2025-09-25T21:32:03.376Z" }, - { url = "https://files.pythonhosted.org/packages/71/60/917329f640924b18ff085ab889a11c763e0b573da888e8404ff486657602/pyyaml-6.0.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:b8bb0864c5a28024fac8a632c443c87c5aa6f215c0b126c449ae1a150412f31d", size = 806638, upload-time = "2025-09-25T21:32:04.553Z" }, - { url = "https://files.pythonhosted.org/packages/dd/6f/529b0f316a9fd167281a6c3826b5583e6192dba792dd55e3203d3f8e655a/pyyaml-6.0.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:1d37d57ad971609cf3c53ba6a7e365e40660e3be0e5175fa9f2365a379d6095a", size = 767463, upload-time = "2025-09-25T21:32:06.152Z" }, - { url = "https://files.pythonhosted.org/packages/f2/6a/b627b4e0c1dd03718543519ffb2f1deea4a1e6d42fbab8021936a4d22589/pyyaml-6.0.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:37503bfbfc9d2c40b344d06b2199cf0e96e97957ab1c1b546fd4f87e53e5d3e4", size = 794986, upload-time = "2025-09-25T21:32:07.367Z" }, - { url = "https://files.pythonhosted.org/packages/45/91/47a6e1c42d9ee337c4839208f30d9f09caa9f720ec7582917b264defc875/pyyaml-6.0.3-cp311-cp311-win32.whl", hash = "sha256:8098f252adfa6c80ab48096053f512f2321f0b998f98150cea9bd23d83e1467b", size = 142543, upload-time = "2025-09-25T21:32:08.95Z" }, - { url = "https://files.pythonhosted.org/packages/da/e3/ea007450a105ae919a72393cb06f122f288ef60bba2dc64b26e2646fa315/pyyaml-6.0.3-cp311-cp311-win_amd64.whl", hash = "sha256:9f3bfb4965eb874431221a3ff3fdcddc7e74e3b07799e0e84ca4a0f867d449bf", size = 158763, upload-time = "2025-09-25T21:32:09.96Z" }, { url = "https://files.pythonhosted.org/packages/d1/33/422b98d2195232ca1826284a76852ad5a86fe23e31b009c9886b2d0fb8b2/pyyaml-6.0.3-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:7f047e29dcae44602496db43be01ad42fc6f1cc0d8cd6c83d342306c32270196", size = 182063, upload-time = "2025-09-25T21:32:11.445Z" }, { url = "https://files.pythonhosted.org/packages/89/a0/6cf41a19a1f2f3feab0e9c0b74134aa2ce6849093d5517a0c550fe37a648/pyyaml-6.0.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:fc09d0aa354569bc501d4e787133afc08552722d3ab34836a80547331bb5d4a0", size = 173973, upload-time = "2025-09-25T21:32:12.492Z" }, { url = "https://files.pythonhosted.org/packages/ed/23/7a778b6bd0b9a8039df8b1b1d80e2e2ad78aa04171592c8a5c43a56a6af4/pyyaml-6.0.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9149cad251584d5fb4981be1ecde53a1ca46c891a79788c0df828d2f166bda28", size = 775116, upload-time = "2025-09-25T21:32:13.652Z" }, @@ -961,21 +877,6 @@ version = "2026.6.3" source = { registry = "https://pypi.org/simple" } sdist = { url = "https://files.pythonhosted.org/packages/aa/2a/9618a122aeb2a169a28b03889a2995fe297588964333d4a7d67bdf46e147/rpds_py-2026.6.3.tar.gz", hash = "sha256:1cebd1337c242e4ec2293e541f712b2da849b29f48f0c293684b71c0632625d4", size = 64051, upload-time = "2026-06-30T07:17:53.009Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/94/1f/a2dca5ffdbf1d475ffc4e80e4d5d720ff3a00f691795910116960ee12511/rpds_py-2026.6.3-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:7b689145a1485c335569bd056464f3243a29af7ed3871c7be31ad624ba239bc7", size = 342174, upload-time = "2026-06-30T07:14:54.821Z" }, - { url = "https://files.pythonhosted.org/packages/4d/dc/323d08583c0832911768663d1944f0107fcd4088704858d84b5e06d105a0/rpds_py-2026.6.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:db08f45aecde626498fb3df07bcf6d2ec040af42e859a4f5040d79c200342911", size = 345513, upload-time = "2026-06-30T07:14:56.515Z" }, - { url = "https://files.pythonhosted.org/packages/0b/2a/e31989834d18d2f26ec1d2774c5b1eb3331df4ea8ada525175294c94b48a/rpds_py-2026.6.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:acc992ab27b15f852c76755eb2ab7dce86585ddadba6fa5946e58556088845b4", size = 373783, upload-time = "2026-06-30T07:14:57.736Z" }, - { url = "https://files.pythonhosted.org/packages/87/fe/e80107ee3639585c9941c17d6a42cd65325022f656c023191fce78c324c8/rpds_py-2026.6.3-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:7f88d653e7b3b779d71ae7454e20dcc9b6bae903f33c269db9f2be41bda3f261", size = 378316, upload-time = "2026-06-30T07:14:59.077Z" }, - { url = "https://files.pythonhosted.org/packages/22/6f/81e3adf81acfb6fa694de2a6e4e7d8863121e3e0799e0a7725e6cf5679c4/rpds_py-2026.6.3-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:e52655eaf81e32593abedaa4bfe33170c8cfedf3365ed9be6e11e07f148f0278", size = 499423, upload-time = "2026-06-30T07:15:00.488Z" }, - { url = "https://files.pythonhosted.org/packages/2d/9a/41263969df0ce3d9af2a96d5005a288200af1989aed3354bfceb5fc0b21f/rpds_py-2026.6.3-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:dfcc8b909769d19db55c7cc9541eb64b9b774b1057ffffb4f1048070475bb9f9", size = 386077, upload-time = "2026-06-30T07:15:01.911Z" }, - { url = "https://files.pythonhosted.org/packages/5e/19/7e98f468bd50346faff5b10e5297374b443bfdddacc8e9fbc65984539597/rpds_py-2026.6.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9c1255b302953c86a486b81d330d5ee1d5bd937691ce271b6be0ef0e299eaab7", size = 371315, upload-time = "2026-06-30T07:15:03.317Z" }, - { url = "https://files.pythonhosted.org/packages/99/3c/2b973b4d371906a134b03decfea7f5d9835a2c6d263454392e15b64b5b18/rpds_py-2026.6.3-cp311-cp311-manylinux_2_31_riscv64.whl", hash = "sha256:8d2294a31386bfa251d8c8a39472beee17db67d4f1a6eabea665d35c9a4461c3", size = 383502, upload-time = "2026-06-30T07:15:04.627Z" }, - { url = "https://files.pythonhosted.org/packages/98/2a/12e2799500af0a307bca76b63361c51f9fe479223561489c29eea1f2ee41/rpds_py-2026.6.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:f8f23ead891a3b762f35ab3b04623da7056545b48aa60d59957e6789914545da", size = 402673, upload-time = "2026-06-30T07:15:05.856Z" }, - { url = "https://files.pythonhosted.org/packages/2d/e3/21e5872d165fe08be4f229e3d5ee9d90019c0bf0e5538de60dbd54009450/rpds_py-2026.6.3-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:421aba32367055614287a4292b6a17f1939c9452299f7a0209c117e990b646d4", size = 549964, upload-time = "2026-06-30T07:15:07.159Z" }, - { url = "https://files.pythonhosted.org/packages/1a/d0/5ee0fe36844297de8123bee27bc12078c1a7416ad9f1b8a8ca18d6b0c0ac/rpds_py-2026.6.3-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:1e5822dfc2f0d4ab7e745eaa6d85945069329beeccef965af3f3bb26058fcab6", size = 615446, upload-time = "2026-06-30T07:15:08.531Z" }, - { url = "https://files.pythonhosted.org/packages/b1/80/1ea5873cb683f2fbe5f21b23ea1f6d179ead19f3c5b249b7eb5dca568ef2/rpds_py-2026.6.3-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:83e35b57523816c8613fd0776b40cd8bb9f596b37ddd2692eb4a6bb5ab2f8c93", size = 576975, upload-time = "2026-06-30T07:15:09.97Z" }, - { url = "https://files.pythonhosted.org/packages/c9/e1/90ef639217a5ddb15b7f4f61b1c33911fd044ad03c311bafdd2bcab85582/rpds_py-2026.6.3-cp311-cp311-win32.whl", hash = "sha256:de3eceba0b683bcbb1ab93da016d0270df1f9ae7be716b40214c5dafac6ea45a", size = 204453, upload-time = "2026-06-30T07:15:11.324Z" }, - { url = "https://files.pythonhosted.org/packages/f2/b7/b7a1695d7af36f521fb11e80d6d3adbd744f73b921859bd3c2a2c0dc706f/rpds_py-2026.6.3-cp311-cp311-win_amd64.whl", hash = "sha256:2c54a076ca4d370980ab57bc0e31df57bbe8d41340436a90ef8b1219a3cbb127", size = 223219, upload-time = "2026-06-30T07:15:12.476Z" }, - { url = "https://files.pythonhosted.org/packages/d7/a2/145afacf796e4506062825941176ad9445c2dcf2b3b6a1f13d3030a15e19/rpds_py-2026.6.3-cp311-cp311-win_arm64.whl", hash = "sha256:168c733a7112e071bb7a66460e667edfcff06c017a3c523f7a8a8e08d0140804", size = 219137, upload-time = "2026-06-30T07:15:13.631Z" }, { url = "https://files.pythonhosted.org/packages/5c/be/2e8974163072e7bab7df1a5acd54c4498e75e35d6d18b864d3a9d5dadc92/rpds_py-2026.6.3-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:a0811d33247c3d6128a3001d763f2aa056bb3425204335400ac54f89eec3a0d0", size = 343691, upload-time = "2026-06-30T07:15:14.96Z" }, { url = "https://files.pythonhosted.org/packages/a4/73/319dfa745dd668efe89309141ded489126461fcecd2b8f3a3cda185129b6/rpds_py-2026.6.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:538949e262e46caa31ac01bdb3c1e8f642622922cacbabbae6a8445d9dc33eaf", size = 338542, upload-time = "2026-06-30T07:15:16.267Z" }, { url = "https://files.pythonhosted.org/packages/21/63/4239893be1c4d09b709b1a8f6be4188f0870084ff547f46606b8a75f1b03/rpds_py-2026.6.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:55927d532399c2c646100ff7feb48eaa940ad70f42cd68e1328f3ded9f81ca24", size = 368180, upload-time = "2026-06-30T07:15:17.62Z" }, @@ -1064,18 +965,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/8b/71/14edf065f04630b1a8472f7653cad03f6c478bcf95ea0e6aed55451e33ea/rpds_py-2026.6.3-cp315-cp315t-musllinux_1_2_x86_64.whl", hash = "sha256:23a439f31ccbeff1574e24889128821d1f7917470e830cf6544dced1c662262a", size = 576533, upload-time = "2026-06-30T07:17:28.546Z" }, { url = "https://files.pythonhosted.org/packages/ba/76/65002b08596c389105720a8c0d22298b8dc25a4baf89b2ce431343c8b1de/rpds_py-2026.6.3-cp315-cp315t-win32.whl", hash = "sha256:913ca42ccad3f8cc6e292b587ae8ae49c8c823e5dce51a736252fc7c7cdfa577", size = 201204, upload-time = "2026-06-30T07:17:30.193Z" }, { url = "https://files.pythonhosted.org/packages/8c/97/d855d6b3c322d1f27e26f5241c42016b56cf01377ea8ed348285f54652f0/rpds_py-2026.6.3-cp315-cp315t-win_amd64.whl", hash = "sha256:ae3d4fe8c0b9213624fdce7279d70e3b148b682ca20719ebd193a23ebfa47324", size = 220719, upload-time = "2026-06-30T07:17:31.788Z" }, - { url = "https://files.pythonhosted.org/packages/b4/9c/f0d19ac587fd0e4ab6b72cda355e9c5a6166b01ef7e064e437aef8eb9fef/rpds_py-2026.6.3-pp311-pypy311_pp73-macosx_10_12_x86_64.whl", hash = "sha256:4cf2d36a2357e4d07bb5a4f98801265327b48256867816cfd2ceb001e9754a8f", size = 349791, upload-time = "2026-06-30T07:17:33.315Z" }, - { url = "https://files.pythonhosted.org/packages/38/c7/1d49d204c9fd2ee6c537601dc4c1ba921e03363ca576bfab94a00254ac9a/rpds_py-2026.6.3-pp311-pypy311_pp73-macosx_11_0_arm64.whl", hash = "sha256:30c6dc199b24a5e3e81d50da0f00858c5bbdb2617a750395687f4339c5818171", size = 352842, upload-time = "2026-06-30T07:17:34.897Z" }, - { url = "https://files.pythonhosted.org/packages/ac/e5/c0b5dc93cd0d4c06ce1f438907649514e2ea077bcd911e3154a51e96c38e/rpds_py-2026.6.3-pp311-pypy311_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9891e594296ab9dada6551c8e7b387b2721f27a67eecd528412e8906247a7b90", size = 382094, upload-time = "2026-06-30T07:17:36.514Z" }, - { url = "https://files.pythonhosted.org/packages/0d/54/ec0e907b4ca8d541112db352409bd15f871c9b243e0c92c9b5a46ae96f01/rpds_py-2026.6.3-pp311-pypy311_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:b5c2dc92304aa48a4a60443b548bb12f12e119d4b72f314015e67b9e1be97fca", size = 388662, upload-time = "2026-06-30T07:17:38.235Z" }, - { url = "https://files.pythonhosted.org/packages/d3/f4/921c22a4fd0f1c1ac13a3996ffbf0aa67951e2c8ad0d1d9574938a2932e8/rpds_py-2026.6.3-pp311-pypy311_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:127e08c0642d880cf32ca47ec2a4a77b901f7e2dd1ad9762adb13955d72ffcc9", size = 504896, upload-time = "2026-06-30T07:17:39.689Z" }, - { url = "https://files.pythonhosted.org/packages/0b/1b/a114b972cefa1ab1cdb3c7bb177cd3844a12826c507c722d3a73516dbbaf/rpds_py-2026.6.3-pp311-pypy311_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:8bb68f03f395eb793220b45c097bd4d8c32944393da0fad8b999efac0868fc8c", size = 391545, upload-time = "2026-06-30T07:17:41.336Z" }, - { url = "https://files.pythonhosted.org/packages/4e/98/af9b3db77d47fcbe6c8c1f36e2c2147ec70292819e99c325f871584a1c11/rpds_py-2026.6.3-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a3450b693fde92133e9f51060568a4c31fcca76d5e53bbd611e689ca446517e9", size = 380059, upload-time = "2026-06-30T07:17:42.857Z" }, - { url = "https://files.pythonhosted.org/packages/c9/ba/0efd8668b97c1d26a61566386c636a7a7a09829e474fdf807caa15a2c844/rpds_py-2026.6.3-pp311-pypy311_pp73-manylinux_2_31_riscv64.whl", hash = "sha256:5e8d07bddee435a2ff6f1920e18feff28d0bc4533e42f4bf6927fbd073312c41", size = 393235, upload-time = "2026-06-30T07:17:44.637Z" }, - { url = "https://files.pythonhosted.org/packages/62/90/8c139ee9690f73b0829f32647de6f40d826f8f443af6fa72644f96351aac/rpds_py-2026.6.3-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl", hash = "sha256:3a83ae6c67b7676b9878378547ca8e93ed77a580037bcbcd1d32f739e1e6089c", size = 413008, upload-time = "2026-06-30T07:17:46.225Z" }, - { url = "https://files.pythonhosted.org/packages/9c/97/0043896fdd7828ce09a1d9a8b06433714d0960fc4ff3fc4aa72b666b764e/rpds_py-2026.6.3-pp311-pypy311_pp73-musllinux_1_2_aarch64.whl", hash = "sha256:2bfd04c19ddbd6640de0b51894d764bd2758854d5b75bd102d2ef10cb9c293a9", size = 558118, upload-time = "2026-06-30T07:17:47.759Z" }, - { url = "https://files.pythonhosted.org/packages/f6/40/02355f0e134f783a8f9814c4680a1bd311d37671577a5964ea838573ff37/rpds_py-2026.6.3-pp311-pypy311_pp73-musllinux_1_2_i686.whl", hash = "sha256:ca6546b66be9dc4738b1b043d5ebd5488c66c578c5ff0fd0e8065313fe3afb76", size = 623138, upload-time = "2026-06-30T07:17:49.355Z" }, - { url = "https://files.pythonhosted.org/packages/10/85/48f0abdcef5cce4e034c7a5b0ceeceba0b01bf0d942824f4bb720afe2dec/rpds_py-2026.6.3-pp311-pypy311_pp73-musllinux_1_2_x86_64.whl", hash = "sha256:8e65860d238379ed982fd9ba690579b5e95af2f4840f99c772816dbe573cb826", size = 586486, upload-time = "2026-06-30T07:17:51.141Z" }, ] [[package]] @@ -1121,60 +1010,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/32/46/9cb0e58b2deb7f82b84065f37f3bffeb12413f947f9388e4cac22c4621ce/sortedcontainers-2.4.0-py2.py3-none-any.whl", hash = "sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0", size = 29575, upload-time = "2021-05-16T22:03:41.177Z" }, ] -[[package]] -name = "tomli" -version = "2.4.1" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/22/de/48c59722572767841493b26183a0d1cc411d54fd759c5607c4590b6563a6/tomli-2.4.1.tar.gz", hash = "sha256:7c7e1a961a0b2f2472c1ac5b69affa0ae1132c39adcb67aba98568702b9cc23f", size = 17543, upload-time = "2026-03-25T20:22:03.828Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/f4/11/db3d5885d8528263d8adc260bb2d28ebf1270b96e98f0e0268d32b8d9900/tomli-2.4.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:f8f0fc26ec2cc2b965b7a3b87cd19c5c6b8c5e5f436b984e85f486d652285c30", size = 154704, upload-time = "2026-03-25T20:21:10.473Z" }, - { url = "https://files.pythonhosted.org/packages/6d/f7/675db52c7e46064a9aa928885a9b20f4124ecb9bc2e1ce74c9106648d202/tomli-2.4.1-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4ab97e64ccda8756376892c53a72bd1f964e519c77236368527f758fbc36a53a", size = 149454, upload-time = "2026-03-25T20:21:12.036Z" }, - { url = "https://files.pythonhosted.org/packages/61/71/81c50943cf953efa35bce7646caab3cf457a7d8c030b27cfb40d7235f9ee/tomli-2.4.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:96481a5786729fd470164b47cdb3e0e58062a496f455ee41b4403be77cb5a076", size = 237561, upload-time = "2026-03-25T20:21:13.098Z" }, - { url = "https://files.pythonhosted.org/packages/48/c1/f41d9cb618acccca7df82aaf682f9b49013c9397212cb9f53219e3abac37/tomli-2.4.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:5a881ab208c0baf688221f8cecc5401bd291d67e38a1ac884d6736cbcd8247e9", size = 243824, upload-time = "2026-03-25T20:21:14.569Z" }, - { url = "https://files.pythonhosted.org/packages/22/e4/5a816ecdd1f8ca51fb756ef684b90f2780afc52fc67f987e3c61d800a46d/tomli-2.4.1-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:47149d5bd38761ac8be13a84864bf0b7b70bc051806bc3669ab1cbc56216b23c", size = 242227, upload-time = "2026-03-25T20:21:15.712Z" }, - { url = "https://files.pythonhosted.org/packages/6b/49/2b2a0ef529aa6eec245d25f0c703e020a73955ad7edf73e7f54ddc608aa5/tomli-2.4.1-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:ec9bfaf3ad2df51ace80688143a6a4ebc09a248f6ff781a9945e51937008fcbc", size = 247859, upload-time = "2026-03-25T20:21:17.001Z" }, - { url = "https://files.pythonhosted.org/packages/83/bd/6c1a630eaca337e1e78c5903104f831bda934c426f9231429396ce3c3467/tomli-2.4.1-cp311-cp311-win32.whl", hash = "sha256:ff2983983d34813c1aeb0fa89091e76c3a22889ee83ab27c5eeb45100560c049", size = 97204, upload-time = "2026-03-25T20:21:18.079Z" }, - { url = "https://files.pythonhosted.org/packages/42/59/71461df1a885647e10b6bb7802d0b8e66480c61f3f43079e0dcd315b3954/tomli-2.4.1-cp311-cp311-win_amd64.whl", hash = "sha256:5ee18d9ebdb417e384b58fe414e8d6af9f4e7a0ae761519fb50f721de398dd4e", size = 108084, upload-time = "2026-03-25T20:21:18.978Z" }, - { url = "https://files.pythonhosted.org/packages/b8/83/dceca96142499c069475b790e7913b1044c1a4337e700751f48ed723f883/tomli-2.4.1-cp311-cp311-win_arm64.whl", hash = "sha256:c2541745709bad0264b7d4705ad453b76ccd191e64aa6f0fc66b69a293a45ece", size = 95285, upload-time = "2026-03-25T20:21:20.309Z" }, - { url = "https://files.pythonhosted.org/packages/c1/ba/42f134a3fe2b370f555f44b1d72feebb94debcab01676bf918d0cb70e9aa/tomli-2.4.1-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:c742f741d58a28940ce01d58f0ab2ea3ced8b12402f162f4d534dfe18ba1cd6a", size = 155924, upload-time = "2026-03-25T20:21:21.626Z" }, - { url = "https://files.pythonhosted.org/packages/dc/c7/62d7a17c26487ade21c5422b646110f2162f1fcc95980ef7f63e73c68f14/tomli-2.4.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:7f86fd587c4ed9dd76f318225e7d9b29cfc5a9d43de44e5754db8d1128487085", size = 150018, upload-time = "2026-03-25T20:21:23.002Z" }, - { url = "https://files.pythonhosted.org/packages/5c/05/79d13d7c15f13bdef410bdd49a6485b1c37d28968314eabee452c22a7fda/tomli-2.4.1-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:ff18e6a727ee0ab0388507b89d1bc6a22b138d1e2fa56d1ad494586d61d2eae9", size = 244948, upload-time = "2026-03-25T20:21:24.04Z" }, - { url = "https://files.pythonhosted.org/packages/10/90/d62ce007a1c80d0b2c93e02cab211224756240884751b94ca72df8a875ca/tomli-2.4.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:136443dbd7e1dee43c68ac2694fde36b2849865fa258d39bf822c10e8068eac5", size = 253341, upload-time = "2026-03-25T20:21:25.177Z" }, - { url = "https://files.pythonhosted.org/packages/1a/7e/caf6496d60152ad4ed09282c1885cca4eea150bfd007da84aea07bcc0a3e/tomli-2.4.1-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:5e262d41726bc187e69af7825504c933b6794dc3fbd5945e41a79bb14c31f585", size = 248159, upload-time = "2026-03-25T20:21:26.364Z" }, - { url = "https://files.pythonhosted.org/packages/99/e7/c6f69c3120de34bbd882c6fba7975f3d7a746e9218e56ab46a1bc4b42552/tomli-2.4.1-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:5cb41aa38891e073ee49d55fbc7839cfdb2bc0e600add13874d048c94aadddd1", size = 253290, upload-time = "2026-03-25T20:21:27.46Z" }, - { url = "https://files.pythonhosted.org/packages/d6/2f/4a3c322f22c5c66c4b836ec58211641a4067364f5dcdd7b974b4c5da300c/tomli-2.4.1-cp312-cp312-win32.whl", hash = "sha256:da25dc3563bff5965356133435b757a795a17b17d01dbc0f42fb32447ddfd917", size = 98141, upload-time = "2026-03-25T20:21:28.492Z" }, - { url = "https://files.pythonhosted.org/packages/24/22/4daacd05391b92c55759d55eaee21e1dfaea86ce5c571f10083360adf534/tomli-2.4.1-cp312-cp312-win_amd64.whl", hash = "sha256:52c8ef851d9a240f11a88c003eacb03c31fc1c9c4ec64a99a0f922b93874fda9", size = 108847, upload-time = "2026-03-25T20:21:29.386Z" }, - { url = "https://files.pythonhosted.org/packages/68/fd/70e768887666ddd9e9f5d85129e84910f2db2796f9096aa02b721a53098d/tomli-2.4.1-cp312-cp312-win_arm64.whl", hash = "sha256:f758f1b9299d059cc3f6546ae2af89670cb1c4d48ea29c3cacc4fe7de3058257", size = 95088, upload-time = "2026-03-25T20:21:30.677Z" }, - { url = "https://files.pythonhosted.org/packages/07/06/b823a7e818c756d9a7123ba2cda7d07bc2dd32835648d1a7b7b7a05d848d/tomli-2.4.1-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:36d2bd2ad5fb9eaddba5226aa02c8ec3fa4f192631e347b3ed28186d43be6b54", size = 155866, upload-time = "2026-03-25T20:21:31.65Z" }, - { url = "https://files.pythonhosted.org/packages/14/6f/12645cf7f08e1a20c7eb8c297c6f11d31c1b50f316a7e7e1e1de6e2e7b7e/tomli-2.4.1-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:eb0dc4e38e6a1fd579e5d50369aa2e10acfc9cace504579b2faabb478e76941a", size = 149887, upload-time = "2026-03-25T20:21:33.028Z" }, - { url = "https://files.pythonhosted.org/packages/5c/e0/90637574e5e7212c09099c67ad349b04ec4d6020324539297b634a0192b0/tomli-2.4.1-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:c7f2c7f2b9ca6bdeef8f0fa897f8e05085923eb091721675170254cbc5b02897", size = 243704, upload-time = "2026-03-25T20:21:34.51Z" }, - { url = "https://files.pythonhosted.org/packages/10/8f/d3ddb16c5a4befdf31a23307f72828686ab2096f068eaf56631e136c1fdd/tomli-2.4.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:f3c6818a1a86dd6dca7ddcaaf76947d5ba31aecc28cb1b67009a5877c9a64f3f", size = 251628, upload-time = "2026-03-25T20:21:36.012Z" }, - { url = "https://files.pythonhosted.org/packages/e3/f1/dbeeb9116715abee2485bf0a12d07a8f31af94d71608c171c45f64c0469d/tomli-2.4.1-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:d312ef37c91508b0ab2cee7da26ec0b3ed2f03ce12bd87a588d771ae15dcf82d", size = 247180, upload-time = "2026-03-25T20:21:37.136Z" }, - { url = "https://files.pythonhosted.org/packages/d3/74/16336ffd19ed4da28a70959f92f506233bd7cfc2332b20bdb01591e8b1d1/tomli-2.4.1-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:51529d40e3ca50046d7606fa99ce3956a617f9b36380da3b7f0dd3dd28e68cb5", size = 251674, upload-time = "2026-03-25T20:21:38.298Z" }, - { url = "https://files.pythonhosted.org/packages/16/f9/229fa3434c590ddf6c0aa9af64d3af4b752540686cace29e6281e3458469/tomli-2.4.1-cp313-cp313-win32.whl", hash = "sha256:2190f2e9dd7508d2a90ded5ed369255980a1bcdd58e52f7fe24b8162bf9fedbd", size = 97976, upload-time = "2026-03-25T20:21:39.316Z" }, - { url = "https://files.pythonhosted.org/packages/6a/1e/71dfd96bcc1c775420cb8befe7a9d35f2e5b1309798f009dca17b7708c1e/tomli-2.4.1-cp313-cp313-win_amd64.whl", hash = "sha256:8d65a2fbf9d2f8352685bc1364177ee3923d6baf5e7f43ea4959d7d8bc326a36", size = 108755, upload-time = "2026-03-25T20:21:40.248Z" }, - { url = "https://files.pythonhosted.org/packages/83/7a/d34f422a021d62420b78f5c538e5b102f62bea616d1d75a13f0a88acb04a/tomli-2.4.1-cp313-cp313-win_arm64.whl", hash = "sha256:4b605484e43cdc43f0954ddae319fb75f04cc10dd80d830540060ee7cd0243cd", size = 95265, upload-time = "2026-03-25T20:21:41.219Z" }, - { url = "https://files.pythonhosted.org/packages/3c/fb/9a5c8d27dbab540869f7c1f8eb0abb3244189ce780ba9cd73f3770662072/tomli-2.4.1-cp314-cp314-macosx_10_15_x86_64.whl", hash = "sha256:fd0409a3653af6c147209d267a0e4243f0ae46b011aa978b1080359fddc9b6cf", size = 155726, upload-time = "2026-03-25T20:21:42.23Z" }, - { url = "https://files.pythonhosted.org/packages/62/05/d2f816630cc771ad836af54f5001f47a6f611d2d39535364f148b6a92d6b/tomli-2.4.1-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:a120733b01c45e9a0c34aeef92bf0cf1d56cfe81ed9d47d562f9ed591a9828ac", size = 149859, upload-time = "2026-03-25T20:21:43.386Z" }, - { url = "https://files.pythonhosted.org/packages/ce/48/66341bdb858ad9bd0ceab5a86f90eddab127cf8b046418009f2125630ecb/tomli-2.4.1-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:559db847dc486944896521f68d8190be1c9e719fced785720d2216fe7022b662", size = 244713, upload-time = "2026-03-25T20:21:44.474Z" }, - { url = "https://files.pythonhosted.org/packages/df/6d/c5fad00d82b3c7a3ab6189bd4b10e60466f22cfe8a08a9394185c8a8111c/tomli-2.4.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:01f520d4f53ef97964a240a035ec2a869fe1a37dde002b57ebc4417a27ccd853", size = 252084, upload-time = "2026-03-25T20:21:45.62Z" }, - { url = "https://files.pythonhosted.org/packages/00/71/3a69e86f3eafe8c7a59d008d245888051005bd657760e96d5fbfb0b740c2/tomli-2.4.1-cp314-cp314-musllinux_1_2_aarch64.whl", hash = "sha256:7f94b27a62cfad8496c8d2513e1a222dd446f095fca8987fceef261225538a15", size = 247973, upload-time = "2026-03-25T20:21:46.937Z" }, - { url = "https://files.pythonhosted.org/packages/67/50/361e986652847fec4bd5e4a0208752fbe64689c603c7ae5ea7cb16b1c0ca/tomli-2.4.1-cp314-cp314-musllinux_1_2_x86_64.whl", hash = "sha256:ede3e6487c5ef5d28634ba3f31f989030ad6af71edfb0055cbbd14189ff240ba", size = 256223, upload-time = "2026-03-25T20:21:48.467Z" }, - { url = "https://files.pythonhosted.org/packages/8c/9a/b4173689a9203472e5467217e0154b00e260621caa227b6fa01feab16998/tomli-2.4.1-cp314-cp314-win32.whl", hash = "sha256:3d48a93ee1c9b79c04bb38772ee1b64dcf18ff43085896ea460ca8dec96f35f6", size = 98973, upload-time = "2026-03-25T20:21:49.526Z" }, - { url = "https://files.pythonhosted.org/packages/14/58/640ac93bf230cd27d002462c9af0d837779f8773bc03dee06b5835208214/tomli-2.4.1-cp314-cp314-win_amd64.whl", hash = "sha256:88dceee75c2c63af144e456745e10101eb67361050196b0b6af5d717254dddf7", size = 109082, upload-time = "2026-03-25T20:21:50.506Z" }, - { url = "https://files.pythonhosted.org/packages/d5/2f/702d5e05b227401c1068f0d386d79a589bb12bf64c3d2c72ce0631e3bc49/tomli-2.4.1-cp314-cp314-win_arm64.whl", hash = "sha256:b8c198f8c1805dc42708689ed6864951fd2494f924149d3e4bce7710f8eb5232", size = 96490, upload-time = "2026-03-25T20:21:51.474Z" }, - { url = "https://files.pythonhosted.org/packages/45/4b/b877b05c8ba62927d9865dd980e34a755de541eb65fffba52b4cc495d4d2/tomli-2.4.1-cp314-cp314t-macosx_10_15_x86_64.whl", hash = "sha256:d4d8fe59808a54658fcc0160ecfb1b30f9089906c50b23bcb4c69eddc19ec2b4", size = 164263, upload-time = "2026-03-25T20:21:52.543Z" }, - { url = "https://files.pythonhosted.org/packages/24/79/6ab420d37a270b89f7195dec5448f79400d9e9c1826df982f3f8e97b24fd/tomli-2.4.1-cp314-cp314t-macosx_11_0_arm64.whl", hash = "sha256:7008df2e7655c495dd12d2a4ad038ff878d4ca4b81fccaf82b714e07eae4402c", size = 160736, upload-time = "2026-03-25T20:21:53.674Z" }, - { url = "https://files.pythonhosted.org/packages/02/e0/3630057d8eb170310785723ed5adcdfb7d50cb7e6455f85ba8a3deed642b/tomli-2.4.1-cp314-cp314t-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:1d8591993e228b0c930c4bb0db464bdad97b3289fb981255d6c9a41aedc84b2d", size = 270717, upload-time = "2026-03-25T20:21:55.129Z" }, - { url = "https://files.pythonhosted.org/packages/7a/b4/1613716072e544d1a7891f548d8f9ec6ce2faf42ca65acae01d76ea06bb0/tomli-2.4.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:734e20b57ba95624ecf1841e72b53f6e186355e216e5412de414e3c51e5e3c41", size = 278461, upload-time = "2026-03-25T20:21:56.228Z" }, - { url = "https://files.pythonhosted.org/packages/05/38/30f541baf6a3f6df77b3df16b01ba319221389e2da59427e221ef417ac0c/tomli-2.4.1-cp314-cp314t-musllinux_1_2_aarch64.whl", hash = "sha256:8a650c2dbafa08d42e51ba0b62740dae4ecb9338eefa093aa5c78ceb546fcd5c", size = 274855, upload-time = "2026-03-25T20:21:57.653Z" }, - { url = "https://files.pythonhosted.org/packages/77/a3/ec9dd4fd2c38e98de34223b995a3b34813e6bdadf86c75314c928350ed14/tomli-2.4.1-cp314-cp314t-musllinux_1_2_x86_64.whl", hash = "sha256:504aa796fe0569bb43171066009ead363de03675276d2d121ac1a4572397870f", size = 283144, upload-time = "2026-03-25T20:21:59.089Z" }, - { url = "https://files.pythonhosted.org/packages/ef/be/605a6261cac79fba2ec0c9827e986e00323a1945700969b8ee0b30d85453/tomli-2.4.1-cp314-cp314t-win32.whl", hash = "sha256:b1d22e6e9387bf4739fbe23bfa80e93f6b0373a7f1b96c6227c32bef95a4d7a8", size = 108683, upload-time = "2026-03-25T20:22:00.214Z" }, - { url = "https://files.pythonhosted.org/packages/12/64/da524626d3b9cc40c168a13da8335fe1c51be12c0a63685cc6db7308daae/tomli-2.4.1-cp314-cp314t-win_amd64.whl", hash = "sha256:2c1c351919aca02858f740c6d33adea0c5deea37f9ecca1cc1ef9e884a619d26", size = 121196, upload-time = "2026-03-25T20:22:01.169Z" }, - { url = "https://files.pythonhosted.org/packages/5a/cd/e80b62269fc78fc36c9af5a6b89c835baa8af28ff5ad28c7028d60860320/tomli-2.4.1-cp314-cp314t-win_arm64.whl", hash = "sha256:eab21f45c7f66c13f2a9e0e1535309cee140182a9cdae1e041d02e47291e8396", size = 100393, upload-time = "2026-03-25T20:22:02.137Z" }, - { url = "https://files.pythonhosted.org/packages/7b/61/cceae43728b7de99d9b847560c262873a1f6c98202171fd5ed62640b494b/tomli-2.4.1-py3-none-any.whl", hash = "sha256:0d85819802132122da43cb86656f8d1f8c6587d54ae7dcaf30e90533028b49fe", size = 14583, upload-time = "2026-03-25T20:22:03.012Z" }, -] - [[package]] name = "traitlets" version = "5.16.1" From ddbf23bee4c46ee320be34bdef103fa600964793 Mon Sep 17 00:00:00 2001 From: Dag Brattli Date: Thu, 12 Nov 2026 02:31:57 +0100 Subject: [PATCH 2/2] refactor: place pipeline error type parameter last --- expression/extra/result/pipeline.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/expression/extra/result/pipeline.py b/expression/extra/result/pipeline.py index ca259142..332eed87 100644 --- a/expression/extra/result/pipeline.py +++ b/expression/extra/result/pipeline.py @@ -14,14 +14,14 @@ def pipeline[A, B, TError](__fn: Callable[[A], Result[B, TError]]) -> Callable[[ @overload -def pipeline[A, B, TError, C]( +def pipeline[A, B, C, TError]( __fn1: Callable[[A], Result[B, TError]], __fn2: Callable[[B], Result[C, TError]], ) -> Callable[[A], Result[C, TError]]: ... @overload -def pipeline[A, B, TError, C, D]( +def pipeline[A, B, C, D, TError]( __fn1: Callable[[A], Result[B, TError]], __fn2: Callable[[B], Result[C, TError]], __fn3: Callable[[C], Result[D, TError]], @@ -29,7 +29,7 @@ def pipeline[A, B, TError, C, D]( @overload -def pipeline[A, B, TError, C, D, E]( +def pipeline[A, B, C, D, E, TError]( __fn1: Callable[[A], Result[B, TError]], __fn2: Callable[[B], Result[C, TError]], __fn3: Callable[[C], Result[D, TError]], @@ -38,7 +38,7 @@ def pipeline[A, B, TError, C, D, E]( @overload -def pipeline[A, B, TError, C, D, E, F]( +def pipeline[A, B, C, D, E, F, TError]( __fn1: Callable[[A], Result[B, TError]], __fn2: Callable[[B], Result[C, TError]], __fn3: Callable[[C], Result[D, TError]], @@ -48,7 +48,7 @@ def pipeline[A, B, TError, C, D, E, F]( @overload -def pipeline[A, B, TError, C, D, E, F, G]( +def pipeline[A, B, C, D, E, F, G, TError]( __fn1: Callable[[A], Result[B, TError]], __fn2: Callable[[B], Result[C, TError]], __fn3: Callable[[C], Result[D, TError]],