Skip to content

Commit

Permalink
try first
Browse files Browse the repository at this point in the history
  • Loading branch information
phi-friday authored and dbrattli committed Aug 13, 2024
1 parent 0b5139e commit e7cd062
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 59 deletions.
10 changes: 6 additions & 4 deletions expression/collections/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import functools
import itertools
from collections.abc import Callable, Collection, Iterable, Iterator, Sequence
from typing import TYPE_CHECKING, Any, Literal, TypeVar, TypeVarTuple, get_args, overload
from typing import TYPE_CHECKING, Any, Literal, TypeVar, get_args, overload

from typing_extensions import TypeVarTuple, Unpack


if TYPE_CHECKING:
Expand Down Expand Up @@ -237,7 +239,7 @@ def map(self, mapping: Callable[[_TSource], _TResult]) -> Block[_TResult]:
"""
return Block((*builtins.map(mapping, self),))

def starmap(self: Block[tuple[*_P]], mapping: Callable[[*_P], _TResult]) -> Block[_TResult]:
def starmap(self: Block[tuple[Unpack[_P]]], mapping: Callable[[Unpack[_P]], _TResult]) -> Block[_TResult]:
"""Starmap source sequence.
Unpack arguments grouped as tuple elements. Builds a new collection
Expand Down Expand Up @@ -746,7 +748,7 @@ def reduce(
return source.tail().fold(reduction, source.head())


def starmap(mapper: Callable[[*_P], _TResult]) -> Callable[[Block[tuple[*_P]]], Block[_TResult]]:
def starmap(mapper: Callable[[Unpack[_P]], _TResult]) -> Callable[[Block[tuple[Unpack[_P]]]], Block[_TResult]]:
"""Starmap source sequence.
Unpack arguments grouped as tuple elements. Builds a new collection
Expand All @@ -760,7 +762,7 @@ def starmap(mapper: Callable[[*_P], _TResult]) -> Callable[[Block[tuple[*_P]]],
Partially applied map function.
"""

def mapper_(args: tuple[*_P]) -> _TResult:
def mapper_(args: tuple[Unpack[_P]]) -> _TResult:
return mapper(*args)

return map(mapper_)
Expand Down
26 changes: 16 additions & 10 deletions expression/core/compose.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from collections.abc import Callable
from functools import reduce
from typing import Any, TypeVar, TypeVarTuple, overload
from typing import Any, TypeVar, overload

from typing_extensions import TypeVarTuple, Unpack


_A = TypeVar("_A")
Expand Down Expand Up @@ -139,26 +141,30 @@ def starcompose() -> Callable[[Any], Any]: ...


@overload
def starcompose(__fn1: Callable[[*_P], _A]) -> Callable[[*_P], _A]: ...
def starcompose(__fn1: Callable[[Unpack[_P]], _A]) -> Callable[[Unpack[_P]], _A]: ...


@overload
def starcompose(__fn1: Callable[[*_P], tuple[*_Y]], __fn2: Callable[[*_Y], _B]) -> Callable[[*_P], _B]: ...
def starcompose(
__fn1: Callable[[Unpack[_P]], tuple[Unpack[_Y]]], __fn2: Callable[[Unpack[_Y]], _B]
) -> Callable[[Unpack[_P]], _B]: ...


@overload
def starcompose(
__fn1: Callable[[*_P], tuple[*_Y]], __fn2: Callable[[*_Y], tuple[*_Z]], __fn3: Callable[[*_Z], _C]
) -> Callable[[*_P], _C]: ...
__fn1: Callable[[Unpack[_P]], tuple[Unpack[_Y]]],
__fn2: Callable[[Unpack[_Y]], tuple[Unpack[_Z]]],
__fn3: Callable[[Unpack[_Z]], _C],
) -> Callable[[Unpack[_P]], _C]: ...


@overload
def starcompose(
__fn1: Callable[[*_P], tuple[*_Y]],
__fn2: Callable[[*_Y], tuple[*_Z]],
__fn3: Callable[[*_Z], tuple[*_X]],
__fn4: Callable[[*_X], _D],
) -> Callable[[*_P], _D]: ...
__fn1: Callable[[Unpack[_P]], tuple[Unpack[_Y]]],
__fn2: Callable[[Unpack[_Y]], tuple[Unpack[_Z]]],
__fn3: Callable[[Unpack[_Z]], tuple[Unpack[_X]]],
__fn4: Callable[[Unpack[_X]], _D],
) -> Callable[[Unpack[_P]], _D]: ...


def starcompose(*fns: Callable[..., Any]) -> Callable[..., Any]:
Expand Down
4 changes: 2 additions & 2 deletions expression/core/misc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections.abc import Callable
from typing import Any, TypeVar

from typing_extensions import TypeVarTuple
from typing_extensions import TypeVarTuple, Unpack


_A = TypeVar("_A")
Expand All @@ -19,7 +19,7 @@ def identity(value: _A) -> _A:
return value


def starid(*value: *_P) -> tuple[*_P]:
def starid(*value: Unpack[_P]) -> tuple[Unpack[_P]]:
return value


Expand Down
8 changes: 5 additions & 3 deletions expression/core/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

import builtins
from collections.abc import Callable, Generator, Iterable
from typing import TYPE_CHECKING, Any, Literal, TypeGuard, TypeVar, TypeVarTuple, get_args, get_origin
from typing import TYPE_CHECKING, Any, Literal, TypeGuard, TypeVar, get_args, get_origin

from typing_extensions import TypeVarTuple, Unpack

from .curry import curry_flip
from .error import EffectError
Expand Down Expand Up @@ -106,7 +108,7 @@ def map2(self, mapper: Callable[[_TSource, _T2], _TResult], other: Option[_T2])
case _:
return Nothing

def starmap(self: Option[tuple[*_P]], mapper: Callable[[*_P], _TResult]) -> Option[_TResult]:
def starmap(self: Option[tuple[Unpack[_P]]], mapper: Callable[[Unpack[_P]], _TResult]) -> Option[_TResult]:
"""Starmap option.
Applies the mapper to the values if the option is Some,
Expand Down Expand Up @@ -431,7 +433,7 @@ def map2(opt1: Option[_T1], opt2: Option[_T2], mapper: Callable[[_T1, _T2], _TRe


@curry_flip(1)
def starmap(option: Option[tuple[*_P]], mapper: Callable[[*_P], _TResult]) -> Option[_TResult]:
def starmap(option: Option[tuple[Unpack[_P]]], mapper: Callable[[*_P], _TResult]) -> Option[_TResult]:
return option.starmap(mapper)


Expand Down
54 changes: 29 additions & 25 deletions expression/core/pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"""

from collections.abc import Callable
from typing import Any, TypeVar, TypeVarTuple, cast, overload
from typing import Any, TypeVar, cast, overload

from typing_extensions import TypeVarTuple, Unpack

from .compose import compose, starcompose
from .misc import starid
Expand Down Expand Up @@ -181,52 +183,54 @@ def pipe3(__values: Any, *fns: Any) -> Any:


@overload
def starpipe(__args: tuple[*_P], __fn1: Callable[[*_P], _B]) -> _B: ...
def starpipe(__args: tuple[Unpack[_P]], __fn1: Callable[[Unpack[_P]], _B]) -> _B: ...


@overload
def starpipe(__args: tuple[*_P], __fn1: Callable[[*_P], tuple[*_Q]], __fn2: Callable[[*_Q], _B]) -> _B: ...
def starpipe(
__args: tuple[Unpack[_P]], __fn1: Callable[[Unpack[_P]], tuple[Unpack[_Q]]], __fn2: Callable[[*_Q], _B]
) -> _B: ...


@overload
def starpipe(
__args: tuple[*_P],
__fn1: Callable[[*_P], tuple[*_Q]],
__fn2: Callable[[*_Q], tuple[*_X]],
__fn3: Callable[[*_X], _B],
__args: tuple[Unpack[_P]],
__fn1: Callable[[Unpack[_P]], tuple[Unpack[_Q]]],
__fn2: Callable[[Unpack[_Q]], tuple[Unpack[_X]]],
__fn3: Callable[[Unpack[_X]], _B],
) -> _B: ...


@overload
def starpipe(
__args: tuple[*_P],
__fn1: Callable[[*_P], tuple[*_Q]],
__fn2: Callable[[*_Q], tuple[*_X]],
__fn3: Callable[[*_X], tuple[*_Y]],
__fn4: Callable[[*_Y], _B],
__args: tuple[Unpack[_P]],
__fn1: Callable[[Unpack[_P]], tuple[Unpack[_Q]]],
__fn2: Callable[[Unpack[_Q]], tuple[Unpack[_X]]],
__fn3: Callable[[Unpack[_X]], tuple[Unpack[_Y]]],
__fn4: Callable[[Unpack[_Y]], _B],
) -> _B: ...


@overload
def starpipe(
__args: tuple[*_P],
__fn1: Callable[[*_P], tuple[*_Q]],
__fn2: Callable[[*_Q], tuple[*_X]],
__fn3: Callable[[*_X], tuple[*_Y]],
__fn4: Callable[[*_Y], tuple[*_Z]],
__fn5: Callable[[*_Z], _B],
__args: tuple[Unpack[_P]],
__fn1: Callable[[Unpack[_P]], tuple[Unpack[_Q]]],
__fn2: Callable[[Unpack[_Q]], tuple[Unpack[_X]]],
__fn3: Callable[[Unpack[_X]], tuple[Unpack[_Y]]],
__fn4: Callable[[Unpack[_Y]], tuple[Unpack[_Z]]],
__fn5: Callable[[Unpack[_Z]], _B],
) -> _B: ...


@overload
def starpipe(
__args: tuple[*_P],
__fn1: Callable[[*_P], tuple[*_Q]],
__fn2: Callable[[*_Q], tuple[*_X]],
__fn3: Callable[[*_X], tuple[*_Y]],
__fn4: Callable[[*_Y], tuple[*_Z]],
__fn5: Callable[[*_Z], tuple[*_K]],
__fn6: Callable[[*_K], _B],
__args: tuple[Unpack[_P]],
__fn1: Callable[[Unpack[_P]], tuple[Unpack[_Q]]],
__fn2: Callable[[Unpack[_Q]], tuple[Unpack[_X]]],
__fn3: Callable[[Unpack[_X]], tuple[Unpack[_Y]]],
__fn4: Callable[[Unpack[_Y]], tuple[Unpack[_Z]]],
__fn5: Callable[[Unpack[_Z]], tuple[Unpack[_K]]],
__fn6: Callable[[Unpack[_K]], _B],
) -> _B: ...


Expand Down
4 changes: 3 additions & 1 deletion expression/core/tagged_union.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from collections.abc import Callable
from copy import deepcopy
from dataclasses import dataclass, field, fields
from typing import Any, TypeVar, dataclass_transform, overload
from typing import Any, TypeVar, overload

from typing_extensions import dataclass_transform


_T = TypeVar("_T")
Expand Down
50 changes: 39 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ classifiers = [
]

[tool.poetry.dependencies]
python = ">= 3.11, < 4"
python = ">= 3.10, < 4"
typing-extensions = "^4.10.0"

pydantic = {version = "^2.6.2", optional = true}
Expand All @@ -43,7 +43,7 @@ all = ["pydantic"]
[tool.ruff]
# Keep in sync with .pre-commit-config.yaml
line-length = 120
target-version = "py311"
target-version = "py310"
# D100: Missing docstring in public module
# D104: Missing docstring in public package
# D105: Missing docstring in magic method
Expand Down
2 changes: 1 addition & 1 deletion pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"reportImportCycles": false,
"reportMissingImports": false,
"pythonVersion": "3.11",
"pythonVersion": "3.10",
"typeCheckingMode": "strict",
"reportShadowedImports": "none",
"venv": ".venv",
Expand Down

0 comments on commit e7cd062

Please sign in to comment.