lazy ¤
This module contains a lazy
decorator.
LazyCallable ¤
Bases: Generic[_R]
This class allows users to create and pass lazy callables to the runner.
Parameters:
-
call
(Callable[_P, _R]
) –The origin callable.
-
args
(tuple
) –The
*args
to pass when calling. -
kwargs
(dict
) –The
**kwargs
to pass when calling. -
name
(str | None
, default:None
) –The name of the callable.
Source code in src/failprint/lazy.py
22 23 24 25 26 27 28 29 30 31 32 33 34 |
|
lazy ¤
lazy(
call: Callable[_P, _R], name: str | None = None
) -> Callable[_P, LazyCallable]
lazy(
call: None = None, name: str | None = None
) -> _DecoratorType
lazy(
call: Callable[_P, _R] | None = None,
name: str | None = None,
) -> Callable[_P, LazyCallable] | _DecoratorType
Transform a callable into a lazy callable.
Being able to create a lazy callable improves the UX/DX. Instead of having to pass args
and kwargs
to the runner, one can now call the function directly, enjoying auto-completion and other editor features. Before:
from failprint.runners import run
def greet(name):
return f"hello {name}"
run(greet, args=["tim"])
After:
from failprint.runners import run
from failprint.lazy import lazy
@lazy
def greet(name):
return f"hello {name}"
run(greet("tim"))
Parameters:
-
call
(Callable[_P, _R] | None
, default:None
) –The callable to lazify.
-
name
(str | None
, default:None
) –An optional name to give to the new callable.
Returns:
-
Callable[_P, LazyCallable] | _DecoratorType
–A lazy callable instance.
Source code in src/failprint/lazy.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|