Skip to main content

deprecation_utils

Utilities for managing deprecated module-level re-exports.

Use deprecated_module_getattr to create a module __getattr__ that lazily imports names that have moved to a new module, emitting a DeprecationWarning on first access.

Example usage in a module whose symbols have moved elsewhere:

from bitfount.utils.deprecation_utils import deprecated_module_getattr

_DEPRECATED_NAMES: dict[str, str | tuple[str, str]] = {
"old_function": "bitfount.new_module",
"renamed_func": ("bitfount.new_module", "new_func"),
}

__getattr__ = deprecated_module_getattr(__name__, _DEPRECATED_NAMES)

Module

Functions

deprecated_module_getattr

def deprecated_module_getattr(    module_name: str, deprecated_names: dict[str, str | tuple[str, str]],)> collections.abc.Callable[[str], typing.Any]:

Create a module-level __getattr__ for deprecated re-exports.

Arguments

  • module_name: The __name__ of the module installing the hook.
  • deprecated_names: Mapping of old_name to either:
  • A module path (str) — the symbol keeps its name in the new module.
  • A (module_path, new_name) tuple — the symbol was renamed.

Returns A __getattr__ function suitable for assignment at module scope.