Source code for efro.dataclassio.templatemultitype
# Released under the MIT License. See LICENSE for details.#"""Template for an IOMultitype setup.To use this template, simply copy the contents of this module somewhereand then replace 'TemplateMultiType' with 'YourType'."""from__future__importannotationsfromtypingimportTYPE_CHECKING,assert_never,overridefromenumimportEnumfromdataclassesimportdataclassfromefro.dataclassioimportioprepped,IOMultiTypeifTYPE_CHECKING:pass
[docs]classTemplateMultiTypeTypeID(Enum):"""Type ID for each of our subclasses."""TEST='test'
[docs]classTemplateMultiType(IOMultiType[TemplateMultiTypeTypeID]):"""Top level class for our multitype."""
[docs]@override@classmethoddefget_type_id(cls)->TemplateMultiTypeTypeID:# Require child classes to supply this themselves. If we did a# full type registry/lookup here it would require us to import# everything and would prevent lazy loading.raiseNotImplementedError()
[docs]@override@classmethoddefget_type(cls,type_id:TemplateMultiTypeTypeID)->type[TemplateMultiType]:"""Return the subclass for each of our type-ids."""# pylint: disable=cyclic-importt=TemplateMultiTypeTypeIDiftype_idist.TEST:returnTest# Important to make sure we provide all types.assert_never(type_id)
[docs]@ioprepped@dataclassclassTest(TemplateMultiType):"""Just a test."""