kd.konfig.ref_fn

kd.konfig.ref_fn#

kauldron.konfig.ref_fn(
fn: kauldron.konfig.ref_utils._FnT,
) kauldron.konfig.ref_utils._FnT[source]
kauldron.konfig.ref_fn(fn: typing.Callable[[~_P], kauldron.konfig.ref_utils._T], *args: typing.~_P, **kwargs: typing.~_P) kauldron.konfig.ref_utils._T

Wrap a function for lazy-evaluation.

Example:

@konfig.ref_fn
def _join_parts(parts):
  return '/'.join(parts)

cfg = konfig.ConfigDict()
cfg.parts = ['a', 'b', 'c']
cfg.joined_parts = _join_parts(cfg.ref.parts)

assert cfg.joined_parts == 'a/b/c'

cfg.parts = ['d', 'e', 'f']
assert cfg.joined_parts == 'd/e/f'

When cfg.joined_parts is accessed, the _join_parts lazy function will be executed.

Can also be applied inline:

cfg.joined_parts = konfig.ref_fn('\'.join, cfg.ref.parts)
Parameters:
  • fn – The function to lazy-evaluate

  • *args – Args and kwargs to pass to the function

  • **kwargs – Args and kwargs to pass to the function

Returns:

The FieldReference to be assigned.