Coverage for src/gone/core.py: 100%
21 statements
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-16 12:01 +0200
« prev ^ index » next coverage.py v7.6.0, created at 2024-07-16 12:01 +0200
1import functools
2import typing as t
4P = t.ParamSpec("P")
5R = t.TypeVar("R")
8def args(fn: t.Callable[P, R]) -> t.Callable[..., R]:
9 """
10 A decorator that absorbs all input arguments and calls the decorated function without them.
12 Args:
13 fn (t.Callable[P, R]): The function to be decorated.
15 Returns:
16 t.Callable[..., R]: A decorated function that ignores its input arguments.
17 """
19 @functools.wraps(fn)
20 def inner(*_: t.Any, **__: t.Any) -> R:
21 return fn()
23 return inner
26def result(fn: t.Callable[P, R]) -> t.Callable[P, None]:
27 """
28 A decorator that discards the result of the decorated function.
30 Args:
31 fn (t.Callable[P, R]): The function to be decorated.
33 Returns:
34 t.Callable[P, None]: A decorated function that ignores its output.
35 """
37 @functools.wraps(fn)
38 def inner(*a: P.args, **kw: P.kwargs) -> None:
39 fn(*a, **kw)
40 return None
42 return inner
45def inout(fn: t.Callable[P, R]) -> t.Callable[..., None]:
46 """
47 A decorator that absorbs all input arguments and discards the result of the decorated function.
49 Args:
50 fn (t.Callable[P, R]): The function to be decorated.
52 Returns:
53 t.Callable[..., None]: A decorated function that ignores both its input and output.
54 """
56 @functools.wraps(fn)
57 def inner(*_: t.Any, **__: t.Any) -> None:
58 fn()
59 return None
61 return inner