[docs]classImmutableModel(pydantic.BaseModel):"""Specifies configurations for validating classes which objects should be immutable."""
[docs]classConfig:"""Configuration options for classes which objects are meant to be immutable."""arbitrary_types_allowed=Trueallow_mutation=Falsevalidate_all=Truesmart_union=Trueextra=Extra.forbid
[docs]defserialize(self)->Any:"""Serialize the object. By defaults, this method raises a RuntimeError to notify the user that the method wasn't implemented. Raises: RuntimeError: Always. """raiseRuntimeError(f"{self.__class__.__name__}.serialize not implemented!")
[docs]@staticmethoddefdeserialize(self)->Any:"""Deserialize the object. By defaults, this method raises a RuntimeError to notify the user that the method wasn't implemented. Raises: RuntimeError: Always. """raiseRuntimeError(f"{self.__class__.__name__}.deserialize not implemented!")
[docs]classAlgorithm(abc.ABC):"""Base class of every node of the iris recognition pipeline."""
__parameters_type__=Parametersdef__init__(self,**kwargs:Any)->None:"""Init function."""self._callbacks:List[Callback]=[]if"callbacks"inkwargs.keys():self._callbacks=deepcopy(kwargs["callbacks"])delkwargs["callbacks"]self.params=self.__parameters_type__(**kwargs)def__call__(self,*args:Any,**kwargs:Any)->Any:"""Make an object a functor. Returns: Any: Object specified by an interface. """returnself.execute(*args,**kwargs)
[docs]defexecute(self,*args:Any,**kwargs:Any)->Any:"""Execute method and wrapped with hooks if such are specified. Returns: Any: Object specified by an interface. """forcallback_funcinself._callbacks:callback_func.on_execute_start(*args,**kwargs)result=self.run(*args,**kwargs)forcallback_funcinself._callbacks:callback_func.on_execute_end(result)returnresult
[docs]defrun(self,*args:Any,**kwargs:Any)->Any:"""Implement method design pattern. Not overwritten by subclass will raise an error. Raises: NotImplementedError: Raised if subclass doesn't implement `run` method. Returns: Any: Return value by concrate implementation of the `run` method. """raiseNotImplementedError(f"{self.__class__.__name__}.run method not implemented!")