LookupRegistry¶
- class parent_lookup.lookup.LookupRegistry(*args: Any, **kwargs: Any)¶
Bases:
object
Registry for management and lookup of parent-child relations at runtime.
- __init__() None ¶
Methods
__init__
()Look up the parent of a given child object.
register_parent
(parent)Register a parent object and its associated child lookup functions.
Attributes
- lookup_parent(child: object, parent: type[TParent]) TParent | None ¶
- lookup_parent(child: object, parent: TParent) TParent | None
Look up the parent of a given child object.
- Parameters:
child (object) – The child object for which to find the parent.
parent (type[TParent] | TParent) – The type or instance of the parent to look for.
- Returns:
TParent | None
- Return type:
The parent object if found, otherwise None.
- register_parent(parent: TParent) None ¶
Register a parent object and its associated child lookup functions.
This method performs the following steps: 1. Determines the type of the provided parent object. 2. Checks if the parent type is already registered. 3. If the parent type is not registered, it finds and registers any unbound child lookup functions. 4. Creates and registers bound child lookup functions for the parent object.
- Parameters:
parent (TParent) – The parent object to be registered.
- Return type:
None
- instance = <parent_lookup.lookup.LookupRegistry object>¶