Skip to content

Commit

Permalink
feat: add inline option to subroutine decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
boblat committed Jan 20, 2025
1 parent 2a25f89 commit 2cc15b3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/_algopy_testing/decorators/subroutine.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
from collections.abc import Callable
from typing import ParamSpec, TypeVar
from functools import partial, wraps
from typing import Literal, ParamSpec, TypeVar, overload

_P = ParamSpec("_P")
_R = TypeVar("_R")


def subroutine(sub: Callable[_P, _R]) -> Callable[_P, _R]:
return sub
@overload
def subroutine(sub: Callable[_P, _R], /) -> Callable[_P, _R]: ...
@overload
def subroutine(
*, inline: bool | Literal["auto"] = "auto"
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
def subroutine(
sub: Callable[_P, _R] | None = None, *, inline: bool | Literal["auto"] = "auto"
) -> Callable[_P, _R] | Callable[[Callable[_P, _R]], Callable[_P, _R]]:
if sub is None:
return partial(subroutine, inline=inline)

@wraps(sub)
def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R:
return sub(*args, **kwargs)

return wrapper

0 comments on commit 2cc15b3

Please # to comment.