jangada.mixin.Identifiable.get_instance#
- classmethod Identifiable.get_instance(id_: str) Identifiable | None#
Retrieve an Identifiable instance by its ID.
Looks up an object in the global instance registry using its unique identifier. Returns the object if it exists and has not been garbage collected, otherwise returns None.
- Parameters:
- id_str
The 32-character hexadecimal UUID string to look up.
- Returns:
- Identifiable or None
The instance with the given ID, or None if no such instance exists or has been garbage collected.
See also
idThe unique identifier property
Notes
This method searches the global registry maintained by the Identifiable class. The registry uses weak references, so objects can be garbage collected even if they’re in the registry.
If an object has been garbage collected, its ID will no longer be in the registry and this method will return None.
The lookup is O(1) as the registry is implemented as a dictionary.
Examples
Basic lookup:
>>> obj = Identifiable() >>> obj_id = obj.id >>> retrieved = Identifiable.get_instance(obj_id) >>> retrieved is obj True
Lookup of non-existent ID:
>>> Identifiable.get_instance('00000000000000000000000000000000') None
Object garbage collected:
>>> obj = Identifiable() >>> obj_id = obj.id >>> del obj # Object can be garbage collected >>> Identifiable.get_instance(obj_id) None