stouputils.decorators.abstraction module#
- abstract( ) Callable[..., T][source]#
- abstract(
- func: None = None,
- *,
- error_log: LogLevels = LogLevels.RAISE_EXCEPTION,
Decorator that marks a function as abstract.
Contrary to the
abc.abstractmethod()decorator that raises aTypeErrorwhen you try to instantiate a class that has abstract methods, this decorator raises aNotImplementedErrorONLY when the decorated function is called, indicating that the function must be implemented by a subclass.- Parameters:
func – The function to mark as abstract
error_log –
Log level for the error handling:
LogLevels.NONE- NoneLogLevels.WARNING- Show as warningLogLevels.WARNING_TRACEBACK- Show as warning with tracebackLogLevels.ERROR_TRACEBACK- Show as error with tracebackLogLevels.RAISE_EXCEPTION- Raise exception
>>> class Base: ... @abstract ... def method(self): ... pass >>> Base().method() Traceback (most recent call last): ... NotImplementedError: Function 'method()' is abstract and must be implemented by a subclass