From 3fdcefc458de1142e1b91c0d796d87cadf625cdc Mon Sep 17 00:00:00 2001 From: acostapazo Date: Sat, 13 May 2023 16:17:47 +0200 Subject: [PATCH] chore: add future annotations to modernize syntax (#62) --- meiga/alias.py | 6 +++--- meiga/deprecation.py | 12 +++++++----- meiga/error.py | 6 ++++-- meiga/handlers.py | 8 +++++--- meiga/misc.py | 4 +++- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/meiga/alias.py b/meiga/alias.py index 5410eb1..daa9847 100644 --- a/meiga/alias.py +++ b/meiga/alias.py @@ -20,6 +20,6 @@ def __init__(self, error: TF = cast(TF, Error())) -> None: BoolResult = Result[bool, Error] AnyResult = Result[Any, Error] -isSuccess: BoolResult = Success() -isFailure: BoolResult = Failure() -NotImplementedMethodError: BoolResult = isFailure +isSuccess: AnyResult = Success() +isFailure: AnyResult = Failure() +NotImplementedMethodError: AnyResult = isFailure diff --git a/meiga/deprecation.py b/meiga/deprecation.py index 87aa635..81e83de 100644 --- a/meiga/deprecation.py +++ b/meiga/deprecation.py @@ -1,11 +1,13 @@ -from typing import Any, Dict, Union +from __future__ import annotations + +from typing import Any from meiga.handlers import OnFailureHandler, OnSuccessHandler def get_on_success_handler_from_deprecated_args( - kwargs: Dict[Any, Any], -) -> Union[OnSuccessHandler, None]: + kwargs: dict[Any, Any] +) -> OnSuccessHandler | None: on_success = kwargs.get("on_success") if on_success: return OnSuccessHandler(func=on_success, args=kwargs.get("success_args")) @@ -13,8 +15,8 @@ def get_on_success_handler_from_deprecated_args( def get_on_failure_handler_from_deprecated_args( - kwargs: Dict[Any, Any], -) -> Union[OnFailureHandler, None]: + kwargs: dict[Any, Any], +) -> OnFailureHandler | None: on_failure = kwargs.get("on_failure") if on_failure: return OnFailureHandler(func=on_failure, args=kwargs.get("failure_args")) diff --git a/meiga/error.py b/meiga/error.py index 56b72f3..18ec029 100644 --- a/meiga/error.py +++ b/meiga/error.py @@ -1,8 +1,10 @@ -from typing import Any, Union +from __future__ import annotations + +from typing import Any class Error(Exception): - message: Union[str, None] + message: str | None def __init__(self) -> None: self.message = None diff --git a/meiga/handlers.py b/meiga/handlers.py index d67dc02..1726cae 100644 --- a/meiga/handlers.py +++ b/meiga/handlers.py @@ -1,4 +1,6 @@ -from typing import TYPE_CHECKING, Any, Callable, Iterable, Union +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, Callable, Iterable from meiga.misc import get_args_list @@ -8,12 +10,12 @@ class Handler: def __init__( - self, func: Callable[..., None], args: Union[Iterable[Any], None] = None + self, func: Callable[..., None], args: Iterable[Any] | None = None ) -> None: self.func = func self.args = args - def execute(self, result: "Result[TS, TF]") -> None: + def execute(self, result: Result[TS, TF]) -> None: if self.args is not None: failure_args = get_args_list(self.args) if result.__id__ in failure_args: diff --git a/meiga/misc.py b/meiga/misc.py index 4810699..0f7b924 100644 --- a/meiga/misc.py +++ b/meiga/misc.py @@ -1,7 +1,9 @@ +from __future__ import annotations + from typing import Any, List, cast -def get_args_list(args: Any) -> List[Any]: +def get_args_list(args: Any) -> list[Any]: if isinstance(args, tuple): list_args = list(args) else: