Skip to content

Commit

Permalink
chore(types): add type hints to meiga decorator (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
acostapazo authored Aug 9, 2022
1 parent f32b412 commit fed8617
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions meiga/decorators/meiga_decorator.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
from functools import wraps
from typing import Callable, TypeVar, cast

from typing_extensions import ParamSpec

from meiga.alias import Failure
from meiga.decorators.unexpected_decoration_order_error import (
UnexpectedDecorationOrderError,
)
from meiga.error import Error
from meiga.on_failure_exception import OnFailureException
from meiga.result import Result

P = ParamSpec("P")
R = TypeVar("R", bound=Result)


def meiga(func):
def _meiga(*args, **kwargs):
def meiga(func: Callable[P, R]) -> Callable[P, R]:
@wraps(func)
def _meiga(*args: P.args, **kwargs: P.kwargs) -> R:
try:
if isinstance(func, staticmethod):
return Failure(UnexpectedDecorationOrderError())
Expand All @@ -18,6 +28,6 @@ def _meiga(*args, **kwargs):
except OnFailureException as exc:
return exc.result
except Error as error:
return Failure(error)
return cast(R, Failure(error))

return _meiga

0 comments on commit fed8617

Please sign in to comment.