deprecate_submodule

glotaran.deprecation.deprecation_utils.deprecate_submodule(*, deprecated_module_name: str, new_module_name: str, to_be_removed_in_version: str, module_load_overwrite: str = '') module[source]

Create a module at runtime which retrieves attributes from new module.

When moving a module, create a variable with the modules name in the parent packages __init__.py, so imports will be redirected to the new module location and a deprecation warning will be given, to help the user adjust the outdated code. Each time an attribute is retrieved there will be a deprecation warning.

Parameters:
  • deprecated_module_name (str) – Fully qualified name of the deprecated module e.g.: 'glotaran.analysis.result'

  • new_module_name (str) – Fully qualified name of the new module e.g.: 'glotaran.project.result'

  • to_be_removed_in_version (str) – Version the support for this usage will be removed.

  • module_load_overwrite (str) – Overwrite the location for the new module the deprecated functionality is loaded from. This allows preserving functionality without polluting a new module with code just for the sake of it. By default ‘’

Returns:

Module containing

Return type:

ModuleType

Raises:

OverDueDeprecation – If the current version is greater or equal to to_be_removed_in_version.

Examples

When moving the module result from glotaran.analysis.result to glotaran.project.result the following code was added to the old parent packages (glotaran.analysis) __init__.py.

glotaran/analysis/__init__.py
from glotaran.deprecation.deprecation_utils import deprecate_submodule

result = deprecate_submodule(
    deprecated_module_name="glotaran.analysis.result",
    new_module_name="glotaran.project.result",
    to_be_removed_in_version="0.6.0",
)