Skip to content

Commit 7b3fea8

Browse files
authored
Merge pull request #29 from algorandfoundation/feat/subroutine-inline
feat: add inline option to subroutine decorator
2 parents 2a25f89 + 2cc15b3 commit 7b3fea8

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
from collections.abc import Callable
2-
from typing import ParamSpec, TypeVar
2+
from functools import partial, wraps
3+
from typing import Literal, ParamSpec, TypeVar, overload
34

45
_P = ParamSpec("_P")
56
_R = TypeVar("_R")
67

78

8-
def subroutine(sub: Callable[_P, _R]) -> Callable[_P, _R]:
9-
return sub
9+
@overload
10+
def subroutine(sub: Callable[_P, _R], /) -> Callable[_P, _R]: ...
11+
@overload
12+
def subroutine(
13+
*, inline: bool | Literal["auto"] = "auto"
14+
) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
15+
def subroutine(
16+
sub: Callable[_P, _R] | None = None, *, inline: bool | Literal["auto"] = "auto"
17+
) -> Callable[_P, _R] | Callable[[Callable[_P, _R]], Callable[_P, _R]]:
18+
if sub is None:
19+
return partial(subroutine, inline=inline)
20+
21+
@wraps(sub)
22+
def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R:
23+
return sub(*args, **kwargs)
24+
25+
return wrapper

0 commit comments

Comments
 (0)