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

1import functools 

2import typing as t 

3 

4P = t.ParamSpec("P") 

5R = t.TypeVar("R") 

6 

7 

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. 

11 

12 Args: 

13 fn (t.Callable[P, R]): The function to be decorated. 

14 

15 Returns: 

16 t.Callable[..., R]: A decorated function that ignores its input arguments. 

17 """ 

18 

19 @functools.wraps(fn) 

20 def inner(*_: t.Any, **__: t.Any) -> R: 

21 return fn() 

22 

23 return inner 

24 

25 

26def result(fn: t.Callable[P, R]) -> t.Callable[P, None]: 

27 """ 

28 A decorator that discards the result of the decorated function. 

29 

30 Args: 

31 fn (t.Callable[P, R]): The function to be decorated. 

32 

33 Returns: 

34 t.Callable[P, None]: A decorated function that ignores its output. 

35 """ 

36 

37 @functools.wraps(fn) 

38 def inner(*a: P.args, **kw: P.kwargs) -> None: 

39 fn(*a, **kw) 

40 return None 

41 

42 return inner 

43 

44 

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. 

48 

49 Args: 

50 fn (t.Callable[P, R]): The function to be decorated. 

51 

52 Returns: 

53 t.Callable[..., None]: A decorated function that ignores both its input and output. 

54 """ 

55 

56 @functools.wraps(fn) 

57 def inner(*_: t.Any, **__: t.Any) -> None: 

58 fn() 

59 return None 

60 

61 return inner