Decorators

The decorators module, located at pyutils.decorators, offers a collection of powerful and reusable decorators that simplify common tasks such as caching, memoization, and input validation. These decorators can be easily applied to functions and methods to enhance their functionality without modifying their core logic.

Implementation

The decorators are implemented as functions that take another function as an argument and return a new function that adds the desired behavior. The primary decorators provided in this module include:

must_implement(func)

A decorator to enforce that a method must be implemented in a subclass. Unlike abstract methods, it allows the base class to be instantiated, but raises an error if the decorated method is called without being implemented in a subclass.

This is useful for creating base classes that can be instantiated but require certain methods to be implemented in derived classes.

Raises:

MustImplementError – Raised when the decorated method is called without being implemented in a subclass.