hydra_zen.kwargs_of#

hydra_zen.kwargs_of(_BuildsFn__hydra_target, *, zen_dataclass=None, zen_exclude=None, **kwarg_overrides)#

Returns a config whose signature matches that of the provided target.

Instantiating the config returns a dictionary.

Parameters:
__hydra_targetCallable[P, Any]

An object with an inspectable signature.

zen_excludeCollection[str | int] | Callable[[str], bool], optional (default=[])

Specifies parameter names and/or indices, or a function for checking names, to exclude those parameters from the config-creation process.

**kwarg_overridesT

Named overrides for the parameters’ default values.

Returns:
type[Builds[type[dict[str, Any]]]]

Examples

>>> from inspect import signature
>>> from hydra_zen import kwargs_of, instantiate
>>> Config = kwargs_of(lambda x, y: None)
>>> signature(Config)
<Signature (x:Any, y: Any) -> None>
>>> config = Config(x=1, y=2)
>>> config
kwargs_of_lambda(x=1, y=2)
>>> instantiate(config)
{'x': 1, 'y': 2}

Excluding the first parameter from the target’s signature:

>>> Config = kwargs_of(lambda *, x, y: None, zen_exclude=(0,))
>>> signature(Config)  # note: type checkers sees that x is removed as well
<Signature (y: Any) -> None>
>>> instantiate(Config(y=88))
{'y': 88}

Overwriting a default

>>> Config = kwargs_of(lambda *, x, y: None, y=22)
>>> signature(Config)
<Signature (x: Any, y: Any = 22) -> None>