improver.utilities.warnings_handler module¶
Classes and functions for managing warnings in the IMPROVER code.
-
class
improver.utilities.warnings_handler.ManageWarnings(ignored_messages=None, warning_types=None, record=False)[source]¶ Bases:
objectA decorator used to manage the warnings that are raised by a function. Ignore a selection of warnings, and either raise any remaining warnings to standard error or record them in a list of warning objects.
-
__init__(ignored_messages=None, warning_types=None, record=False)[source]¶ Set up a decorator with the warnings we want to ignore and what we want to do with any remaining warnings.
- Parameters
ignored_messages (list of str) – A list of messages, one for each warning message we want to ignore.
warning_types (list) – A list containing the Warning category for each of the messages. If not provided then the Warning Category is assumed to be UserWarning for each of the messages.
record (bool) – A flag for whether to store any warnings that are not ignored. Default is False which means warnings go to standard error. When set to True the warnings are recorded in a warning list which is passed to the function being decorated.
- Raises
TypeError – ignored_messages not list.
ValueError – Raise error if both ignored messages and warning_types are given and they are not the same length.
-