stouputils.decorators.abstract module#
- abstract(
- func: Callable[..., T],
- *,
- error_log: LogLevels = LogLevels.RAISE_EXCEPTION,
- 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 (Callable[..., T] | None) – The function to mark as abstract
error_log (LogLevels) –
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
Examples
>>> 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