Acquisition is a mechanism that allows objects to obtain attributes from the containment hierarchy they're in. This foundational Zope library, currently at version 6.2, facilitates dynamic attribute lookup based on an object's position within a hierarchy or explicitly set context. While it does not have a fixed release cadence, it is actively maintained by the Zope Foundation.
pip install AcquisitionVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic implicit acquisition. An object `b` acquires attributes from `a` when `a` is set as its context using `__of__`. Subsequent objects in the context chain can also acquire attributes from higher up the hierarchy.
Avoid using Acquisition with C methods in extension base classes that rely on specific internal data structures. Consider refactoring to use Python methods or explicitly unwrapping the object (`obj.aq_base`) before calling C methods, though this removes acquisition capabilities for that call.
Carefully review the official documentation on explicit vs. implicit acquisition and the roles of `__of__` (context) and object containment. Debug acquisition paths using `obj.aq_chain()` to visualize the hierarchy and `obj.aq_base` to get the unwrapped object.
Use acquisition judiciously for genuinely hierarchical patterns. For critical paths or where clarity is paramount, consider more explicit dependency injection or passing attributes directly rather than relying solely on the acquisition chain.
Inspect the object's acquisition chain using `obj.aq_chain()` to verify the available parents and their attributes. Ensure the attribute exists on one of the objects in the expected acquisition path. Use `obj.aq_acquire(attribute_name, default=None)` to safely test for acquirable attributes.
Install the library using pip: `pip install Acquisition`. If using a virtual environment, ensure it is activated before installation and execution.
Ensure that both the object on which `__of__` is called and the object passed as its argument are instances of classes that properly support Acquisition, typically by inheriting from `Acquisition.Implicit` or `Acquisition.Explicit`.
No dependency data recorded yet.