hooks.warnings module

Provides warning hooking functionality.

class hooks.warnings._WarningHooks[source]

Bases: hooks.base._HookBase

Class used to log warnings.

print_warning(message, category, filename, lineno, file=None, line=None)[source]

Called when a warning is encountered.

This method hooks warnings.showwarning to log all warnings and call registered callbacks with the provided arguments.

@hooks.warnings.WarningHook[source]

Bases: hooks.base._HookDecorator

Fired when a warning is encountered.

The decorated function is passed the following parameters when a warning is fired:

Parameters:
  • message (Warning) – The Warning instance.
  • category (Warning) – The type of Warning that was encountered.
  • filename (str) – The name of the file where the warning was encountered.
  • lineno (int) – The line number of the file where the warning was encountered.
from hooks.warnings import WarningHook

@WarningHook
def warning_callback(message, category, filename, lineno):
    # Code...
hooks.warnings.warning_hooks

The singleton object of the _WarningHooks class.