|
@@ -18,7 +18,6 @@ from cipy.common import Context, Status, _validate
|
|
|
Action = TypeVar("Action", bound=cipy.common.Action)
|
|
Action = TypeVar("Action", bound=cipy.common.Action)
|
|
|
type Run[Action] = Callable[[Action, Context], Status]
|
|
type Run[Action] = Callable[[Action, Context], Status]
|
|
|
type GetLines[Action] = Callable[[Action], str | Iterable[str]]
|
|
type GetLines[Action] = Callable[[Action], str | Iterable[str]]
|
|
|
-type ExtraFormatting[Action] = list[tuple[str, GetLines[Action]]]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
@contextmanager
|
|
@@ -86,44 +85,22 @@ def logging_group(self: Action, message: str, *args: Any) -> Iterator[None]:
|
|
|
|
|
|
|
|
@overload
|
|
@overload
|
|
|
def preamble(
|
|
def preamble(
|
|
|
- func: Run[Action],
|
|
|
|
|
- *,
|
|
|
|
|
- extra: ExtraFormatting[Action] | None = None,
|
|
|
|
|
|
|
+ func: Run[Action], *extra: tuple[str, GetLines[Action]]
|
|
|
) -> Run[Action]: ...
|
|
) -> Run[Action]: ...
|
|
|
|
|
|
|
|
|
|
|
|
|
@overload
|
|
@overload
|
|
|
def preamble(
|
|
def preamble(
|
|
|
- func: ExtraFormatting[Action],
|
|
|
|
|
- *,
|
|
|
|
|
- extra: ExtraFormatting[Action] | None = None,
|
|
|
|
|
-) -> Callable[
|
|
|
|
|
- [Run[Action]],
|
|
|
|
|
- Run[Action],
|
|
|
|
|
-]: ...
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-@overload
|
|
|
|
|
-def preamble(
|
|
|
|
|
- func: None = None, *, extra: ExtraFormatting[Action] | None = None
|
|
|
|
|
|
|
+ func: tuple[str, GetLines[Action]], *extra: tuple[str, GetLines[Action]]
|
|
|
) -> Callable[[Run[Action]], Run[Action]]: ...
|
|
) -> Callable[[Run[Action]], Run[Action]]: ...
|
|
|
|
|
|
|
|
|
|
|
|
|
def preamble(
|
|
def preamble(
|
|
|
- func: Run[Action] | ExtraFormatting[Action] | None = None,
|
|
|
|
|
- *,
|
|
|
|
|
- extra: ExtraFormatting[Action] | None = None,
|
|
|
|
|
|
|
+ func: Run[Action] | tuple[str, GetLines[Action]],
|
|
|
|
|
+ *extra: tuple[str, GetLines[Action]],
|
|
|
):
|
|
):
|
|
|
- if isinstance(func, list):
|
|
|
|
|
- assert extra is None
|
|
|
|
|
- return lambda f: preamble(f, extra=func)
|
|
|
|
|
-
|
|
|
|
|
- if func is None:
|
|
|
|
|
- assert extra is not None
|
|
|
|
|
- return lambda f: preamble(f, extra=extra)
|
|
|
|
|
-
|
|
|
|
|
- if extra is None:
|
|
|
|
|
- extra = []
|
|
|
|
|
|
|
+ if isinstance(func, tuple):
|
|
|
|
|
+ return lambda f: preamble(f, func, *extra)
|
|
|
|
|
|
|
|
@functools.wraps(func)
|
|
@functools.wraps(func)
|
|
|
def wrapper(self: Action, context: Context) -> Status:
|
|
def wrapper(self: Action, context: Context) -> Status:
|