Package: indexed-class
INDEXED CLASSMaintainer: aachn3n45t31@protonmail.comSite:https://gitlab.com/pyutil/indexed_classVersion: 1.1.0AboutThis package provides some metaclasses/class hierarchy roots capable of storing and
retrieving subclasses using arbitrary keys and registry types.Table of ContentsstructureusageexamplessupportrequirementsinstallationtestsunitintegrationProject Structure-NoRootClassError(TypeError)
-NoMatchingSubclassError(KeyError)
-SubclassValidationError(ValueError)
-defaultregistry(dict)
-IndexedClassMeta(type)
 -keys
 -operator[]
-IndexedClass(meta=IndexedClassMeta)
-DefaultIndexedClass(IndexedClass)
-AbstractIndexedClassMeta(IndexedClassMeta, ABCMeta)
-AbstractIndexedClass(meta=AbstractIndexedClassMeta)
-DefaultAbstractIndexedClass(AbstractIndexedClass)Usage(Abstract)IndexedClassMeta exposes following parameters:key (optional, any type): the key under which the class is to be stored in the registry;
if the__registry__attribute is not defined anywhere in parent  hierarchy, a NoRootClassError
is raisedroot (optional, boolean): if set to True, the class defines a__registry__attribute as a new
instance of the ``@registry_classparameterregistry_class (optional, type exposing__getitem__,__delitem__and__setitem__): class
used to initialise empty__registry__in root classes, defaults tosuper().__registry_class__,
sets__registry_class__Methods exposed by classes derived from (Abstract)IndexedClassMeta:keys (property): returns a set of all keys defined in__registry__; if this attribute is not
defined anywhere in parent hierarchy, a NoRootClassError is raised; by default uses.__registry__.keys()- override if yourregistry_classdoes not implementkeys()method__getitem__(key): returns a class stored in__registry__under@key; if the__registry__attribute is not defined anywhere in parent hierarchy, a NoRootClassError is raised; if@keyis
not found in__registry__, a NoMatchingSubclassError is raised__setitem__(key, value): stores@valueunder@keyin__registry__; if the__registry__attribute is not defined anywhere in parent hierarchy, a NoRootClassError is raised; if@valueis not a valid subclass of calling class, a SubclassValidationError is raised__delitem__(key): deletes@keyfrom__registry__; if the__registry__attribute is not
defined anywhere in parent hierarchy, a NoRootClassError is raised; if@keyis not found in__registry__, a NoMatchingSubclassError is raisedCode samplesBasic usecasefromindexed_classimportAbstractIndexedClass,NoMatchingSubclassErrorfromabcimportabstractmethodimportjsonimportpickleclassFileParser(AbstractIndexedClass,root=True):def__init__(self,filename:str):self.filename=filename@abstractmethoddeffetch_content(self)->dict:raiseNotImplementedError("abstract method requires override")classJsonFileParser(FileParser,key="json"):deffetch_content(self)->dict:withopen(self.filename,"r")ascontent:returnjson.load(content)classPickleFileParser(FileParser,key="pickle"):deffetch_content(self)->dict:withopen(self.filename,"rb")ascontent:returnpickle.load(content)### MAIN #### example settings:#   filename: /some/path/data.json#   filetype: jsonwithopen("settings.json","r")asfile:settings=json.load(file)try:data=FileParser[settings["filetype"]](settings["filename"]).fetch_content()exceptNoMatchingSubclassError:data=None...SupportPrerequisitespython >= 3.8.0Installationpip3 installTesting package functionalityUnit testsFormat: pytestIntegration testsFormat: None