EntityCollection
Name-addressed view on one entity collection of a facade.
This is the read-and-remove counterpart of ensure_entity_name_available, for the collections a facade exposes through its add_ / get_ / remove_ / has_ method set.
The collection keeps a reference to the list it was given rather than a copy, so remove mutates the caller’s list. Constructing one per call site is intended: def get_runtime_context(self, name: str) → RuntimeContextFacade: context = EntityCollection(self._runtime.contexts, "Runtime context").get(name) return RuntimeContextFacade(context.name, context)
Member Functions:
get
get(name: str)
Return the entity called name.
| Name | Type | Description |
|---|---|---|
|
|
Entity name to look up. |
- Returns
-
EntityT— The first entity in the collection whose name equals name.
Raises:
-
KeyError— If no entity in the collection is called name.
find
find(name: str)
Return the entity called name, or None.
Use get when the absence of name is an error. The naming mirrors dict[key] versus dict.get(key).
| Name | Type | Description |
|---|---|---|
|
|
Entity name to look up. |
- Returns
-
EntityT | None— The first entity in the collection whose name equals name, or None if there is none.
has
has(name: str)
Return whether the collection contains an entity called name.
| Name | Type | Description |
|---|---|---|
|
|
Entity name to look up. |
- Returns
-
bool— True if any entity in the collection is called name.
remove
remove(name: str)
Remove the entity called name from the underlying list in place.
The entity is deleted by position rather than through list.remove, which would re-scan the list and delete the first element equal to the located one. Entities are Pydantic models with value equality, so the two differ as soon as a collection holds equal entities.
| Name | Type | Description |
|---|---|---|
|
|
Entity name to remove. |
Raises:
-
KeyError— If no entity in the collection is called name.