Serialize
JSONSerializable
JSON serialization for Python classes.
Saves keyword arguments at construction,
and also any state returned by the save_state
method.
Does not attempt to serialize code or any other attributes.
to make class a serializable, subclass JSONSerializable,
and in the constructor use e.g. super().__init__(a=0, b=1 ...)
with any keyword args which should be serialized.
override save_state
and load_state
to handle any mutable state.
Constructor args and return values of save_state
can be other JSONSerializable objects, or any types which are already serializable by
the standard library json
module.
Source code in src/anguilla/serialize.py
load_state(state)
get_cls(s)
convert a type name to a type, importing dependencies as needed
e.g. "somepackage.submodule.SomeClass" -> SomeClass
this works by doing: import somepackage import somepackage.submodule.SomeClass eval("somepackage.submodule.SomeClass")
this should work in most cases, but could possibly break if the package containing the type has a weird structure.
In cases where dependencies rename / reorganize their types, breaking old anguilla files, any translation of type names can be done here.