betty.model.collections module

Entity collections.

class betty.model.collections.EntityCollection[source]

Bases: Generic[_TargetT], ABC

Provide a collection of entities.

__init__()[source]
abstractmethod add(*entities: _TargetT & Entity) None[source]

Add the given entities.

abstractmethod clear() None[source]

Clear all entities from the collection.

abstractmethod remove(*entities: _TargetT & Entity) None[source]

Remove the given entities.

replace(*entities: _TargetT & Entity) None[source]

Replace all entities with the given ones.

property view: Sequence[_TargetT & Entity]

A view of the entities at the time of calling.

class betty.model.collections.MultipleTypesEntityCollection[source]

Bases: Generic[_TargetT], EntityCollection[_TargetT]

Collect entities of multiple types.

__init__(*entities: _TargetT & Entity, entity_type_id_to_type_mapping: PluginIdToTypeMapping[Entity])[source]
add(*entities: _TargetT & Entity) None[source]

Add the given entities.

clear() None[source]

Clear all entities from the collection.

async classmethod new(*entities: _TargetT & Entity) Self[source]

Create a new instance.

remove(*entities: _TargetT & Entity) None[source]

Remove the given entities.

class betty.model.collections.SingleTypeEntityCollection[source]

Bases: Generic[_TargetT], EntityCollection[_TargetT]

Collect entities of a single type.

__init__(target_type: type[_TargetT], *entities: _TargetT & Entity)[source]
add(*entities: _TargetT & Entity) None[source]

Add the given entities.

clear() None[source]

Clear all entities from the collection.

remove(*entities: _TargetT & Entity) None[source]

Remove the given entities.

betty.model.collections.record_added(entities: EntityCollection[_EntityT]) AsyncIterator[MultipleTypesEntityCollection[_EntityT]][source]

Record all entities that are added to a collection.