findmy.util.abc#
Various utility ABCs for internal and external classes.
Attributes#
Classes#
ABC for async classes that need to be cleaned up before exiting. |
|
ABC for serializable classes. |
Module Contents#
- findmy.util.abc.logger#
- class findmy.util.abc.Closable(loop: asyncio.AbstractEventLoop | None = None)#
Bases:
abc.ABC
ABC for async classes that need to be cleaned up before exiting.
- abstractmethod close() None #
- Async:
Clean up.
- __del__() None #
Attempt to automatically clean up when garbage collected.
- class findmy.util.abc.Serializable#
Bases:
Generic
[_T
],abc.ABC
ABC for serializable classes.
- abstractmethod to_json(dst: str | pathlib.Path | None = None, /) _T #
Export the current state of the object as a JSON-serializable dictionary.
If an argument is provided, the output will also be written to that file.
The output of this method is guaranteed to be JSON-serializable, and passing the return value of this function as an argument to
Serializable.from_json()
will always result in an exact copy of the internal state as it was when exported.You are encouraged to save and load object states to and from disk whenever possible, to prevent unnecessary API calls or otherwise unexpected behavior.
- classmethod from_json(val: str | pathlib.Path | _T, /) Self #
- Abstractmethod:
Restore state from a previous
Closable.to_json()
export.If given a str or Path, it must point to a json file from
Serializable.to_json()
. Otherwise, it should be the Mapping itself.See
Serializable.to_json()
for more information.