diff --git a/meiga/decorators/meiga_decorator.py b/meiga/decorators/meiga_decorator.py index 323b64d..bb1c335 100644 --- a/meiga/decorators/meiga_decorator.py +++ b/meiga/decorators/meiga_decorator.py @@ -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()) @@ -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