synthesizer.warnings¶
A module containing warnings and deprecation utilities.
This module contains functions and decorators for issuing warnings to the end user.
Example usage:
deprecation("x will have to be a unyt_array in future versions.")
@deprecated()
def old_function():
pass
@deprecated("will be removed in v2.0")
def old_function():
pass
warn("This is a warning message.")
Functions
- synthesizer.warnings.deprecated(message=None, category=<class 'FutureWarning'>)[source]¶
Decorate a function to mark it as deprecated.
This decorator will issue a warning to the end user when the function is called. The message and category can be optionally specified, if not a default message will be used and FutureWarning will be issued (which will by default warn the end user unless explicitly silenced).
- Parameters:
message (str) – The message to be displayed to the end user. If None a default message will be used.
category (Warning) – The warning category to use. FutureWarning by default.
- synthesizer.warnings.deprecation(message, category=<class 'FutureWarning'>)[source]¶
Issue a deprecation warning to the end user.
A message must be specified, and a category can be optionally specified. FutureWarning will, by default, warn the end user, DeprecationWarning will only warn when the user has set the PYTHONWARNINGS environment variable, and PendingDeprecationWarning can be used for far future deprecations.
- Parameters:
message (str) – The message to be displayed to the end user.
category (Warning) – The warning category to use. FutureWarning by default.
- synthesizer.warnings.warn(message, category=<class 'RuntimeWarning'>, stacklevel=3)[source]¶
Issue a warning to the end user.
A message must be specified, and a category can be optionally specified. RuntimeWarning will, by default, warn the end user, and can be silenced by setting the PYTHONWARNINGS environment variable.
This function is a simple wrapper around the warnings.warn function but with a default stacklevel of 3, removing the need to specify it each time.
- Parameters:
message (str) – The message to be displayed to the end user.
category (Warning) – The warning category to use. RuntimeWarning by default.
stacklevel (int) – The number of stack levels to skip when displaying the warning.