def get_nested_target()

in chz/blueprint/_entrypoint.py [0:0]


def get_nested_target(main: Callable[[_T], object]) -> type[_T]:
    """Returns the type of the first argument of a function.

    For example:
    ```
    def main(run: Run) -> None: ...

    assert chz.get_nested_target(main) is Run
    ```
    """
    params = list(inspect.signature(main).parameters.values())
    if not params or params[0].annotation == inspect.Parameter.empty:
        raise ValueError("Nested entrypoints must take a type annotated argument")
    if any(p.default is p.empty for p in params[1:]):
        raise ValueError("Nested entrypoints must take at most one argument without a default")
    return _resolve_annotation(params[0].annotation, main)