resolve_alias

Contents

resolve_alias#

rapidtools.config.resolve_alias(kwargs: dict[str, Any], new_name: str, *old_names: str, default: Any = None, stacklevel: int = 3) → Any[source]#

Pop a deprecated keyword alias from kwargs and return the value.

Used while parameter names are being harmonized: components accept the new name (e.g. save_directory) and still honour the old one (e.g. output_dir) with a DeprecationWarning.

Parameters:
  • kwargs – The **kwargs dict received by the constructor (mutated).

  • new_name – The canonical parameter name, for the warning message.

  • *old_names – Deprecated aliases to look for, in priority order.

  • default – Value returned when no alias is present.

  • stacklevel – Passed to warnings.warn().

Returns:

Any – The alias value, or default.

Raises:

TypeError – If kwargs still holds unrelated keys afterwards (mirrors the error a normal signature would raise).

Example

>>> from rapidtools.config import resolve_alias
>>> kwargs = {'output_dir': 'tiles'}
>>> resolve_alias(kwargs, 'save_directory', 'output_dir')  # warns
'tiles'
>>> kwargs
{}