LookupRegistry

class parent_lookup.lookup.LookupRegistry

Bases: object

Registry for management and lookup of parent-child relations at runtime.

Return type:

LookupRegistry

__init__() → None

Initialize the lookup indexes for the singleton registry.

Return type:

None

Methods

__init__()

Initialize the lookup indexes for the singleton registry.

lookup_parent(...)

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 whose parent is being resolved.

  • parent (type[TParent] | TParent) – The parent class or instance to match.

Returns:

The matching parent object, or None if no parent is found.

Return type:

TParent | 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 whose child lookup functions are registered.

Return type:

None

instance = <parent_lookup.lookup.LookupRegistry object>