pygsti.tools.legacytools

Functions related deprecating other functions

Module Contents

Functions

warn_deprecated(name, replacement=None)

Formats and prints a deprecation warning message.

deprecate(replacement=None)

Decorator for deprecating a function.

deprecate_imports(module_name, replacement_map, warning_msg)

Utility to deprecate imports from a module.

pygsti.tools.legacytools.warn_deprecated(name, replacement=None)

Formats and prints a deprecation warning message.

Parameters
  • name (str) – The name of the function that is now deprecated.

  • replacement (str, optional) – the name of the function that should replace it.

Returns

None

pygsti.tools.legacytools.deprecate(replacement=None)

Decorator for deprecating a function.

Parameters

replacement (str, optional) – the name of the function that should replace it.

Returns

function

pygsti.tools.legacytools.deprecate_imports(module_name, replacement_map, warning_msg)

Utility to deprecate imports from a module.

This works by swapping the underlying module in the import mechanisms with a ModuleType object that overrides attribute lookup to check against the replacement map.

Note that this will slow down module attribute lookup substantially. If you need to deprecate multiple names, DO NOT call this method more than once on a given module! Instead, use the replacement map to batch multiple deprecations into one call. When using this method, plan to remove the deprecated paths altogether sooner rather than later.

Parameters
  • module_name (str) – The fully-qualified name of the module whose names have been deprecated.

  • replacement_map ({name: function}) – A map of each deprecated name to a factory which will be called with no arguments when importing the name.

  • warning_msg (str) – A message to be displayed as a warning when importing a deprecated name. Optionally, this may include the format string name, which will be formatted with the deprecated name.

Returns

None