Zope Location is a small, focused library from the Zope Foundation providing an interface and a default implementation for objects that know their hierarchical position via `__parent__` and `__name__` attributes. It's a foundational component for traversal in many Zope-based applications. The current version is 6.0. It follows the Zope Foundation's release cadence, typically releasing new major versions to drop old Python support or introduce minor enhancements.
pip install zope.locationVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to create a simple hierarchy of objects using `zope.location.location.Location`. It highlights the necessity of explicitly setting the `__parent__` and `__name__` attributes, which are central to `zope.location`, and verifies that the `ILocation` interface is correctly provided by the objects.
Always ensure you explicitly set `obj.__parent__ = parent_obj` and `obj.__name__ = 'obj_name'` after creating a `Location` instance, or handle their initialization within your custom class's `__init__` method.
If you need a located object to also act as a container for other located objects (e.g., a folder), you must implement the container methods (like `__getitem__`, `__setitem__`, `__delitem__`) yourself, typically in a subclass or by combining `Location` with another base class.
Before upgrading to or installing `zope.location==6.0`, ensure your project's Python environment is running Python 3.9 or a newer compatible version.
Ensure that you explicitly set `obj.__parent__ = parent_obj` and `obj.__name__ = 'child_name'` after creating your located object, or within its `__init__` method.
If you require your located objects to also function as containers, you must implement the `__getitem__` (and potentially `__setitem__`, `__delitem__`) methods in your custom located class. `zope.location` itself focuses only on the location aspects.