Skip to content

Commit

Permalink
chore: add future annotations to modernize syntax (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
acostapazo authored May 13, 2023
1 parent b3ac895 commit 3fdcefc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
6 changes: 3 additions & 3 deletions meiga/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 7 additions & 5 deletions meiga/deprecation.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
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"))
return None


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"))
Expand Down
6 changes: 4 additions & 2 deletions meiga/error.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 5 additions & 3 deletions meiga/handlers.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion meiga/misc.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 3fdcefc

Please sign in to comment.