lazr.delegates provides a simple, declarative way to create Python objects that delegate behavior to other objects. It simplifies the implementation of common design patterns like composition, allowing classes to expose methods from 'delegatee' objects without boilerplate code. The current version is 2.1.1, and the library maintains a stable, albeit infrequent, release cadence, primarily focusing on Python compatibility and bug fixes.
pip install lazr-delegatesVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use the `@delegates` decorator to easily expose methods from another class. `MyPet` delegates `make_sound` and `get_animal_type` to an instance of `SoundMaker` implicitly.
Ensure your project's Python environment is 3.8 or higher. If you need older Python support, use `lazr-delegates<2.0.0` (e.g., 1.0.3 for Python 3.7, 1.0.2 for Python 2.7).
Set `_DelegateType.delegated_attributes = True` on a custom delegate type, or pass `delegated_attributes=True` when defining the delegate type for `delegates`.
Carefully design your class hierarchy. For complex cases, explicitly define the MRO if possible, or consider using custom `DelegateType` classes to control how methods are looked up and invoked. Test thoroughly with `inspect.getmro()`.
No dependency data recorded yet.