PrintConstructionCallMixin

class dtaianomaly.utils.PrintConstructionCallMixin[source]

Mixin object to print the construction call of an object.

Mixin object to add functionality for automatically print the contruction call of an object, using the currently set paramters. By default, this mixin object will try to include a hyperparaemter as <name>=<value> in the construction-call, but if there are *arg values, then this is not possible and the first parameters are included as parameter. Note that this only works if the names of the parameters are identical to the names of the attributes.

Examples

>>> from dtaianomaly.utils import PrintConstructionCallMixin
>>>
>>> class MyObject(PrintConstructionCallMixin):
...
...     def __init__(self, obligated: int, optional: float = 3.14, *args, **kwargs):
...         self.obligated = obligated
...         self.optional = optional
...         self.args = args
...         self.kwargs = kwargs
>>>
>>> print(MyObject(42))
MyObject(obligated=42)
>>> print(MyObject(42, 1.41))
MyObject(obligated=42,optional=1.41)
>>> print(MyObject(42, 1.41, 1, 2, 3))
MyObject(42,1.41,1,2,3)
>>> print(MyObject(42, other_param="other-value"))
MyObject(obligated=42,other_param='other-value')
>>> print(MyObject(42, 1.41, 1, 2, 3, other_param="other-value"))
MyObject(42,1.41,1,2,3,other_param='other-value')