lisa.utils.SerializeViaConstructor#

class lisa.utils.SerializeViaConstructor(*args, **kwargs)[source]#

Bases: object

Base class providing serialization to objects that typically cannot due to unpicklable attributes.

This works by recording the constructor that was used and the parameters passed to it in order to recreate an equivalent object, under the assmuption that the constructor arguments will be picklable.

Alternative constructors (e.g. classmethod) can be decorated with SerializeViaConstructor.constructor() in order to record the parameters passed to them if necessary.

Methods

constructor()

Decorator to apply on alternative constructors if arguments passed to the class are not serializable, or if the alternative constructor makes necessary initialization.

Methods#

classmethod SerializeViaConstructor.constructor(f)[source]#

Decorator to apply on alternative constructors if arguments passed to the class are not serializable, or if the alternative constructor makes necessary initialization.

Example:

class Foo(SerializeViaConstructor):
    def __init__(self, x):
        self.x = x

    @classmethod
    @SerializeViaConstructor.constructor
    def from_path(cls, path):
        return cls(x=open(path))

Note

This only works on classmethods. staticmethods are not supported.