diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b7c16e2ac..521c6ee7d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -73,7 +73,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ['3.9', '3.10', '3.11', '3.12'] + python-version: ['3.10', '3.11', '3.12', '3.13'] shard: [0, 1, 2, 3] steps: diff --git a/returns/_internal/futures/_future.py b/returns/_internal/futures/_future.py index 6c59c3504..c0c8f6850 100644 --- a/returns/_internal/futures/_future.py +++ b/returns/_internal/futures/_future.py @@ -1,4 +1,5 @@ -from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar +from collections.abc import Awaitable, Callable +from typing import TYPE_CHECKING, TypeVar from returns.io import IO from returns.primitives.hkt import Kind1, dekind diff --git a/returns/_internal/futures/_future_result.py b/returns/_internal/futures/_future_result.py index 36c81bb0d..d6ca49d07 100644 --- a/returns/_internal/futures/_future_result.py +++ b/returns/_internal/futures/_future_result.py @@ -1,4 +1,5 @@ -from typing import TYPE_CHECKING, Any, Awaitable, Callable, TypeVar +from collections.abc import Awaitable, Callable +from typing import TYPE_CHECKING, Any, TypeVar from returns.io import IO, IOResult from returns.primitives.hkt import Kind2, dekind diff --git a/returns/_internal/futures/_reader_future_result.py b/returns/_internal/futures/_reader_future_result.py index b9468d2be..710dddf6c 100644 --- a/returns/_internal/futures/_reader_future_result.py +++ b/returns/_internal/futures/_reader_future_result.py @@ -1,4 +1,5 @@ -from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar +from collections.abc import Awaitable, Callable +from typing import TYPE_CHECKING, TypeVar from returns.primitives.hkt import Kind3, dekind from returns.result import Result, Success diff --git a/returns/_internal/pipeline/managed.py b/returns/_internal/pipeline/managed.py index 2dc27ba8a..d5c44c909 100644 --- a/returns/_internal/pipeline/managed.py +++ b/returns/_internal/pipeline/managed.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.specific.ioresult import IOResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/context/requires_context.py b/returns/context/requires_context.py index 167396a71..46e6434b4 100644 --- a/returns/context/requires_context.py +++ b/returns/context/requires_context.py @@ -1,8 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Callable, ClassVar, TypeVar, final - -from typing_extensions import TypeAlias +from collections.abc import Callable +from typing import TYPE_CHECKING, Any, ClassVar, TypeAlias, TypeVar, final from returns.functions import identity from returns.future import FutureResult diff --git a/returns/context/requires_context_future_result.py b/returns/context/requires_context_future_result.py index 833dadb87..bb54b5559 100644 --- a/returns/context/requires_context_future_result.py +++ b/returns/context/requires_context_future_result.py @@ -1,16 +1,7 @@ from __future__ import annotations -from typing import ( - TYPE_CHECKING, - Any, - Awaitable, - Callable, - ClassVar, - TypeVar, - final, -) - -from typing_extensions import TypeAlias +from collections.abc import Awaitable, Callable +from typing import TYPE_CHECKING, Any, ClassVar, TypeAlias, TypeVar, final from returns._internal.futures import _reader_future_result from returns.context import NoDeps diff --git a/returns/context/requires_context_ioresult.py b/returns/context/requires_context_ioresult.py index b005f47e1..b976c17e0 100644 --- a/returns/context/requires_context_ioresult.py +++ b/returns/context/requires_context_ioresult.py @@ -1,8 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Callable, ClassVar, TypeVar, final - -from typing_extensions import TypeAlias +from collections.abc import Callable +from typing import TYPE_CHECKING, Any, ClassVar, TypeAlias, TypeVar, final from returns.context import NoDeps from returns.interfaces.specific import reader_ioresult diff --git a/returns/context/requires_context_result.py b/returns/context/requires_context_result.py index 48db4af8c..285a5d37a 100644 --- a/returns/context/requires_context_result.py +++ b/returns/context/requires_context_result.py @@ -1,8 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Callable, ClassVar, TypeVar, final - -from typing_extensions import TypeAlias +from collections.abc import Callable +from typing import TYPE_CHECKING, Any, ClassVar, TypeAlias, TypeVar, final from returns.context import NoDeps from returns.interfaces.specific import reader_result diff --git a/returns/contrib/hypothesis/_entrypoint.py b/returns/contrib/hypothesis/_entrypoint.py index 77d1e0afb..8d2351117 100644 --- a/returns/contrib/hypothesis/_entrypoint.py +++ b/returns/contrib/hypothesis/_entrypoint.py @@ -10,7 +10,8 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Callable, Sequence, Type, TypeVar +from collections.abc import Callable, Sequence +from typing import TYPE_CHECKING, Any, TypeVar if TYPE_CHECKING: from returns.primitives.laws import Lawful @@ -33,7 +34,7 @@ def _setup_hook() -> None: from returns.result import Result def factory( - container_type: Type[_Inst], + container_type: type[_Inst], ) -> Callable[[Any], st.SearchStrategy[_Inst]]: def decorator(thing: Any) -> st.SearchStrategy[_Inst]: from returns.contrib.hypothesis.containers import ( @@ -44,7 +45,7 @@ def decorator(thing: Any) -> st.SearchStrategy[_Inst]: #: Our types that we register in hypothesis #: to be working with ``st.from_type`` - registered_types: Sequence[Type[Lawful]] = ( + registered_types: Sequence[type[Lawful]] = ( Result, Maybe, IO, diff --git a/returns/contrib/hypothesis/containers.py b/returns/contrib/hypothesis/containers.py index 5c61e0ce8..0842b5dfc 100644 --- a/returns/contrib/hypothesis/containers.py +++ b/returns/contrib/hypothesis/containers.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Any, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, Any, TypeVar from hypothesis import strategies as st diff --git a/returns/contrib/hypothesis/laws.py b/returns/contrib/hypothesis/laws.py index 07bfa5e01..eaab28e40 100644 --- a/returns/contrib/hypothesis/laws.py +++ b/returns/contrib/hypothesis/laws.py @@ -1,16 +1,7 @@ import inspect +from collections.abc import Callable, Iterator from contextlib import ExitStack, contextmanager -from typing import ( - Any, - Callable, - Dict, - Iterator, - NamedTuple, - Optional, - Type, - TypeVar, - final, -) +from typing import Any, NamedTuple, TypeVar, final import pytest from hypothesis import given @@ -26,14 +17,14 @@ class _Settings(NamedTuple): """Settings that we provide to an end user.""" - settings_kwargs: Dict[str, Any] + settings_kwargs: dict[str, Any] use_init: bool def check_all_laws( - container_type: Type[Lawful], + container_type: type[Lawful], *, - settings_kwargs: Optional[Dict[str, Any]] = None, + settings_kwargs: dict[str, Any] | None = None, use_init: bool = False, ) -> None: """ @@ -79,7 +70,7 @@ def check_all_laws( @contextmanager def container_strategies( - container_type: Type[Lawful], + container_type: type[Lawful], *, settings: _Settings, ) -> Iterator[None]: @@ -123,7 +114,7 @@ def container_strategies( @contextmanager def register_container( - container_type: Type['Lawful'], + container_type: type['Lawful'], *, use_init: bool, ) -> Iterator[None]: @@ -160,30 +151,25 @@ def factory(thing) -> st.SearchStrategy: if len(thing.__args__) == 1 else (lambda *args, **kwargs: None) ) + return_type = thing.__args__[-1] return st.functions( like=like, - returns=st.from_type(thing.__args__[-1]), + returns=st.from_type( + return_type + if return_type is not None + else type(None), + ), pure=True, ) - callable_type = _get_callable_type() - used = types._global_type_lookup[callable_type] - st.register_type_strategy(callable_type, factory) + used = types._global_type_lookup[Callable] # type: ignore[index] + st.register_type_strategy(Callable, factory) # type: ignore[arg-type] try: yield finally: - types._global_type_lookup.pop(callable_type) - st.register_type_strategy(callable_type, used) - - -def _get_callable_type() -> Any: - # Helper to accommodate changes in `hypothesis@6.79.0` - if Callable.__origin__ in types._global_type_lookup: # type: ignore - return Callable.__origin__ # type: ignore - elif Callable in types._global_type_lookup: # type: ignore - return Callable - raise RuntimeError('Failed to find Callable type strategy') + types._global_type_lookup.pop(Callable) # type: ignore[call-overload] + st.register_type_strategy(Callable, used) # type: ignore[arg-type] @contextmanager @@ -242,7 +228,7 @@ def _clean_caches() -> None: def _run_law( - container_type: Type[Lawful], + container_type: type[Lawful], law: Law, *, settings: _Settings, @@ -263,8 +249,8 @@ def factory(source: st.DataObject) -> None: def _create_law_test_case( - container_type: Type[Lawful], - interface: Type[Lawful], + container_type: type[Lawful], + interface: type[Lawful], law: Law, *, settings: _Settings, diff --git a/returns/contrib/mypy/_features/curry.py b/returns/contrib/mypy/_features/curry.py index 835a279bd..b74988e58 100644 --- a/returns/contrib/mypy/_features/curry.py +++ b/returns/contrib/mypy/_features/curry.py @@ -1,6 +1,7 @@ +from collections.abc import Iterator from itertools import groupby, product from operator import itemgetter -from typing import Iterator, List, Optional, Tuple, cast, final +from typing import cast, final from mypy.nodes import ARG_STAR, ARG_STAR2 from mypy.plugin import FunctionContext @@ -15,7 +16,7 @@ ) #: Raw material to build `_ArgTree`. -_RawArgTree = List[List[List[FuncArg]]] +_RawArgTree = list[list[list[FuncArg]]] def analyze(ctx: FunctionContext) -> MypyType: @@ -34,9 +35,9 @@ def analyze(ctx: FunctionContext) -> MypyType: class _ArgTree: """Represents a node in tree of arguments.""" - def __init__(self, case: Optional[CallableType]) -> None: + def __init__(self, case: CallableType | None) -> None: self.case = case - self.children: List['_ArgTree'] = [] + self.children: list['_ArgTree'] = [] @final @@ -62,7 +63,7 @@ def __init__(self, original: CallableType, ctx: FunctionContext) -> None: """ self._original = original self._ctx = ctx - self._overloads: List[CallableType] = [] + self._overloads: list[CallableType] = [] self._args = FuncArg.from_callable(self._original) # We need to get rid of generics here. @@ -112,7 +113,7 @@ def _build_argtree( """ def factory( args: _RawArgTree, - ) -> Iterator[Tuple[List[FuncArg], _RawArgTree]]: + ) -> Iterator[tuple[list[FuncArg], _RawArgTree]]: if not args or not args[0]: return # we have reached an end of arguments yield from ( @@ -159,7 +160,7 @@ def _build_overloads_from_argtree(self, argtree: _ArgTree) -> None: else: # Root is reached, we need to save the result: self._overloads.append(child.case) - def _slices(self, source: List[FuncArg]) -> Iterator[List[List[FuncArg]]]: + def _slices(self, source: list[FuncArg]) -> Iterator[list[list[FuncArg]]]: """ Generate all possible slices of a source list. diff --git a/returns/contrib/mypy/_features/do_notation.py b/returns/contrib/mypy/_features/do_notation.py index 71a0aea2b..7ff3958ff 100644 --- a/returns/contrib/mypy/_features/do_notation.py +++ b/returns/contrib/mypy/_features/do_notation.py @@ -1,4 +1,4 @@ -from typing import Final, Optional, Tuple +from typing import Final from mypy.maptype import map_instance_to_supertype from mypy.nodes import Expression, GeneratorExpr, TypeInfo @@ -86,7 +86,7 @@ def _try_fetch_error_type( type_info: TypeInfo, seq: Expression, ctx: MethodContext, -) -> Optional[MypyType]: +) -> MypyType | None: inst = Instance( type_info, [ @@ -110,7 +110,7 @@ def _try_fetch_error_type( def _extract_error_type( typ: MypyType, type_info: TypeInfo, -) -> Tuple[bool, Optional[MypyType]]: +) -> tuple[bool, MypyType | None]: typ = get_proper_type(typ) if isinstance(typ, Instance): return True, _decide_error_type( @@ -129,7 +129,7 @@ def _extract_error_type( return False, None -def _decide_error_type(typ: Instance) -> Optional[MypyType]: +def _decide_error_type(typ: Instance) -> MypyType | None: if len(typ.args) < 2: return None if isinstance(get_proper_type(typ.args[1]), AnyType): diff --git a/returns/contrib/mypy/_features/kind.py b/returns/contrib/mypy/_features/kind.py index 5b3db6956..29eadc2ef 100644 --- a/returns/contrib/mypy/_features/kind.py +++ b/returns/contrib/mypy/_features/kind.py @@ -1,5 +1,5 @@ +from collections.abc import Sequence from enum import Enum, unique -from typing import Optional, Sequence, Tuple from mypy.checkmember import analyze_member_access from mypy.plugin import ( @@ -159,8 +159,8 @@ class _KindErrors(str, Enum): # noqa: WPS600 def _crop_kind_args( kind: Instance, - limit: Optional[Sequence[MypyType]] = None, -) -> Tuple[MypyType, ...]: + limit: Sequence[MypyType] | None = None, +) -> tuple[MypyType, ...]: """Returns the correct amount of type arguments for a kind.""" if limit is None: limit = kind.args[0].args # type: ignore diff --git a/returns/contrib/mypy/_features/partial.py b/returns/contrib/mypy/_features/partial.py index 5e0d970bb..50c3069aa 100644 --- a/returns/contrib/mypy/_features/partial.py +++ b/returns/contrib/mypy/_features/partial.py @@ -1,4 +1,5 @@ -from typing import Final, Iterator, List, Optional, Tuple, final +from collections.abc import Iterator +from typing import Final, final from mypy.nodes import ARG_STAR, ARG_STAR2 from mypy.plugin import FunctionContext @@ -104,7 +105,7 @@ def __init__( self, default_return_type: FunctionLike, original: FunctionLike, - applied_args: List[FuncArg], + applied_args: list[FuncArg], ctx: FunctionContext, ) -> None: """ @@ -122,8 +123,8 @@ def __init__( self._applied_args = applied_args self._ctx = ctx - self._case_functions: List[CallableType] = [] - self._fallbacks: List[CallableType] = [] + self._case_functions: list[CallableType] = [] + self._fallbacks: list[CallableType] = [] def new_partial(self) -> ProperType: """ @@ -149,7 +150,7 @@ def new_partial(self) -> ProperType: def _create_intermediate( self, case_function: CallableType, - ) -> Tuple[CallableType, Optional[CallableType]]: + ) -> tuple[CallableType, CallableType | None]: intermediate = Intermediate(case_function).with_applied_args( self._applied_args, ) @@ -234,7 +235,7 @@ def get_callable_from_context(self) -> ProperType: self._function_ctx, )) - def build_from_context(self) -> Tuple[bool, List[FuncArg]]: + def build_from_context(self) -> tuple[bool, list[FuncArg]]: """ Builds handy arguments structures from the context. diff --git a/returns/contrib/mypy/_features/pipe.py b/returns/contrib/mypy/_features/pipe.py index 363df1a93..eb78fe4dd 100644 --- a/returns/contrib/mypy/_features/pipe.py +++ b/returns/contrib/mypy/_features/pipe.py @@ -36,7 +36,7 @@ >>> assert pipeline(0) == 'not bigger' # `signature and `infer` again """ -from typing import Callable, List, Tuple +from collections.abc import Callable from mypy.nodes import ARG_POS from mypy.plugin import FunctionContext, MethodContext, MethodSigContext @@ -116,9 +116,9 @@ def _unify_type( def _get_pipeline_def( - arg_types: List[MypyType], + arg_types: list[MypyType], ctx: FunctionContext, -) -> Tuple[ProperType, ProperType]: +) -> tuple[ProperType, ProperType]: first_step = get_proper_type(arg_types[0]) last_step = get_proper_type(arg_types[-1]) diff --git a/returns/contrib/mypy/_structures/args.py b/returns/contrib/mypy/_structures/args.py index 767f583cb..9f5988072 100644 --- a/returns/contrib/mypy/_structures/args.py +++ b/returns/contrib/mypy/_structures/args.py @@ -1,5 +1,5 @@ from collections import namedtuple -from typing import List, Optional, final +from typing import final from mypy.nodes import ArgKind, Context, TempNode from mypy.types import CallableType @@ -13,7 +13,7 @@ class FuncArg(_FuncArgStruct): """Representation of function arg with all required fields and methods.""" - name: Optional[str] + name: str | None type: MypyType # noqa: WPS125 kind: ArgKind @@ -22,7 +22,7 @@ def expression(self, context: Context) -> TempNode: return TempNode(self.type, context=context) @classmethod - def from_callable(cls, function_def: CallableType) -> List['FuncArg']: + def from_callable(cls, function_def: CallableType) -> list['FuncArg']: """Public constructor to create FuncArg lists from callables.""" parts = zip( function_def.arg_names, diff --git a/returns/contrib/mypy/_typeops/analtype.py b/returns/contrib/mypy/_typeops/analtype.py index 3ff654f92..d8ce126ae 100644 --- a/returns/contrib/mypy/_typeops/analtype.py +++ b/returns/contrib/mypy/_typeops/analtype.py @@ -1,12 +1,11 @@ from types import MappingProxyType -from typing import Final, List, Optional, overload +from typing import Final, Literal, overload from mypy.checkmember import analyze_member_access from mypy.nodes import ARG_NAMED, ARG_OPT from mypy.types import CallableType, FunctionLike, ProperType from mypy.types import Type as MypyType from mypy.types import get_proper_type -from typing_extensions import Literal from returns.contrib.mypy._structures.args import FuncArg from returns.contrib.mypy._structures.types import CallableContext @@ -23,7 +22,7 @@ @overload def analyze_call( function: FunctionLike, - args: List[FuncArg], + args: list[FuncArg], ctx: CallableContext, *, show_errors: Literal[True], @@ -34,11 +33,11 @@ def analyze_call( @overload def analyze_call( function: FunctionLike, - args: List[FuncArg], + args: list[FuncArg], ctx: CallableContext, *, show_errors: bool, -) -> Optional[CallableType]: +) -> CallableType | None: """Errors are not reported, we can get ``None`` when errors happen.""" diff --git a/returns/contrib/mypy/_typeops/fallback.py b/returns/contrib/mypy/_typeops/fallback.py index d2372276f..12941da5a 100644 --- a/returns/contrib/mypy/_typeops/fallback.py +++ b/returns/contrib/mypy/_typeops/fallback.py @@ -1,5 +1,6 @@ +from collections.abc import Callable from functools import wraps -from typing import Callable, TypeVar +from typing import TypeVar from mypy.types import AnyType, TypeOfAny diff --git a/returns/contrib/mypy/_typeops/inference.py b/returns/contrib/mypy/_typeops/inference.py index 8333415e3..8b9153750 100644 --- a/returns/contrib/mypy/_typeops/inference.py +++ b/returns/contrib/mypy/_typeops/inference.py @@ -1,4 +1,5 @@ -from typing import Iterable, List, Mapping, Optional, cast, final +from collections.abc import Iterable, Mapping +from typing import TypeAlias, cast, final from mypy.argmap import map_actuals_to_formals from mypy.constraints import infer_constraints_for_callable @@ -8,7 +9,6 @@ from mypy.types import CallableType, FunctionLike, ProperType from mypy.types import Type as MypyType from mypy.types import TypeVarId, get_proper_type -from typing_extensions import TypeAlias from returns.contrib.mypy._structures.args import FuncArg from returns.contrib.mypy._structures.types import CallableContext @@ -32,7 +32,7 @@ def __init__( case_function: CallableType, ctx: FunctionContext, *, - fallback: Optional[CallableType] = None, + fallback: CallableType | None = None, ) -> None: """ Create the callable inference. @@ -55,7 +55,7 @@ def __init__( def from_usage( self, - applied_args: List[FuncArg], + applied_args: list[FuncArg], ) -> CallableType: """Infers function constrains from its usage: passed arguments.""" constraints = self._infer_constraints(applied_args) @@ -63,7 +63,7 @@ def from_usage( def _infer_constraints( self, - applied_args: List[FuncArg], + applied_args: list[FuncArg], ) -> _Constraints: """Creates mapping of ``typevar`` to real type that we already know.""" checker = self._ctx.api.expr_checker # type: ignore diff --git a/returns/contrib/mypy/_typeops/transform_callable.py b/returns/contrib/mypy/_typeops/transform_callable.py index 0b981cc5e..7909176d5 100644 --- a/returns/contrib/mypy/_typeops/transform_callable.py +++ b/returns/contrib/mypy/_typeops/transform_callable.py @@ -1,4 +1,4 @@ -from typing import ClassVar, Dict, FrozenSet, List, final +from typing import ClassVar, final from mypy.nodes import ARG_OPT, ARG_POS, ARG_STAR, ARG_STAR2, ArgKind from mypy.typeops import get_type_vars @@ -10,7 +10,7 @@ def proper_type( - case_functions: List[CallableType], + case_functions: list[CallableType], ) -> FunctionLike: """Returns a ``CallableType`` or ``Overloaded`` based on case functions.""" if len(case_functions) == 1: @@ -28,7 +28,7 @@ class Intermediate: """ #: Positional arguments can be of this kind. - _positional_kinds: ClassVar[FrozenSet[ArgKind]] = frozenset(( + _positional_kinds: ClassVar[frozenset[ArgKind]] = frozenset(( ARG_POS, ARG_OPT, ARG_STAR, @@ -38,7 +38,7 @@ def __init__(self, case_function: CallableType) -> None: """We only need a callable to work on.""" self._case_function = case_function - def with_applied_args(self, applied_args: List[FuncArg]) -> CallableType: + def with_applied_args(self, applied_args: list[FuncArg]) -> CallableType: """ By calling this method we construct a new callable from its usage. @@ -48,7 +48,7 @@ def with_applied_args(self, applied_args: List[FuncArg]) -> CallableType: new_named_args = self._applied_named_args(applied_args) return self.with_signature(new_pos_args + new_named_args) - def with_signature(self, new_args: List[FuncArg]) -> CallableType: + def with_signature(self, new_args: list[FuncArg]) -> CallableType: """Smartly creates a new callable from a given arguments.""" return detach_callable(self._case_function.copy_modified( arg_names=[arg.name for arg in new_args], @@ -62,8 +62,8 @@ def with_ret_type(self, ret_type: MypyType) -> CallableType: def _applied_positional_args( self, - applied_args: List[FuncArg], - ) -> List[FuncArg]: + applied_args: list[FuncArg], + ) -> list[FuncArg]: callee_args = list(filter( lambda name: name.name is None, # TODO: maybe use `kind` instead? applied_args, @@ -77,8 +77,8 @@ def _applied_positional_args( def _applied_named_args( self, - applied_args: List[FuncArg], - ) -> List[FuncArg]: + applied_args: list[FuncArg], + ) -> list[FuncArg]: callee_args = list(filter( lambda name: name.name is not None, applied_args, @@ -157,7 +157,7 @@ def detach_callable(typ: CallableType) -> CallableType: # noqa: C901, WPS210 """ type_list = typ.arg_types + [typ.ret_type] - appear_map: Dict[str, List[int]] = {} + appear_map: dict[str, list[int]] = {} for idx, inner_type in enumerate(type_list): typevars_available = get_type_vars(inner_type) for var in typevars_available: # noqa: WPS110 diff --git a/returns/contrib/mypy/_typeops/visitor.py b/returns/contrib/mypy/_typeops/visitor.py index cb09a96bf..6b08d521e 100644 --- a/returns/contrib/mypy/_typeops/visitor.py +++ b/returns/contrib/mypy/_typeops/visitor.py @@ -1,4 +1,4 @@ -from typing import Dict, Iterable, List, Optional +from collections.abc import Iterable from mypy.typeops import erase_to_bound from mypy.types import ( @@ -56,7 +56,7 @@ def translate_kind_instance(typ: MypyType) -> ProperType: # noqa: WPS, C901 if isinstance(typ, _LEAF_TYPES): # noqa: WPS223 return typ elif isinstance(typ, Instance): - last_known_value: Optional[LiteralType] = None + last_known_value: LiteralType | None = None if typ.last_known_value is not None: raw_last_known_value = translate_kind_instance(typ.last_known_value) assert isinstance(raw_last_known_value, LiteralType) @@ -85,7 +85,7 @@ def translate_kind_instance(typ: MypyType) -> ProperType: # noqa: WPS, C901 typ.column, ) elif isinstance(typ, TypedDictType): - dict_items: Dict[str, MypyType] = { + dict_items: dict[str, MypyType] = { item_name: translate_kind_instance(item_type) for item_name, item_type in typ.items.items() } @@ -109,7 +109,7 @@ def translate_kind_instance(typ: MypyType) -> ProperType: # noqa: WPS, C901 elif isinstance(typ, UnionType): return UnionType(_translate_types(typ.items), typ.line, typ.column) elif isinstance(typ, Overloaded): - functions: List[CallableType] = [] + functions: list[CallableType] = [] for func in typ.items: new = translate_kind_instance(func) assert isinstance(new, CallableType) @@ -124,7 +124,7 @@ def translate_kind_instance(typ: MypyType) -> ProperType: # noqa: WPS, C901 return typ -def _translate_types(types: Iterable[MypyType]) -> List[MypyType]: +def _translate_types(types: Iterable[MypyType]) -> list[MypyType]: return [translate_kind_instance(typ) for typ in types] diff --git a/returns/contrib/mypy/returns_plugin.py b/returns/contrib/mypy/returns_plugin.py index 3e518823c..8e77d6438 100644 --- a/returns/contrib/mypy/returns_plugin.py +++ b/returns/contrib/mypy/returns_plugin.py @@ -10,7 +10,8 @@ We use ``pytest-mypy-plugins`` to test that it works correctly, see: https://github.com/mkurnikov/pytest-mypy-plugins """ -from typing import Callable, ClassVar, Mapping, Optional, Type, final +from collections.abc import Callable, Mapping +from typing import ClassVar, Optional, final from mypy.nodes import SymbolTableNode from mypy.plugin import ( @@ -85,7 +86,7 @@ class _ReturnsPlugin(Plugin): def get_function_hook( self, fullname: str, - ) -> Optional[_FunctionCallback]: + ) -> _FunctionCallback | None: """ Called for function return types from ``mypy``. @@ -100,7 +101,7 @@ def get_function_hook( def get_attribute_hook( self, fullname: str, - ) -> Optional[_AttributeCallback]: + ) -> _AttributeCallback | None: """Called for any exiting or ``__getattr__`` aatribute access.""" if fullname.startswith(_consts.TYPED_KINDN_ACCESS): return kind.attribute_access @@ -109,18 +110,18 @@ def get_attribute_hook( def get_method_signature_hook( self, fullname: str, - ) -> Optional[_MethodSigCallback]: + ) -> _MethodSigCallback | None: """Called for method signature from ``mypy``.""" return self._method_sig_hook_plugins.get(fullname) def get_method_hook( self, fullname: str, - ) -> Optional[_MethodCallback]: + ) -> _MethodCallback | None: """Called for method return types from ``mypy``.""" return self._method_hook_plugins.get(fullname) -def plugin(version: str) -> Type[Plugin]: +def plugin(version: str) -> type[Plugin]: """Plugin's public API and entrypoint.""" return _ReturnsPlugin diff --git a/returns/contrib/pytest/plugin.py b/returns/contrib/pytest/plugin.py index 5c5392f06..601946960 100644 --- a/returns/contrib/pytest/plugin.py +++ b/returns/contrib/pytest/plugin.py @@ -1,19 +1,10 @@ import inspect import sys +from collections.abc import Callable, Iterator from contextlib import ExitStack, contextmanager from functools import partial, wraps from types import FrameType, MappingProxyType -from typing import ( - TYPE_CHECKING, - Any, - Callable, - Dict, - Final, - Iterator, - TypeVar, - Union, - final, -) +from typing import TYPE_CHECKING, Any, Final, TypeVar, Union, final from unittest import mock import pytest @@ -30,7 +21,7 @@ # Also, the object itself cannot be (in) the key because # (1) we cannot always assume hashability and # (2) we need to track the object identity, not its value -_ErrorsHandled = Dict[int, Any] +_ErrorsHandled = dict[int, Any] _FunctionType = TypeVar('_FunctionType', bound=Callable) _ReturnsResultType = TypeVar( diff --git a/returns/converters.py b/returns/converters.py index 864fb9ca0..ee0bd673c 100644 --- a/returns/converters.py +++ b/returns/converters.py @@ -1,4 +1,4 @@ -from typing import TypeVar, Union, overload +from typing import TypeVar, overload from returns.functions import identity from returns.interfaces.bindable import BindableN @@ -88,8 +88,8 @@ def maybe_to_result( def maybe_to_result( maybe_container: Maybe[_FirstType], - default_error: Union[_SecondType, None] = None, -) -> Result[_FirstType, Union[_SecondType, None]]: + default_error: _SecondType | None = None, +) -> Result[_FirstType, _SecondType | None]: """ Converts ``Maybe`` container to ``Result`` container. diff --git a/returns/curry.py b/returns/curry.py index e14915194..21d9041ad 100644 --- a/returns/curry.py +++ b/returns/curry.py @@ -1,7 +1,8 @@ +from collections.abc import Callable from functools import partial as _partial from functools import wraps from inspect import BoundArguments, Signature -from typing import Any, Callable, Tuple, TypeVar, Union +from typing import Any, TypeVar, Union _FirstType = TypeVar('_FirstType') _SecondType = TypeVar('_SecondType') @@ -127,7 +128,7 @@ def _eager_curry( argspec, args: tuple, kwargs: dict, -) -> Union[_ReturnType, Callable[..., _ReturnType]]: +) -> _ReturnType | Callable[..., _ReturnType]: """ Internal ``curry`` implementation. @@ -147,9 +148,9 @@ def decorator(*inner_args, **inner_kwargs): _ArgSpec = Union[ # Case when all arguments are bound and function can be called: - Tuple[None, Tuple[tuple, dict]], + tuple[None, tuple[tuple, dict]], # Case when there are still unbound arguments: - Tuple[BoundArguments, None], + tuple[BoundArguments, None], ] diff --git a/returns/functions.py b/returns/functions.py index 4c129cc57..bf3f9b3ee 100644 --- a/returns/functions.py +++ b/returns/functions.py @@ -1,5 +1,6 @@ +from collections.abc import Callable from functools import wraps -from typing import Any, Callable, TypeVar +from typing import Any, TypeVar from typing_extensions import Never, ParamSpec diff --git a/returns/future.py b/returns/future.py index 81ada3cb8..9195fef6d 100644 --- a/returns/future.py +++ b/returns/future.py @@ -1,21 +1,15 @@ -from functools import wraps -from typing import ( - Any, +from collections.abc import ( AsyncGenerator, AsyncIterator, Awaitable, Callable, Coroutine, Generator, - Tuple, - Type, - TypeVar, - Union, - final, - overload, ) +from functools import wraps +from typing import Any, TypeAlias, TypeVar, final, overload -from typing_extensions import ParamSpec, TypeAlias +from typing_extensions import ParamSpec from returns._internal.futures import _future, _future_result from returns.interfaces.specific.future import FutureBased1 @@ -1476,7 +1470,7 @@ def future_safe( @overload def future_safe( - exceptions: Tuple[Type[_ExceptionType], ...], + exceptions: tuple[type[_ExceptionType], ...], ) -> Callable[ [ Callable[ @@ -1490,15 +1484,15 @@ def future_safe( def future_safe( # noqa: C901, WPS212, WPS234, - exceptions: Union[ + exceptions: ( Callable[ _FuncParams, Coroutine[_FirstType, _SecondType, _ValueType], - ], - Tuple[Type[_ExceptionType], ...], - ], -) -> Union[ - Callable[_FuncParams, FutureResultE[_ValueType]], + ] | + tuple[type[_ExceptionType], ...] + ), +) -> ( + Callable[_FuncParams, FutureResultE[_ValueType]] | Callable[ [ Callable[ @@ -1507,8 +1501,8 @@ def future_safe( # noqa: C901, WPS212, WPS234, ], ], Callable[_FuncParams, FutureResult[_ValueType, _ExceptionType]], - ], -]: + ] +): """ Decorator to convert exception-throwing coroutine to ``FutureResult``. @@ -1565,7 +1559,7 @@ def _future_safe_factory( # noqa: WPS430 _FuncParams, Coroutine[_FirstType, _SecondType, _ValueType], ], - inner_exceptions: Tuple[Type[_ExceptionType], ...], + inner_exceptions: tuple[type[_ExceptionType], ...], ) -> Callable[_FuncParams, FutureResult[_ValueType, _ExceptionType]]: async def factory( *args: _FuncParams.args, diff --git a/returns/interfaces/altable.py b/returns/interfaces/altable.py index 9e0b68c1f..cccc34f2f 100644 --- a/returns/interfaces/altable.py +++ b/returns/interfaces/altable.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Callable, ClassVar, Generic, Sequence, TypeVar, final +from collections.abc import Callable, Sequence +from typing import ClassVar, Generic, TypeVar, final from typing_extensions import Never diff --git a/returns/interfaces/applicative.py b/returns/interfaces/applicative.py index ce06b503b..a963d55d2 100644 --- a/returns/interfaces/applicative.py +++ b/returns/interfaces/applicative.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Callable, ClassVar, Sequence, Type, TypeVar, final +from collections.abc import Callable, Sequence +from typing import ClassVar, TypeVar, final from typing_extensions import Never @@ -157,7 +158,7 @@ def apply( @classmethod @abstractmethod def from_value( - cls: Type[_ApplicativeType], # noqa: N805 + cls: type[_ApplicativeType], # noqa: N805 inner_value: _UpdatedType, ) -> KindN[_ApplicativeType, _UpdatedType, _SecondType, _ThirdType]: """Unit method to create new containers from any raw value.""" diff --git a/returns/interfaces/bindable.py b/returns/interfaces/bindable.py index a7604a40f..2f66331fb 100644 --- a/returns/interfaces/bindable.py +++ b/returns/interfaces/bindable.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Callable, Generic, TypeVar +from collections.abc import Callable +from typing import Generic, TypeVar from typing_extensions import Never diff --git a/returns/interfaces/container.py b/returns/interfaces/container.py index f049ac2db..6709928a6 100644 --- a/returns/interfaces/container.py +++ b/returns/interfaces/container.py @@ -1,4 +1,5 @@ -from typing import Callable, ClassVar, Sequence, TypeVar, final +from collections.abc import Callable, Sequence +from typing import ClassVar, TypeVar, final from typing_extensions import Never diff --git a/returns/interfaces/equable.py b/returns/interfaces/equable.py index 287b7e4a9..d81f58e41 100644 --- a/returns/interfaces/equable.py +++ b/returns/interfaces/equable.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import ClassVar, Sequence, TypeVar, final +from collections.abc import Sequence +from typing import ClassVar, TypeVar, final from returns.primitives.laws import ( Law, diff --git a/returns/interfaces/failable.py b/returns/interfaces/failable.py index 7eab7b2a4..5d69508e9 100644 --- a/returns/interfaces/failable.py +++ b/returns/interfaces/failable.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Callable, ClassVar, Sequence, Type, TypeVar, final +from collections.abc import Callable, Sequence +from typing import ClassVar, TypeVar, final from typing_extensions import Never @@ -252,7 +253,7 @@ class DiverseFailableN( @classmethod @abstractmethod def from_failure( - cls: Type[_DiverseFailableType], + cls: type[_DiverseFailableType], inner_value: _UpdatedType, ) -> KindN[_DiverseFailableType, _FirstType, _UpdatedType, _ThirdType]: """Unit method to create new containers from any raw value.""" diff --git a/returns/interfaces/lashable.py b/returns/interfaces/lashable.py index e3580c159..235d34a2b 100644 --- a/returns/interfaces/lashable.py +++ b/returns/interfaces/lashable.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Callable, Generic, TypeVar +from collections.abc import Callable +from typing import Generic, TypeVar from typing_extensions import Never diff --git a/returns/interfaces/mappable.py b/returns/interfaces/mappable.py index 4ed23bdd0..3853397f1 100644 --- a/returns/interfaces/mappable.py +++ b/returns/interfaces/mappable.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Callable, ClassVar, Generic, Sequence, TypeVar, final +from collections.abc import Callable, Sequence +from typing import ClassVar, Generic, TypeVar, final from typing_extensions import Never diff --git a/returns/interfaces/specific/future.py b/returns/interfaces/specific/future.py index 20ad92e72..b8b88463a 100644 --- a/returns/interfaces/specific/future.py +++ b/returns/interfaces/specific/future.py @@ -9,15 +9,8 @@ from __future__ import annotations from abc import abstractmethod -from typing import ( - TYPE_CHECKING, - Any, - Awaitable, - Callable, - Generator, - Generic, - TypeVar, -) +from collections.abc import Awaitable, Callable, Generator +from typing import TYPE_CHECKING, Any, Generic, TypeVar from typing_extensions import Never diff --git a/returns/interfaces/specific/future_result.py b/returns/interfaces/specific/future_result.py index c91b63d67..e0f07911b 100644 --- a/returns/interfaces/specific/future_result.py +++ b/returns/interfaces/specific/future_result.py @@ -9,7 +9,8 @@ from __future__ import annotations from abc import abstractmethod -from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar +from collections.abc import Awaitable, Callable +from typing import TYPE_CHECKING, TypeVar from typing_extensions import Never diff --git a/returns/interfaces/specific/io.py b/returns/interfaces/specific/io.py index af3b358db..971d9a2a9 100644 --- a/returns/interfaces/specific/io.py +++ b/returns/interfaces/specific/io.py @@ -1,7 +1,8 @@ from __future__ import annotations from abc import abstractmethod -from typing import TYPE_CHECKING, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar from typing_extensions import Never diff --git a/returns/interfaces/specific/ioresult.py b/returns/interfaces/specific/ioresult.py index 3dd13829d..b797922d2 100644 --- a/returns/interfaces/specific/ioresult.py +++ b/returns/interfaces/specific/ioresult.py @@ -7,7 +7,8 @@ from __future__ import annotations from abc import abstractmethod -from typing import TYPE_CHECKING, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar from typing_extensions import Never diff --git a/returns/interfaces/specific/maybe.py b/returns/interfaces/specific/maybe.py index 5c935a571..5f31f5f1f 100644 --- a/returns/interfaces/specific/maybe.py +++ b/returns/interfaces/specific/maybe.py @@ -1,14 +1,6 @@ from abc import abstractmethod -from typing import ( - Callable, - ClassVar, - Optional, - Sequence, - Type, - TypeVar, - Union, - final, -) +from collections.abc import Callable, Sequence +from typing import ClassVar, TypeVar, final from typing_extensions import Never @@ -78,7 +70,7 @@ def bind_short_circuit_law( @law_definition def bind_optional_short_circuit_law( container: 'MaybeLikeN[_FirstType, _SecondType, _ThirdType]', - function: Callable[[_FirstType], Optional[_NewType1]], + function: Callable[[_FirstType], _NewType1 | None], ) -> None: """Ensures that you cannot bind from failures.""" assert_equal( @@ -137,15 +129,15 @@ class MaybeLikeN( @abstractmethod def bind_optional( self: _MaybeLikeType, - function: Callable[[_FirstType], Optional[_UpdatedType]], + function: Callable[[_FirstType], _UpdatedType | None], ) -> KindN[_MaybeLikeType, _UpdatedType, _SecondType, _ThirdType]: """Binds a function that returns ``Optional`` values.""" @classmethod @abstractmethod def from_optional( - cls: Type[_MaybeLikeType], # noqa: N805 - inner_value: Optional[_ValueType], + cls: type[_MaybeLikeType], # noqa: N805 + inner_value: _ValueType | None, ) -> KindN[_MaybeLikeType, _ValueType, _SecondType, _ThirdType]: """Unit method to create containers from ``Optional`` value.""" @@ -174,7 +166,7 @@ class MaybeBasedN( def or_else_call( self, function: Callable[[], _ValueType], - ) -> Union[_FirstType, _ValueType]: + ) -> _FirstType | _ValueType: """Calls a function in case there nothing to unwrap.""" diff --git a/returns/interfaces/specific/reader.py b/returns/interfaces/specific/reader.py index 0fc1d368f..61de0f2ca 100644 --- a/returns/interfaces/specific/reader.py +++ b/returns/interfaces/specific/reader.py @@ -27,15 +27,8 @@ from __future__ import annotations from abc import abstractmethod -from typing import ( - TYPE_CHECKING, - Callable, - ClassVar, - Generic, - Sequence, - TypeVar, - final, -) +from collections.abc import Callable, Sequence +from typing import TYPE_CHECKING, ClassVar, Generic, TypeVar, final from returns.interfaces.container import Container2, Container3 from returns.primitives.hkt import Kind2, Kind3 diff --git a/returns/interfaces/specific/reader_future_result.py b/returns/interfaces/specific/reader_future_result.py index c84487ffe..39b7bd6a3 100644 --- a/returns/interfaces/specific/reader_future_result.py +++ b/returns/interfaces/specific/reader_future_result.py @@ -1,15 +1,8 @@ from __future__ import annotations from abc import abstractmethod -from typing import ( - TYPE_CHECKING, - Awaitable, - Callable, - ClassVar, - Sequence, - TypeVar, - final, -) +from collections.abc import Awaitable, Callable, Sequence +from typing import TYPE_CHECKING, ClassVar, TypeVar, final from returns.interfaces.specific import future_result, reader, reader_ioresult from returns.primitives.asserts import assert_equal diff --git a/returns/interfaces/specific/reader_ioresult.py b/returns/interfaces/specific/reader_ioresult.py index 68477628c..b4566382e 100644 --- a/returns/interfaces/specific/reader_ioresult.py +++ b/returns/interfaces/specific/reader_ioresult.py @@ -1,7 +1,8 @@ from __future__ import annotations from abc import abstractmethod -from typing import TYPE_CHECKING, Callable, ClassVar, Sequence, TypeVar, final +from collections.abc import Callable, Sequence +from typing import TYPE_CHECKING, ClassVar, TypeVar, final from returns.interfaces.specific import ioresult, reader, reader_result from returns.primitives.hkt import KindN diff --git a/returns/interfaces/specific/reader_result.py b/returns/interfaces/specific/reader_result.py index 26a356604..bc1599594 100644 --- a/returns/interfaces/specific/reader_result.py +++ b/returns/interfaces/specific/reader_result.py @@ -1,7 +1,8 @@ from __future__ import annotations from abc import abstractmethod -from typing import TYPE_CHECKING, Callable, ClassVar, Sequence, TypeVar, final +from collections.abc import Callable, Sequence +from typing import TYPE_CHECKING, ClassVar, TypeVar, final from returns.interfaces.specific import reader, result from returns.primitives.hkt import KindN diff --git a/returns/interfaces/specific/result.py b/returns/interfaces/specific/result.py index 88fe4dee1..0c38d367b 100644 --- a/returns/interfaces/specific/result.py +++ b/returns/interfaces/specific/result.py @@ -8,7 +8,8 @@ from __future__ import annotations from abc import abstractmethod -from typing import TYPE_CHECKING, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar from typing_extensions import Never diff --git a/returns/interfaces/swappable.py b/returns/interfaces/swappable.py index e02a013b3..c48f34697 100644 --- a/returns/interfaces/swappable.py +++ b/returns/interfaces/swappable.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import ClassVar, Sequence, TypeVar, final +from collections.abc import Sequence +from typing import ClassVar, TypeVar, final from typing_extensions import Never diff --git a/returns/io.py b/returns/io.py index 19e526980..3cb4cb59d 100644 --- a/returns/io.py +++ b/returns/io.py @@ -1,23 +1,10 @@ from abc import ABCMeta +from collections.abc import Callable, Generator, Iterator from functools import wraps from inspect import FrameInfo -from typing import ( - TYPE_CHECKING, - Any, - Callable, - Generator, - Iterator, - List, - Optional, - Tuple, - Type, - TypeVar, - Union, - final, - overload, -) +from typing import TYPE_CHECKING, Any, TypeAlias, TypeVar, final, overload -from typing_extensions import ParamSpec, TypeAlias +from typing_extensions import ParamSpec from returns.interfaces.specific import io, ioresult from returns.primitives.container import BaseContainer, container_equality @@ -368,10 +355,10 @@ def __repr__(self) -> str: '>' """ - return ''.format(str(self._inner_value)) + return ''.format(self._inner_value) @property - def trace(self) -> Optional[List[FrameInfo]]: + def trace(self) -> list[FrameInfo] | None: """Returns a stack trace when :func:`~IOFailure` was called.""" return self._inner_value.trace @@ -567,7 +554,7 @@ def lash( def value_or( self, default_value: _NewValueType, - ) -> IO[Union[_ValueType, _NewValueType]]: + ) -> IO[_ValueType | _NewValueType]: """ Get value from successful container or default value from failed one. @@ -901,7 +888,7 @@ def impure_safe( @overload def impure_safe( - exceptions: Tuple[Type[_ExceptionType], ...], + exceptions: tuple[type[_ExceptionType], ...], ) -> Callable[ [Callable[_FuncParams, _NewValueType]], Callable[_FuncParams, IOResult[_NewValueType, _ExceptionType]], @@ -910,17 +897,17 @@ def impure_safe( def impure_safe( # noqa: WPS234, C901 - exceptions: Union[ - Callable[_FuncParams, _NewValueType], - Tuple[Type[_ExceptionType], ...], - ], -) -> Union[ - Callable[_FuncParams, IOResultE[_NewValueType]], + exceptions: ( + Callable[_FuncParams, _NewValueType] | + tuple[type[_ExceptionType], ...] + ), +) -> ( + Callable[_FuncParams, IOResultE[_NewValueType]] | Callable[ [Callable[_FuncParams, _NewValueType]], Callable[_FuncParams, IOResult[_NewValueType, _ExceptionType]], - ], -]: + ] +): """ Decorator to mark function that it returns :class:`~IOResult` container. @@ -964,7 +951,7 @@ def impure_safe( # noqa: WPS234, C901 """ def factory( inner_function: Callable[_FuncParams, _NewValueType], - inner_exceptions: Tuple[Type[_ExceptionType], ...], + inner_exceptions: tuple[type[_ExceptionType], ...], ) -> Callable[_FuncParams, IOResult[_NewValueType, _ExceptionType]]: @wraps(inner_function) def decorator( diff --git a/returns/iterables.py b/returns/iterables.py index 647f266b3..b6084a8b9 100644 --- a/returns/iterables.py +++ b/returns/iterables.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Callable, Iterable, Tuple, TypeVar, final +from collections.abc import Callable, Iterable +from typing import Tuple, TypeVar, final from returns.interfaces.applicative import ApplicativeN from returns.interfaces.failable import FailableN diff --git a/returns/maybe.py b/returns/maybe.py index 32678a025..088ff05ed 100644 --- a/returns/maybe.py +++ b/returns/maybe.py @@ -1,17 +1,7 @@ from abc import ABCMeta +from collections.abc import Callable, Generator, Iterator from functools import wraps -from typing import ( - TYPE_CHECKING, - Any, - Callable, - ClassVar, - Generator, - Iterator, - Optional, - TypeVar, - Union, - final, -) +from typing import TYPE_CHECKING, Any, ClassVar, Optional, TypeVar, final from typing_extensions import Never, ParamSpec @@ -47,7 +37,7 @@ class Maybe( # type: ignore[type-var] __slots__ = () - _inner_value: Optional[_ValueType] + _inner_value: _ValueType | None __match_args__ = ('_inner_value',) #: Alias for `Nothing` @@ -115,7 +105,7 @@ def bind( def bind_optional( self, - function: Callable[[_ValueType], Optional[_NewValueType]], + function: Callable[[_ValueType], _NewValueType | None], ) -> 'Maybe[_NewValueType]': """ Binds a function returning an optional value over a container. @@ -194,7 +184,7 @@ def do( def value_or( self, default_value: _NewValueType, - ) -> Union[_ValueType, _NewValueType]: + ) -> _ValueType | _NewValueType: """ Get value from successful container or default value from failed one. @@ -209,7 +199,7 @@ def value_or( def or_else_call( self, function: Callable[[], _NewValueType], - ) -> Union[_ValueType, _NewValueType]: + ) -> _ValueType | _NewValueType: """ Get value from successful container or default value from failed one. @@ -295,7 +285,7 @@ def from_value( @classmethod def from_optional( - cls, inner_value: Optional[_NewValueType], + cls, inner_value: _NewValueType | None, ) -> 'Maybe[_NewValueType]': """ Creates new instance of ``Maybe`` container based on an optional value. @@ -449,7 +439,7 @@ def failure(self): def maybe( - function: Callable[_FuncParams, Optional[_ValueType]], + function: Callable[_FuncParams, _ValueType | None], ) -> Callable[_FuncParams, Maybe[_ValueType]]: """ Decorator to convert ``None``-returning function to ``Maybe`` container. diff --git a/returns/methods/cond.py b/returns/methods/cond.py index dc29443bd..032227b0d 100644 --- a/returns/methods/cond.py +++ b/returns/methods/cond.py @@ -1,4 +1,4 @@ -from typing import Optional, Type, TypeVar, Union, overload +from typing import TypeVar, overload from returns.context import NoDeps from returns.interfaces.failable import DiverseFailableN, SingleFailableN @@ -13,7 +13,7 @@ @overload def internal_cond( - container_type: Type[_SingleFailableKind], + container_type: type[_SingleFailableKind], is_success: bool, success_value: _ValueType, ) -> KindN[_SingleFailableKind, _ValueType, _ErrorType, NoDeps]: @@ -22,7 +22,7 @@ def internal_cond( @overload def internal_cond( - container_type: Type[_DiverseFailableKind], + container_type: type[_DiverseFailableKind], is_success: bool, success_value: _ValueType, error_value: _ErrorType, @@ -31,12 +31,12 @@ def internal_cond( def internal_cond( - container_type: Union[ - Type[_SingleFailableKind], Type[_DiverseFailableKind], - ], + container_type: ( + type[_SingleFailableKind] | type[_DiverseFailableKind] + ), is_success: bool, success_value: _ValueType, - error_value: Optional[_ErrorType] = None, + error_value: _ErrorType | None = None, ): """ Reduce the boilerplate when choosing paths. diff --git a/returns/methods/partition.py b/returns/methods/partition.py index f844fda7c..00f2c4b10 100644 --- a/returns/methods/partition.py +++ b/returns/methods/partition.py @@ -1,5 +1,5 @@ - -from typing import Iterable, List, TypeVar +from collections.abc import Iterable +from typing import TypeVar from returns.interfaces.unwrappable import Unwrappable from returns.primitives.exceptions import UnwrapFailedError @@ -12,7 +12,7 @@ def partition( containers: Iterable[ Unwrappable[_ValueType, _ErrorType], ], -) -> tuple[List[_ValueType], List[_ErrorType]]: +) -> tuple[list[_ValueType], list[_ErrorType]]: """ Partition a list of unwrappables into successful and failed values. diff --git a/returns/methods/unwrap_or_failure.py b/returns/methods/unwrap_or_failure.py index 207e8980a..120c4d0df 100644 --- a/returns/methods/unwrap_or_failure.py +++ b/returns/methods/unwrap_or_failure.py @@ -1,4 +1,4 @@ -from typing import TypeVar, Union +from typing import TypeVar from returns.interfaces.unwrappable import Unwrappable from returns.pipeline import is_successful @@ -9,7 +9,7 @@ def unwrap_or_failure( container: Unwrappable[_FirstType, _SecondType], -) -> Union[_FirstType, _SecondType]: +) -> _FirstType | _SecondType: """ Unwraps either successful or failed value. diff --git a/returns/pointfree/alt.py b/returns/pointfree/alt.py index 05940d3c0..dd1222bb5 100644 --- a/returns/pointfree/alt.py +++ b/returns/pointfree/alt.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.altable import AltableN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/apply.py b/returns/pointfree/apply.py index 8748fa14b..471ca0a42 100644 --- a/returns/pointfree/apply.py +++ b/returns/pointfree/apply.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.applicative import ApplicativeN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/bimap.py b/returns/pointfree/bimap.py index a09b1a44e..59568418d 100644 --- a/returns/pointfree/bimap.py +++ b/returns/pointfree/bimap.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.bimappable import BiMappableN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/bind.py b/returns/pointfree/bind.py index b07441b94..8e8e94a26 100644 --- a/returns/pointfree/bind.py +++ b/returns/pointfree/bind.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.bindable import BindableN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/bind_async.py b/returns/pointfree/bind_async.py index 5e1d5dc80..7581206c4 100644 --- a/returns/pointfree/bind_async.py +++ b/returns/pointfree/bind_async.py @@ -1,4 +1,5 @@ -from typing import Awaitable, Callable, TypeVar +from collections.abc import Awaitable, Callable +from typing import TypeVar from returns.interfaces.specific.future import FutureLikeN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/bind_async_context_future_result.py b/returns/pointfree/bind_async_context_future_result.py index d1a492d49..034f53213 100644 --- a/returns/pointfree/bind_async_context_future_result.py +++ b/returns/pointfree/bind_async_context_future_result.py @@ -1,4 +1,5 @@ -from typing import TYPE_CHECKING, Awaitable, Callable, TypeVar +from collections.abc import Awaitable, Callable +from typing import TYPE_CHECKING, TypeVar from returns.interfaces.specific.reader_future_result import ( ReaderFutureResultLikeN, diff --git a/returns/pointfree/bind_async_future.py b/returns/pointfree/bind_async_future.py index 542a4e53b..f8987abeb 100644 --- a/returns/pointfree/bind_async_future.py +++ b/returns/pointfree/bind_async_future.py @@ -1,4 +1,5 @@ -from typing import Awaitable, Callable, TypeVar +from collections.abc import Awaitable, Callable +from typing import TypeVar from returns.future import Future from returns.interfaces.specific.future import FutureLikeN diff --git a/returns/pointfree/bind_async_future_result.py b/returns/pointfree/bind_async_future_result.py index 3ccbbd1a3..7d6a36d34 100644 --- a/returns/pointfree/bind_async_future_result.py +++ b/returns/pointfree/bind_async_future_result.py @@ -1,4 +1,5 @@ -from typing import Awaitable, Callable, TypeVar +from collections.abc import Awaitable, Callable +from typing import TypeVar from returns.future import FutureResult from returns.interfaces.specific.future_result import FutureResultLikeN diff --git a/returns/pointfree/bind_awaitable.py b/returns/pointfree/bind_awaitable.py index 1ca5dc2e9..0ac7cdef3 100644 --- a/returns/pointfree/bind_awaitable.py +++ b/returns/pointfree/bind_awaitable.py @@ -1,4 +1,5 @@ -from typing import Awaitable, Callable, TypeVar +from collections.abc import Awaitable, Callable +from typing import TypeVar from returns.interfaces.specific.future import FutureLikeN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/bind_context.py b/returns/pointfree/bind_context.py index cca35d87c..d3e7fcf6b 100644 --- a/returns/pointfree/bind_context.py +++ b/returns/pointfree/bind_context.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar from returns.interfaces.specific.reader import ReaderLike2, ReaderLike3 from returns.primitives.hkt import Kind2, Kind3, Kinded, kinded diff --git a/returns/pointfree/bind_context_future_result.py b/returns/pointfree/bind_context_future_result.py index a0f93fa3e..33fa35a5b 100644 --- a/returns/pointfree/bind_context_future_result.py +++ b/returns/pointfree/bind_context_future_result.py @@ -1,4 +1,5 @@ -from typing import TYPE_CHECKING, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar from returns.interfaces.specific.reader_future_result import ( ReaderFutureResultLikeN, diff --git a/returns/pointfree/bind_context_ioresult.py b/returns/pointfree/bind_context_ioresult.py index 2fad3cc8a..564ed15f4 100644 --- a/returns/pointfree/bind_context_ioresult.py +++ b/returns/pointfree/bind_context_ioresult.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar from returns.interfaces.specific.reader_ioresult import ReaderIOResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/bind_context_result.py b/returns/pointfree/bind_context_result.py index 971c7ad8c..091f43051 100644 --- a/returns/pointfree/bind_context_result.py +++ b/returns/pointfree/bind_context_result.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar from returns.interfaces.specific.reader_result import ReaderResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/bind_future.py b/returns/pointfree/bind_future.py index c61d05ca5..6b8e4b877 100644 --- a/returns/pointfree/bind_future.py +++ b/returns/pointfree/bind_future.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.future import Future from returns.interfaces.specific.future import FutureLikeN diff --git a/returns/pointfree/bind_future_result.py b/returns/pointfree/bind_future_result.py index 303722564..ff765d8f2 100644 --- a/returns/pointfree/bind_future_result.py +++ b/returns/pointfree/bind_future_result.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.future import FutureResult from returns.interfaces.specific.future_result import FutureResultLikeN diff --git a/returns/pointfree/bind_io.py b/returns/pointfree/bind_io.py index 5b038910b..cff9730a9 100644 --- a/returns/pointfree/bind_io.py +++ b/returns/pointfree/bind_io.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar from returns.interfaces.specific.io import IOLikeN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/bind_ioresult.py b/returns/pointfree/bind_ioresult.py index 4aa38bf8e..8a83e5cf1 100644 --- a/returns/pointfree/bind_ioresult.py +++ b/returns/pointfree/bind_ioresult.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar from returns.interfaces.specific.ioresult import IOResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/bind_optional.py b/returns/pointfree/bind_optional.py index 8b0de52f1..e35af8dee 100644 --- a/returns/pointfree/bind_optional.py +++ b/returns/pointfree/bind_optional.py @@ -1,4 +1,5 @@ -from typing import Callable, Optional, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.specific.maybe import MaybeLikeN from returns.primitives.hkt import Kinded, KindN, kinded @@ -12,7 +13,7 @@ def bind_optional( - function: Callable[[_FirstType], Optional[_UpdatedType]], + function: Callable[[_FirstType], _UpdatedType | None], ) -> Kinded[Callable[ [KindN[_MaybeLikeKind, _FirstType, _SecondType, _ThirdType]], KindN[_MaybeLikeKind, _UpdatedType, _SecondType, _ThirdType], diff --git a/returns/pointfree/bind_result.py b/returns/pointfree/bind_result.py index d0bddf62c..28ee180a2 100644 --- a/returns/pointfree/bind_result.py +++ b/returns/pointfree/bind_result.py @@ -1,6 +1,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING, Callable, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, TypeVar from returns.interfaces.specific.result import ResultLikeN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/compose_result.py b/returns/pointfree/compose_result.py index fe0605ef4..7b2e3035e 100644 --- a/returns/pointfree/compose_result.py +++ b/returns/pointfree/compose_result.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.specific.ioresult import IOResultLikeN from returns.primitives.hkt import Kind3, Kinded, kinded diff --git a/returns/pointfree/cond.py b/returns/pointfree/cond.py index beb59a604..07649ebbc 100644 --- a/returns/pointfree/cond.py +++ b/returns/pointfree/cond.py @@ -1,4 +1,5 @@ -from typing import Callable, Optional, Type, TypeVar, Union, overload +from collections.abc import Callable +from typing import TypeVar, overload from returns.context import NoDeps from returns.interfaces.failable import DiverseFailableN, SingleFailableN @@ -14,7 +15,7 @@ @overload def cond( - container_type: Type[_SingleFailableKind], + container_type: type[_SingleFailableKind], success_value: _ValueType, ) -> Kinded[ Callable[ @@ -26,7 +27,7 @@ def cond( @overload def cond( - container_type: Type[_DiverseFailableKind], + container_type: type[_DiverseFailableKind], success_value: _ValueType, error_value: _ErrorType, ) -> Kinded[ @@ -38,11 +39,11 @@ def cond( def cond( - container_type: Union[ - Type[_SingleFailableKind], Type[_DiverseFailableKind], - ], + container_type: ( + type[_SingleFailableKind] | type[_DiverseFailableKind] + ), success_value: _ValueType, - error_value: Optional[_ErrorType] = None, + error_value: _ErrorType | None = None, ): """ Reduce the boilerplate when choosing paths. diff --git a/returns/pointfree/lash.py b/returns/pointfree/lash.py index 7a934fad8..16b63e2c2 100644 --- a/returns/pointfree/lash.py +++ b/returns/pointfree/lash.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.lashable import LashableN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/map.py b/returns/pointfree/map.py index 1efb66c77..bd83af8ad 100644 --- a/returns/pointfree/map.py +++ b/returns/pointfree/map.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.mappable import MappableN from returns.primitives.hkt import Kinded, KindN, kinded diff --git a/returns/pointfree/modify_env.py b/returns/pointfree/modify_env.py index 5bbdfc6b7..2663cadde 100644 --- a/returns/pointfree/modify_env.py +++ b/returns/pointfree/modify_env.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.specific.reader import ReaderLike2, ReaderLike3 from returns.primitives.hkt import Kind2, Kind3, Kinded, kinded diff --git a/returns/pointfree/unify.py b/returns/pointfree/unify.py index f1145adfd..53071462e 100644 --- a/returns/pointfree/unify.py +++ b/returns/pointfree/unify.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar, Union +from collections.abc import Callable +from typing import TypeVar from returns.interfaces.failable import DiverseFailableN from returns.primitives.hkt import Kinded, KindN, kinded @@ -26,7 +27,7 @@ def unify( # noqa: WPS234 KindN[ _DiverseFailableKind, _NewFirstType, - Union[_SecondType, _NewSecondType], + _SecondType | _NewSecondType, _NewThirdType, ], ] @@ -63,7 +64,7 @@ def factory( ) -> KindN[ _DiverseFailableKind, _NewFirstType, - Union[_SecondType, _NewSecondType], + _SecondType | _NewSecondType, _NewThirdType, ]: return container.bind(function) # type: ignore diff --git a/returns/primitives/container.py b/returns/primitives/container.py index b4ac79367..d7be94281 100644 --- a/returns/primitives/container.py +++ b/returns/primitives/container.py @@ -1,5 +1,5 @@ from abc import ABCMeta -from typing import Any, TypeVar, Union +from typing import Any, TypeVar from typing_extensions import TypedDict @@ -56,7 +56,7 @@ def __getstate__(self) -> _PickleState: """That's how this object will be pickled.""" return {'container_value': self._inner_value} # type: ignore - def __setstate__(self, state: Union[_PickleState, Any]) -> None: + def __setstate__(self, state: _PickleState | Any) -> None: """Loading state from pickled data.""" if isinstance(state, dict) and 'container_value' in state: object.__setattr__( # noqa: WPS609 diff --git a/returns/primitives/hkt.py b/returns/primitives/hkt.py index 66ffdb3d0..b374a8a53 100644 --- a/returns/primitives/hkt.py +++ b/returns/primitives/hkt.py @@ -1,6 +1,7 @@ -from typing import TYPE_CHECKING, Any, Callable, Protocol, TypeVar +from collections.abc import Callable +from typing import TYPE_CHECKING, Any, Generic, Protocol, TypeVar -from typing_extensions import Generic, Never, TypeVarTuple, Unpack +from typing_extensions import Never, TypeVarTuple, Unpack _InstanceType = TypeVar('_InstanceType', covariant=True) _TypeArgType1 = TypeVar('_TypeArgType1', covariant=True) diff --git a/returns/primitives/laws.py b/returns/primitives/laws.py index a2c4ad9f4..309fb811c 100644 --- a/returns/primitives/laws.py +++ b/returns/primitives/laws.py @@ -1,13 +1,5 @@ -from typing import ( - Callable, - ClassVar, - Dict, - Generic, - Sequence, - Type, - TypeVar, - final, -) +from collections.abc import Callable, Sequence +from typing import ClassVar, Generic, TypeVar, final from returns.primitives.types import Immutable @@ -122,7 +114,7 @@ class Lawful(Generic[_Caps]): @final # noqa: WPS210 @classmethod - def laws(cls) -> Dict[Type['Lawful'], Sequence[Law]]: # noqa: WPS210 + def laws(cls) -> dict[type['Lawful'], Sequence[Law]]: # noqa: WPS210 """ Collects all laws from all parent classes. diff --git a/returns/primitives/reawaitable.py b/returns/primitives/reawaitable.py index 836bf4bc4..d8f5e460c 100644 --- a/returns/primitives/reawaitable.py +++ b/returns/primitives/reawaitable.py @@ -1,13 +1,5 @@ -from typing import ( - Awaitable, - Callable, - Generator, - NewType, - TypeVar, - Union, - cast, - final, -) +from collections.abc import Awaitable, Callable, Generator +from typing import NewType, TypeVar, cast, final _ValueType = TypeVar('_ValueType') _FunctionCoroType = TypeVar('_FunctionCoroType', bound=Callable[..., Awaitable]) @@ -59,7 +51,7 @@ class ReAwaitable: def __init__(self, coro: Awaitable[_ValueType]) -> None: """We need just an awaitable to work with.""" self._coro = coro - self._cache: Union[_ValueType, _Sentinel] = _sentinel + self._cache: _ValueType | _Sentinel = _sentinel def __await__(self) -> Generator[None, None, _ValueType]: """ diff --git a/returns/primitives/tracing.py b/returns/primitives/tracing.py index 86786d026..6f73d40f3 100644 --- a/returns/primitives/tracing.py +++ b/returns/primitives/tracing.py @@ -1,16 +1,8 @@ import types +from collections.abc import Callable, Iterator from contextlib import contextmanager from inspect import FrameInfo, stack -from typing import ( - Callable, - ContextManager, - Iterator, - List, - Optional, - TypeVar, - Union, - overload, -) +from typing import ContextManager, TypeVar, overload from returns.result import Failure @@ -28,8 +20,8 @@ def collect_traces(function: _FunctionType) -> _FunctionType: def collect_traces( - function: Optional[_FunctionType] = None, -) -> Union[_FunctionType, ContextManager[None]]: # noqa: DAR101, DAR201, DAR301 + function: _FunctionType | None = None, +) -> _FunctionType | ContextManager[None]: # noqa: DAR101, DAR201, DAR301 """ Context Manager/Decorator to active traces collect to the Failures. @@ -76,7 +68,7 @@ def factory() -> Iterator[None]: return factory()(function) if function else factory() -def _get_trace(_self: Failure) -> Optional[List[FrameInfo]]: +def _get_trace(_self: Failure) -> list[FrameInfo] | None: """ Function to be used on Monkey Patching. diff --git a/returns/primitives/types.py b/returns/primitives/types.py index 197cbe479..a28e40d1c 100644 --- a/returns/primitives/types.py +++ b/returns/primitives/types.py @@ -1,4 +1,4 @@ -from typing import Any, Dict +from typing import Any from typing_extensions import Never, Self @@ -35,7 +35,7 @@ def __copy__(self) -> Self: """Returns itself.""" return self - def __deepcopy__(self, memo: Dict[Any, Any]) -> Self: + def __deepcopy__(self, memo: dict[Any, Any]) -> Self: """Returns itself.""" return self diff --git a/returns/result.py b/returns/result.py index 972f8b7af..293ede7e4 100644 --- a/returns/result.py +++ b/returns/result.py @@ -1,23 +1,10 @@ from abc import ABCMeta +from collections.abc import Callable, Generator, Iterator from functools import wraps from inspect import FrameInfo -from typing import ( - TYPE_CHECKING, - Any, - Callable, - Generator, - Iterator, - List, - Optional, - Tuple, - Type, - TypeVar, - Union, - final, - overload, -) - -from typing_extensions import Never, ParamSpec, TypeAlias +from typing import TYPE_CHECKING, Any, TypeAlias, TypeVar, final, overload + +from typing_extensions import Never, ParamSpec from returns.interfaces.specific import result from returns.primitives.container import BaseContainer, container_equality @@ -55,14 +42,14 @@ class Result( # type: ignore[type-var] __slots__ = ('_trace',) __match_args__ = ('_inner_value',) - _inner_value: Union[_ValueType, _ErrorType] - _trace: Optional[List[FrameInfo]] + _inner_value: _ValueType | _ErrorType + _trace: list[FrameInfo] | None #: Typesafe equality comparison with other `Result` objects. equals = container_equality @property - def trace(self) -> Optional[List[FrameInfo]]: + def trace(self) -> list[FrameInfo] | None: """Returns a list with stack trace when :func:`~Failure` was called.""" return self._trace @@ -239,7 +226,7 @@ def do( def value_or( self, default_value: _NewValueType, - ) -> Union[_ValueType, _NewValueType]: + ) -> _ValueType | _NewValueType: """ Get value or default value. @@ -403,7 +390,7 @@ def failure(self) -> _ErrorType: """Returns failed value.""" return self._inner_value - def _get_trace(self) -> Optional[List[FrameInfo]]: + def _get_trace(self) -> list[FrameInfo] | None: """Method that will be monkey patched when trace is active.""" @@ -487,7 +474,7 @@ def safe( @overload def safe( - exceptions: Tuple[Type[_ExceptionType], ...], + exceptions: tuple[type[_ExceptionType], ...], ) -> Callable[ [Callable[_FuncParams, _ValueType]], Callable[_FuncParams, Result[_ValueType, _ExceptionType]], @@ -496,17 +483,17 @@ def safe( def safe( # noqa: WPS234, C901 - exceptions: Union[ - Callable[_FuncParams, _ValueType], - Tuple[Type[_ExceptionType], ...], - ], -) -> Union[ - Callable[_FuncParams, ResultE[_ValueType]], + exceptions: ( + Callable[_FuncParams, _ValueType] | + tuple[type[_ExceptionType], ...] + ), +) -> ( + Callable[_FuncParams, ResultE[_ValueType]] | Callable[ [Callable[_FuncParams, _ValueType]], Callable[_FuncParams, Result[_ValueType, _ExceptionType]], - ], -]: + ] +): """ Decorator to convert exception-throwing function to ``Result`` container. @@ -549,7 +536,7 @@ def safe( # noqa: WPS234, C901 """ def factory( inner_function: Callable[_FuncParams, _ValueType], - inner_exceptions: Tuple[Type[_ExceptionType], ...], + inner_exceptions: tuple[type[_ExceptionType], ...], ) -> Callable[_FuncParams, Result[_ValueType, _ExceptionType]]: @wraps(inner_function) def decorator( diff --git a/returns/trampolines.py b/returns/trampolines.py index ecfb6de0e..b0dbc0e48 100644 --- a/returns/trampolines.py +++ b/returns/trampolines.py @@ -1,5 +1,6 @@ +from collections.abc import Callable from functools import wraps -from typing import Callable, Generic, TypeVar, Union, final +from typing import Generic, TypeVar, final from typing_extensions import ParamSpec @@ -35,7 +36,7 @@ def __call__(self) -> _ReturnType: def trampoline( - func: Callable[_FuncParams, Union[_ReturnType, Trampoline[_ReturnType]]], + func: Callable[_FuncParams, _ReturnType | Trampoline[_ReturnType]], ) -> Callable[_FuncParams, _ReturnType]: """ Convert functions using recursion to regular functions. diff --git a/setup.cfg b/setup.cfg index 7a27ff958..2ce466c3d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,12 +32,6 @@ extend-exclude = # Bad code that I write to test things: ex.py experiments - # Pattern matching, flake8 and friends are not ready to deal with it - # Remove these lines when https://github.com/PyCQA/pyflakes/pull/630 is merged - tests/test_examples/test_result/test_result_pattern_matching.py - tests/test_examples/test_maybe/test_maybe_pattern_matching.py - tests/test_examples/test_io/test_ioresult_container/test_ioresult_pattern_matching.py - tests/test_pattern_matching.py ignore = D100, diff --git a/tests/test_context/test_requires_context/test_context_equality.py b/tests/test_context/test_requires_context/test_context_equality.py index 87f912919..1b3c2ec76 100644 --- a/tests/test_context/test_requires_context/test_context_equality.py +++ b/tests/test_context/test_requires_context/test_context_equality.py @@ -1,4 +1,4 @@ -from typing import Callable +from collections.abc import Callable from returns.context import RequiresContext diff --git a/tests/test_contrib/test_hypothesis/test_laws/test_custom_type_applicative.py b/tests/test_contrib/test_hypothesis/test_laws/test_custom_type_applicative.py index 0f600ef07..481a67c80 100644 --- a/tests/test_contrib/test_hypothesis/test_laws/test_custom_type_applicative.py +++ b/tests/test_contrib/test_hypothesis/test_laws/test_custom_type_applicative.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.contrib.hypothesis.laws import check_all_laws from returns.interfaces import applicative diff --git a/tests/test_contrib/test_hypothesis/test_laws/test_custom_type_with_init.py b/tests/test_contrib/test_hypothesis/test_laws/test_custom_type_with_init.py index cc37c38d2..87f8f19ab 100644 --- a/tests/test_contrib/test_hypothesis/test_laws/test_custom_type_with_init.py +++ b/tests/test_contrib/test_hypothesis/test_laws/test_custom_type_with_init.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar from returns.contrib.hypothesis.laws import check_all_laws from returns.interfaces import equable, mappable diff --git a/tests/test_contrib/test_hypothesis/test_laws/test_unsatisfiable_type.py b/tests/test_contrib/test_hypothesis/test_laws/test_unsatisfiable_type.py index d45bd3bbe..124dc0a5b 100644 --- a/tests/test_contrib/test_hypothesis/test_laws/test_unsatisfiable_type.py +++ b/tests/test_contrib/test_hypothesis/test_laws/test_unsatisfiable_type.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar import pytest from hypothesis.errors import ResolutionFailed diff --git a/tests/test_contrib/test_hypothesis/test_laws/test_wrong_custom_type_with_init.py b/tests/test_contrib/test_hypothesis/test_laws/test_wrong_custom_type_with_init.py index 9c02361f5..3efda4e38 100644 --- a/tests/test_contrib/test_hypothesis/test_laws/test_wrong_custom_type_with_init.py +++ b/tests/test_contrib/test_hypothesis/test_laws/test_wrong_custom_type_with_init.py @@ -1,4 +1,5 @@ -from typing import Callable, TypeVar +from collections.abc import Callable +from typing import TypeVar import pytest diff --git a/tests/test_contrib/test_hypothesis/test_type_resolution.py b/tests/test_contrib/test_hypothesis/test_type_resolution.py index 4fdb431ce..a9c922d58 100644 --- a/tests/test_contrib/test_hypothesis/test_type_resolution.py +++ b/tests/test_contrib/test_hypothesis/test_type_resolution.py @@ -1,4 +1,5 @@ -from typing import Any, Sequence, Type +from collections.abc import Sequence +from typing import Any import pytest from hypothesis import given @@ -21,7 +22,7 @@ from returns.primitives.laws import Lawful from returns.result import Result, ResultE -_all_containers: Sequence[Type[Lawful]] = ( +_all_containers: Sequence[type[Lawful]] = ( Maybe, Result, IO, @@ -45,7 +46,7 @@ @pytest.mark.filterwarnings('ignore:.*') @pytest.mark.parametrize('container_type', _all_containers) -def test_all_containers_resolves(container_type: Type[Lawful]) -> None: +def test_all_containers_resolves(container_type: type[Lawful]) -> None: """Ensures all containers do resolve.""" assert st.from_type(container_type).example() is not None diff --git a/tests/test_curry/test_curry.py b/tests/test_curry/test_curry.py index 9246733fa..64387c042 100644 --- a/tests/test_curry/test_curry.py +++ b/tests/test_curry/test_curry.py @@ -1,5 +1,4 @@ from inspect import getdoc -from typing import List, Tuple import pytest @@ -20,7 +19,7 @@ def test_immutable(): """Check that arguments from previous calls are immutable.""" @curry - def factory(arg: int, other: int) -> Tuple[int, int]: + def factory(arg: int, other: int) -> tuple[int, int]: return (arg, other) cached = factory(arg=1) @@ -59,7 +58,7 @@ def test_two_args(): """Ensures that it is possible to curry a function with two args.""" @curry - def factory(arg: int, other: int) -> Tuple[int, int]: + def factory(arg: int, other: int) -> tuple[int, int]: return (arg, other) assert factory(1)(2) == (1, 2) @@ -121,7 +120,7 @@ def test_star_kwargs(): """Ensures that it is possible to curry a function with ``**kwargs``.""" @curry - def factory(**kwargs: int) -> List[Tuple[str, int]]: + def factory(**kwargs: int) -> list[tuple[str, int]]: return sorted(kwargs.items()) assert not factory() @@ -141,7 +140,7 @@ def test_arg_star_kwargs(): """The decorator should work with ``kwargs``.""" @curry - def factory(first: int, **kwargs: int) -> List[Tuple[str, int]]: + def factory(first: int, **kwargs: int) -> list[tuple[str, int]]: return [('first', first)] + sorted(kwargs.items()) assert factory(1) == [('first', 1)] @@ -168,7 +167,7 @@ def test_kwonly(): """The decorator should work with kw-only args.""" @curry - def factory(*args: int, by: int) -> Tuple[int, ...]: + def factory(*args: int, by: int) -> tuple[int, ...]: return args + (by, ) assert factory( diff --git a/tests/test_examples/test_context/test_reader_future_result.py b/tests/test_examples/test_context/test_reader_future_result.py index 3d9c29b48..8eba31fab 100644 --- a/tests/test_examples/test_context/test_reader_future_result.py +++ b/tests/test_examples/test_context/test_reader_future_result.py @@ -1,4 +1,5 @@ -from typing import Final, Sequence, cast +from collections.abc import Sequence +from typing import Final, cast import anyio # you would need to `pip install anyio` import httpx # you would need to `pip install httpx` diff --git a/tests/test_examples/test_future/test_future_result.py b/tests/test_examples/test_future/test_future_result.py index 188bca433..13bcf3480 100644 --- a/tests/test_examples/test_future/test_future_result.py +++ b/tests/test_examples/test_future/test_future_result.py @@ -1,5 +1,6 @@ import asyncio # we use `asyncio` only as an example, you can use any io lib -from typing import Final, Sequence, cast +from collections.abc import Sequence +from typing import Final, cast import httpx # you would need to `pip install httpx` from typing_extensions import TypedDict diff --git a/tests/test_examples/test_your_container/test_pair1.py b/tests/test_examples/test_your_container/test_pair1.py index 0060f9850..a71b04227 100644 --- a/tests/test_examples/test_your_container/test_pair1.py +++ b/tests/test_examples/test_your_container/test_pair1.py @@ -1,4 +1,5 @@ -from typing import Callable, Tuple, TypeVar, final +from collections.abc import Callable +from typing import TypeVar, final from returns.interfaces import bindable, equable, lashable, swappable from returns.primitives.container import BaseContainer, container_equality @@ -30,7 +31,7 @@ class Pair( def __init__( self, - inner_value: Tuple[_FirstType, _SecondType], + inner_value: tuple[_FirstType, _SecondType], ) -> None: """Saves passed tuple as ``._inner_value`` inside this instance.""" super().__init__(inner_value) diff --git a/tests/test_examples/test_your_container/test_pair2.py b/tests/test_examples/test_your_container/test_pair2.py index 5451a67f9..304cb0aa1 100644 --- a/tests/test_examples/test_your_container/test_pair2.py +++ b/tests/test_examples/test_your_container/test_pair2.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Callable, Tuple, Type, TypeVar, final +from collections.abc import Callable +from typing import TypeVar, final from typing_extensions import Never @@ -38,7 +39,7 @@ def pair( @classmethod @abstractmethod def from_paired( - cls: Type[_PairLikeKind], + cls: type[_PairLikeKind], first: _NewFirstType, second: _NewSecondType, ) -> KindN[_PairLikeKind, _NewFirstType, _NewSecondType, _ThirdType]: @@ -47,7 +48,7 @@ def from_paired( @classmethod @abstractmethod def from_unpaired( - cls: Type[_PairLikeKind], + cls: type[_PairLikeKind], inner_value: _NewFirstType, ) -> KindN[_PairLikeKind, _NewFirstType, _NewFirstType, _ThirdType]: """Allows to create a PairLikeN from just a single object.""" @@ -73,7 +74,7 @@ class Pair( def __init__( self, - inner_value: Tuple[_FirstType, _SecondType], + inner_value: tuple[_FirstType, _SecondType], ) -> None: """Saves passed tuple as ``._inner_value`` inside this instance.""" super().__init__(inner_value) diff --git a/tests/test_examples/test_your_container/test_pair3.py b/tests/test_examples/test_your_container/test_pair3.py index 0a2928e82..3f75fe2bb 100644 --- a/tests/test_examples/test_your_container/test_pair3.py +++ b/tests/test_examples/test_your_container/test_pair3.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Callable, Tuple, Type, TypeVar, final +from collections.abc import Callable +from typing import TypeVar, final from typing_extensions import Never @@ -38,7 +39,7 @@ def pair( @classmethod @abstractmethod def from_paired( - cls: Type[_PairLikeKind], + cls: type[_PairLikeKind], first: _NewFirstType, second: _NewSecondType, ) -> KindN[_PairLikeKind, _NewFirstType, _NewSecondType, _ThirdType]: @@ -47,7 +48,7 @@ def from_paired( @classmethod @abstractmethod def from_unpaired( - cls: Type[_PairLikeKind], + cls: type[_PairLikeKind], inner_value: _NewFirstType, ) -> KindN[_PairLikeKind, _NewFirstType, _NewFirstType, _ThirdType]: """Allows to create a PairLikeN from just a single object.""" @@ -73,7 +74,7 @@ class Pair( def __init__( self, - inner_value: Tuple[_FirstType, _SecondType], + inner_value: tuple[_FirstType, _SecondType], ) -> None: """Saves passed tuple as ``._inner_value`` inside this instance.""" super().__init__(inner_value) diff --git a/tests/test_examples/test_your_container/test_pair4.py b/tests/test_examples/test_your_container/test_pair4.py index 6c2514a73..0b8c23be2 100644 --- a/tests/test_examples/test_your_container/test_pair4.py +++ b/tests/test_examples/test_your_container/test_pair4.py @@ -1,5 +1,6 @@ from abc import abstractmethod -from typing import Callable, ClassVar, Sequence, Tuple, Type, TypeVar, final +from collections.abc import Callable, Sequence +from typing import ClassVar, TypeVar, final from typing_extensions import Never @@ -34,7 +35,7 @@ def pair_equality_law( @law_definition def pair_left_identity_law( - pair: Tuple[_FirstType, _SecondType], + pair: tuple[_FirstType, _SecondType], container: 'PairLikeN[_FirstType, _SecondType, _ThirdType]', function: Callable[ [_FirstType, _SecondType], @@ -74,7 +75,7 @@ def pair( @classmethod @abstractmethod def from_paired( - cls: Type[_PairLikeKind], + cls: type[_PairLikeKind], first: _NewFirstType, second: _NewSecondType, ) -> KindN[_PairLikeKind, _NewFirstType, _NewSecondType, _ThirdType]: @@ -83,7 +84,7 @@ def from_paired( @classmethod @abstractmethod def from_unpaired( - cls: Type[_PairLikeKind], + cls: type[_PairLikeKind], inner_value: _NewFirstType, ) -> KindN[_PairLikeKind, _NewFirstType, _NewFirstType, _ThirdType]: """Allows to create a PairLikeN from just a single object.""" @@ -109,7 +110,7 @@ class Pair( def __init__( self, - inner_value: Tuple[_FirstType, _SecondType], + inner_value: tuple[_FirstType, _SecondType], ) -> None: """Saves passed tuple as ``._inner_value`` inside this instance.""" super().__init__(inner_value) diff --git a/tests/test_functions/test_raise_exception.py b/tests/test_functions/test_raise_exception.py index 41d904b1b..2d31ba186 100644 --- a/tests/test_functions/test_raise_exception.py +++ b/tests/test_functions/test_raise_exception.py @@ -1,4 +1,3 @@ -from typing import Type import pytest @@ -15,7 +14,7 @@ class _CustomException(Exception): ValueError, _CustomException, ]) -def test_raise_regular_exception(exception_type: Type[Exception]): +def test_raise_regular_exception(exception_type: type[Exception]): """Ensures that regular exception can be thrown.""" with pytest.raises(exception_type): raise_exception(exception_type()) diff --git a/tests/test_future/test_future_container/test_future_units.py b/tests/test_future/test_future_container/test_future_units.py index 06490ab6c..55f75b4c9 100644 --- a/tests/test_future/test_future_container/test_future_units.py +++ b/tests/test_future/test_future_container/test_future_units.py @@ -1,4 +1,5 @@ -from typing import Any, Awaitable, List +from collections.abc import Awaitable +from typing import Any import pytest @@ -9,7 +10,7 @@ @pytest.mark.anyio async def test_inner_value(subtests): """Ensure that coroutine correct value is preserved for all units.""" - containers: List[Awaitable[Any]] = [ + containers: list[Awaitable[Any]] = [ # We have to define these values inside the test, because # otherwise `anyio` will `await` reused coroutines. # And they have to be fresh. That's why we use subtests for it. diff --git a/tests/test_future/test_future_result/test_future_result_decorator.py b/tests/test_future/test_future_result/test_future_result_decorator.py index ddb35289d..ef7a0a716 100644 --- a/tests/test_future/test_future_result/test_future_result_decorator.py +++ b/tests/test_future/test_future_result/test_future_result_decorator.py @@ -1,4 +1,3 @@ -from typing import Union import pytest @@ -17,7 +16,7 @@ async def _coro_two(arg: int) -> float: @future_safe((ZeroDivisionError,)) -async def _coro_three(arg: Union[int, str]) -> float: +async def _coro_three(arg: int | str) -> float: assert isinstance(arg, int) return 1 / arg diff --git a/tests/test_io/test_ioresult_container/test_ioresult_functions/test_impure_safe.py b/tests/test_io/test_ioresult_container/test_ioresult_functions/test_impure_safe.py index 736f8bb05..80251273c 100644 --- a/tests/test_io/test_ioresult_container/test_ioresult_functions/test_impure_safe.py +++ b/tests/test_io/test_ioresult_container/test_ioresult_functions/test_impure_safe.py @@ -1,4 +1,3 @@ -from typing import Union import pytest @@ -11,13 +10,13 @@ def _function(number: int) -> float: @impure_safe(exceptions=(ZeroDivisionError,)) -def _function_two(number: Union[int, str]) -> float: +def _function_two(number: int | str) -> float: assert isinstance(number, int) return number / number @impure_safe((ZeroDivisionError,)) # no name -def _function_three(number: Union[int, str]) -> float: +def _function_three(number: int | str) -> float: assert isinstance(number, int) return number / number diff --git a/tests/test_iterables/test_fold/test_collect.py b/tests/test_iterables/test_fold/test_collect.py index 5b708220e..9688f392c 100644 --- a/tests/test_iterables/test_fold/test_collect.py +++ b/tests/test_iterables/test_fold/test_collect.py @@ -1,5 +1,5 @@ import sys -from typing import Iterable, List, Sequence, Tuple +from collections.abc import Iterable, Sequence import pytest @@ -120,7 +120,7 @@ def test_fold_collect_reader(iterable, sequence): @pytest.mark.anyio async def test_fold_collect_reader_future_result(subtests): """Iterable for ``ReaderFutureResult`` and ``Fold``.""" - containers: List[Tuple[ # noqa: WPS234 + containers: list[tuple[ # noqa: WPS234 Iterable[ReaderFutureResult[int, str, NoDeps]], ReaderFutureResult[Sequence[int], str, NoDeps], ]] = [ @@ -162,7 +162,7 @@ async def test_fold_collect_reader_future_result(subtests): @pytest.mark.anyio async def test_fold_collect_future(subtests): """Iterable for ``Future`` and ``Fold``.""" - containers: List[Tuple[ # noqa: WPS234 + containers: list[tuple[ # noqa: WPS234 Iterable[Future[int]], Future[Sequence[int]], ]] = [ @@ -183,7 +183,7 @@ async def test_fold_collect_future(subtests): @pytest.mark.anyio async def test_fold_collect_future_result(subtests): """Iterable for ``FutureResult`` and ``Fold``.""" - containers: List[Tuple[ # noqa: WPS234 + containers: list[tuple[ # noqa: WPS234 Iterable[FutureResult[int, str]], FutureResult[Sequence[int], str], ]] = [ diff --git a/tests/test_iterables/test_fold/test_collect_all.py b/tests/test_iterables/test_fold/test_collect_all.py index adf294f50..70eaf391a 100644 --- a/tests/test_iterables/test_fold/test_collect_all.py +++ b/tests/test_iterables/test_fold/test_collect_all.py @@ -1,5 +1,5 @@ import sys -from typing import Iterable, List, Sequence, Tuple +from collections.abc import Iterable, Sequence import pytest @@ -99,7 +99,7 @@ def test_collect_all_reader_result(iterable, sequence): @pytest.mark.anyio async def test_collect_all_reader_future_result(subtests): """Iterable for ``ReaderFutureResult`` and ``Fold``.""" - containers: List[Tuple[ # noqa: WPS234 + containers: list[tuple[ # noqa: WPS234 Iterable[ReaderFutureResult[int, str, NoDeps]], ReaderFutureResult[Sequence[int], str, NoDeps], ]] = [ @@ -141,7 +141,7 @@ async def test_collect_all_reader_future_result(subtests): @pytest.mark.anyio async def test_collect_all_future_result(subtests): """Iterable for ``FutureResult`` and ``Fold``.""" - containers: List[Tuple[ # noqa: WPS234 + containers: list[tuple[ # noqa: WPS234 Iterable[FutureResult[int, str]], FutureResult[Sequence[int], str], ]] = [ diff --git a/tests/test_iterables/test_fold/test_loop.py b/tests/test_iterables/test_fold/test_loop.py index a45c02469..6b3ac6f03 100644 --- a/tests/test_iterables/test_fold/test_loop.py +++ b/tests/test_iterables/test_fold/test_loop.py @@ -1,5 +1,5 @@ import sys -from typing import Iterable, List, Tuple +from collections.abc import Iterable import pytest @@ -128,7 +128,7 @@ def test_fold_loop_reader(iterable, sequence): @pytest.mark.anyio async def test_fold_loop_reader_future_result(subtests): """Iterable for ``ReaderFutureResult`` and ``Fold``.""" - containers: List[Tuple[ # noqa: WPS234 + containers: list[tuple[ # noqa: WPS234 Iterable[ReaderFutureResult[int, str, NoDeps]], ReaderFutureResult[int, str, NoDeps], ]] = [ @@ -177,7 +177,7 @@ async def test_fold_loop_reader_future_result(subtests): @pytest.mark.anyio async def test_fold_collect_future(subtests): """Iterable for ``Future`` and ``Fold``.""" - containers: List[Tuple[ # noqa: WPS234 + containers: list[tuple[ # noqa: WPS234 Iterable[Future[int]], Future[int], ]] = [ @@ -198,7 +198,7 @@ async def test_fold_collect_future(subtests): @pytest.mark.anyio async def test_fold_collect_future_result(subtests): """Iterable for ``FutureResult`` and ``Fold``.""" - containers: List[Tuple[ # noqa: WPS234 + containers: list[tuple[ # noqa: WPS234 Iterable[FutureResult[int, str]], FutureResult[int, str], ]] = [ diff --git a/tests/test_maybe/test_maybe_bind.py b/tests/test_maybe/test_maybe_bind.py index c3f66c095..27516d2e2 100644 --- a/tests/test_maybe/test_maybe_bind.py +++ b/tests/test_maybe/test_maybe_bind.py @@ -1,4 +1,3 @@ -from typing import Optional from returns.maybe import Maybe, Nothing, Some @@ -17,7 +16,7 @@ def factory(inner_value: int) -> Maybe[int]: def test_bind_optional(): """Ensures that bind_optional works correctly.""" - def factory(inner_value: int) -> Optional[int]: + def factory(inner_value: int) -> int | None: return inner_value if inner_value else None assert Some(1).bind_optional(factory) == Some(1) diff --git a/tests/test_maybe/test_maybe_functions/test_maybe_decorator.py b/tests/test_maybe/test_maybe_functions/test_maybe_decorator.py index 50eca0929..2561f7594 100644 --- a/tests/test_maybe/test_maybe_functions/test_maybe_decorator.py +++ b/tests/test_maybe/test_maybe_functions/test_maybe_decorator.py @@ -1,10 +1,9 @@ -from typing import Dict, Optional from returns.maybe import Nothing, Some, maybe @maybe -def _function(hashmap: Dict[str, str], key: str) -> Optional[str]: +def _function(hashmap: dict[str, str], key: str) -> str | None: return hashmap.get(key, None) diff --git a/tests/test_methods/test_partition.py b/tests/test_methods/test_partition.py index d68faefb8..f6ec452f2 100644 --- a/tests/test_methods/test_partition.py +++ b/tests/test_methods/test_partition.py @@ -1,4 +1,3 @@ - import pytest from returns.io import IO, IOResult diff --git a/tests/test_pipeline/test_managed/test_managed_future_result.py b/tests/test_pipeline/test_managed/test_managed_future_result.py index aeb2d122d..e7947f49e 100644 --- a/tests/test_pipeline/test_managed/test_managed_future_result.py +++ b/tests/test_pipeline/test_managed/test_managed_future_result.py @@ -1,4 +1,3 @@ -from typing import List, Tuple import pytest @@ -25,7 +24,7 @@ def _use_failure(inner_value: str) -> FutureResult[str, str]: class _ReleaseSuccess: - def __init__(self, logs: List[Tuple[str, Result[str, str]]]) -> None: + def __init__(self, logs: list[tuple[str, Result[str, str]]]) -> None: self._logs = logs def __call__( @@ -38,7 +37,7 @@ def __call__( class _ReleaseFailure: - def __init__(self, logs: List[Tuple[str, Result[str, str]]]) -> None: + def __init__(self, logs: list[tuple[str, Result[str, str]]]) -> None: self._logs = logs def __call__( @@ -113,7 +112,7 @@ def __call__( ]) async def test_all_success(acquire, use, release, final_result, log): """Ensures that managed works as intended.""" - pipeline_logs: List[Tuple[str, Result[str, str]]] = [] + pipeline_logs: list[tuple[str, Result[str, str]]] = [] pipeline_result = managed( use, release(pipeline_logs), @@ -126,7 +125,7 @@ async def test_all_success(acquire, use, release, final_result, log): @pytest.mark.anyio async def test_full_typing(): """This test is here to be a case for typing.""" - logs: List[Tuple[str, Result[str, str]]] = [] + logs: list[tuple[str, Result[str, str]]] = [] pipeline_result = managed( _use_success, _ReleaseSuccess(logs), diff --git a/tests/test_pipeline/test_managed/test_managed_ioresult.py b/tests/test_pipeline/test_managed/test_managed_ioresult.py index e7f28dc9b..5281ceac5 100644 --- a/tests/test_pipeline/test_managed/test_managed_ioresult.py +++ b/tests/test_pipeline/test_managed/test_managed_ioresult.py @@ -1,4 +1,3 @@ -from typing import List, Tuple import pytest @@ -19,7 +18,7 @@ def _use_failure(inner_value: str) -> IOResult[str, str]: class _ReleaseSuccess: - def __init__(self, logs: List[Tuple[str, Result[str, str]]]) -> None: + def __init__(self, logs: list[tuple[str, Result[str, str]]]) -> None: self._logs = logs def __call__( @@ -32,7 +31,7 @@ def __call__( class _ReleaseFailure: - def __init__(self, logs: List[Tuple[str, Result[str, str]]]) -> None: + def __init__(self, logs: list[tuple[str, Result[str, str]]]) -> None: self._logs = logs def __call__( @@ -106,7 +105,7 @@ def __call__( ]) def test_all_success(acquire, use, release, final_result, log): """Ensures that managed works as intended.""" - pipeline_logs: List[Tuple[str, Result[str, str]]] = [] + pipeline_logs: list[tuple[str, Result[str, str]]] = [] pipeline_result = managed( use, release(pipeline_logs), @@ -118,7 +117,7 @@ def test_all_success(acquire, use, release, final_result, log): def test_full_typing(): """This test is here to be a case for typing.""" - logs: List[Tuple[str, Result[str, str]]] = [] + logs: list[tuple[str, Result[str, str]]] = [] pipeline_result = managed( _use_success, _ReleaseSuccess(logs), diff --git a/tests/test_pipeline/test_managed/test_managed_reader_future_result.py b/tests/test_pipeline/test_managed/test_managed_reader_future_result.py index d1d883693..4aa364e43 100644 --- a/tests/test_pipeline/test_managed/test_managed_reader_future_result.py +++ b/tests/test_pipeline/test_managed/test_managed_reader_future_result.py @@ -1,4 +1,3 @@ -from typing import List, Tuple import pytest @@ -25,7 +24,7 @@ def _use_failure(inner_value: str) -> ReaderFutureResult[str, str, NoDeps]: class _ReleaseSuccess: - def __init__(self, logs: List[Tuple[str, Result[str, str]]]) -> None: + def __init__(self, logs: list[tuple[str, Result[str, str]]]) -> None: self._logs = logs def __call__( @@ -38,7 +37,7 @@ def __call__( class _ReleaseFailure: - def __init__(self, logs: List[Tuple[str, Result[str, str]]]) -> None: + def __init__(self, logs: list[tuple[str, Result[str, str]]]) -> None: self._logs = logs def __call__( @@ -113,7 +112,7 @@ def __call__( ]) async def test_all_success(acquire, use, release, final_result, log): """Ensures that managed works as intended.""" - pipeline_logs: List[Tuple[str, Result[str, str]]] = [] + pipeline_logs: list[tuple[str, Result[str, str]]] = [] pipeline_result = managed( use, release(pipeline_logs), @@ -126,7 +125,7 @@ async def test_all_success(acquire, use, release, final_result, log): @pytest.mark.anyio async def test_full_typing(): """This test is here to be a case for typing.""" - logs: List[Tuple[str, Result[str, str]]] = [] + logs: list[tuple[str, Result[str, str]]] = [] pipeline_result = managed( _use_success, _ReleaseSuccess(logs), diff --git a/tests/test_pipeline/test_managed/test_managed_reader_ioresult.py b/tests/test_pipeline/test_managed/test_managed_reader_ioresult.py index f4f1626df..82cf6e973 100644 --- a/tests/test_pipeline/test_managed/test_managed_reader_ioresult.py +++ b/tests/test_pipeline/test_managed/test_managed_reader_ioresult.py @@ -1,4 +1,3 @@ -from typing import List, Tuple import pytest @@ -20,7 +19,7 @@ def _use_failure(inner_value: str) -> ReaderIOResult[str, str, NoDeps]: class _ReleaseSuccess: - def __init__(self, logs: List[Tuple[str, Result[str, str]]]) -> None: + def __init__(self, logs: list[tuple[str, Result[str, str]]]) -> None: self._logs = logs def __call__( @@ -33,7 +32,7 @@ def __call__( class _ReleaseFailure: - def __init__(self, logs: List[Tuple[str, Result[str, str]]]) -> None: + def __init__(self, logs: list[tuple[str, Result[str, str]]]) -> None: self._logs = logs def __call__( @@ -107,7 +106,7 @@ def __call__( ]) def test_all_success(acquire, use, release, final_result, log): """Ensures that managed works as intended.""" - pipeline_logs: List[Tuple[str, Result[str, str]]] = [] + pipeline_logs: list[tuple[str, Result[str, str]]] = [] pipeline_result = managed( use, release(pipeline_logs), @@ -119,7 +118,7 @@ def test_all_success(acquire, use, release, final_result, log): def test_full_typing(): """This test is here to be a case for typing.""" - logs: List[Tuple[str, Result[str, str]]] = [] + logs: list[tuple[str, Result[str, str]]] = [] pipeline_result = managed( _use_success, _ReleaseSuccess(logs), diff --git a/tests/test_primitives/test_asserts/test_assert_equal.py b/tests/test_primitives/test_asserts/test_assert_equal.py index 51b5356e7..78af6715a 100644 --- a/tests/test_primitives/test_asserts/test_assert_equal.py +++ b/tests/test_primitives/test_asserts/test_assert_equal.py @@ -1,4 +1,4 @@ -from typing import Sequence +from collections.abc import Sequence import pytest diff --git a/tests/test_primitives/test_laws/test_lawful/test_laws_resolution.py b/tests/test_primitives/test_laws/test_lawful/test_laws_resolution.py index 06f4709f2..af9e656d9 100644 --- a/tests/test_primitives/test_laws/test_lawful/test_laws_resolution.py +++ b/tests/test_primitives/test_laws/test_lawful/test_laws_resolution.py @@ -1,4 +1,3 @@ -from typing import List, Type import pytest @@ -27,9 +26,9 @@ RequiresContextIOResult, RequiresContextResult, ]) -def test_laws_resolution(container: Type[Lawful]): +def test_laws_resolution(container: type[Lawful]): """Ensures all tests are unique.""" - all_laws: List[Law] = [] + all_laws: list[Law] = [] for laws in container.laws().values(): all_laws.extend(laws) assert len(all_laws) == len(set(all_laws)) diff --git a/tests/test_result/test_result_functions/test_safe.py b/tests/test_result/test_result_functions/test_safe.py index d574ba2c1..90c972aa8 100644 --- a/tests/test_result/test_result_functions/test_safe.py +++ b/tests/test_result/test_result_functions/test_safe.py @@ -1,4 +1,3 @@ -from typing import Union import pytest @@ -11,13 +10,13 @@ def _function(number: int) -> float: @safe(exceptions=(ZeroDivisionError,)) -def _function_two(number: Union[int, str]) -> float: +def _function_two(number: int | str) -> float: assert isinstance(number, int) return number / number @safe((ZeroDivisionError,)) # no name -def _function_three(number: Union[int, str]) -> float: +def _function_three(number: int | str) -> float: assert isinstance(number, int) return number / number diff --git a/tests/test_trampolines/test_trampoline_decorator.py b/tests/test_trampolines/test_trampoline_decorator.py index 9e6b107e4..ca64751fc 100644 --- a/tests/test_trampolines/test_trampoline_decorator.py +++ b/tests/test_trampolines/test_trampoline_decorator.py @@ -1,5 +1,5 @@ import sys -from typing import Callable, Iterator, Union +from collections.abc import Callable, Iterator import pytest @@ -10,7 +10,7 @@ def _accumulate( numbers: Iterator[int], acc: int = 0, -) -> Union[int, Trampoline[int]]: +) -> int | Trampoline[int]: number = next(numbers, None) if number is None: return acc @@ -21,7 +21,7 @@ def _accumulate( def _with_func_kwarg( numbers: Iterator[int], func: int = 0, # we need this name to match `Trampoline` constructor -) -> Union[int, Trampoline[int]]: +) -> int | Trampoline[int]: number = next(numbers, None) if number is None: return func diff --git a/typesafety/test_primitives/test_tracing/test_collect_traces.yml b/typesafety/test_primitives/test_tracing/test_collect_traces.yml index b2a3925ce..2bacedebe 100644 --- a/typesafety/test_primitives/test_tracing/test_collect_traces.yml +++ b/typesafety/test_primitives/test_tracing/test_collect_traces.yml @@ -1,4 +1,5 @@ - case: collect_traces_context_manager_return_type_one + skip: sys.version_info[:2] >= (3, 13) disable_cache: false main: | from returns.primitives.tracing import collect_traces @@ -6,6 +7,7 @@ reveal_type(collect_traces) # N: Revealed type is "Overload(def () -> typing.ContextManager[None], def [_FunctionType <: def (*Any, **Any) -> Any] (function: _FunctionType`-1) -> _FunctionType`-1)" - case: collect_traces_context_manager_return_type_two + skip: sys.version_info[:2] >= (3, 13) disable_cache: false main: | from returns.primitives.tracing import collect_traces