class documentation

class CountWarnings(object):

View In Hierarchy

Count warnings to improve warning control.

Calling this instance, see __call__, counts how often the passed object instance was called with the given warning name and returns True iff skip_warns < count <= max_warns.

The max_warns and skip_warns parameters can be modified by the user for each "warning name" by changing the module variables max_warnings:dict and skip_warnings:dict, respectively, for example like cma.warnings_and_exceptions.max_warnings['warning name'] = 3.

Usage for developers:

from cma import warnings_and_exceptions as _we

if _we.deliver_warning(self, 'new warning name', max_warns=3):
    warnings.warn('my message. ' +
                  _we.deliver_warning.message())

warnings.warn is called in place to not obscure the code line to which the warning refers to.

The internal representation is by a dictionary like .counters[(object_instance, warning_name)] == [warnings_done, max_warns, skip_warns].

Method __call__ increment warning count and return 0 < count - skip_warns <= max_warns
Method __init__ Undocumented
Method message append count to message and the warning name to allow to change max_warns
Instance Variable counters Undocumented
Instance Variable _last_key Undocumented
def __call__(self, object_instance, warning_name, max_warns=1, skip_warns=0):

increment warning count and return 0 < count - skip_warns <= max_warns

which is by default True for the first warning and False otherwise. skip_warns indicates how many initial warnings shall be ignored and max_warns indicates how many warnings should be exposed to the user.

The warning is identified by (object_instance, warning_name), such that the warnings count starts with each instance anew.

object_instance and warning_name must be hashable objects which in combination give a unique ID for the warnings count.

Details: having two id input arguments is somewhat arbitrary and deliver_warning(0, (self, name)) behaves identical to deliver_warning(self, name). However, the user control of max_warn` via `cma.warnings_and_exceptions.max_warnings should and does not depend on the specific instance, i.e. the first of the two id inputs.

def __init__(self):

Undocumented

def message(self, message='', object_instance=None, warning_name=None):

append count to message and the warning name to allow to change max_warns

counters: dict =

Undocumented

_last_key =

Undocumented