betty.collections.keyed.adapter module

Adapters between keyed collections and Python data types.

class betty.collections.keyed.adapter.KeyedCollectionAdapter

Bases: KeyedCollection, Generic

A collection of values that are accessible by their primary keys.

__init__(values: Mapping[KeyT, ValueT] | Iterable[tuple[KeyT, ValueT]] | None = None, *, key_resolver: Callable[[ResolvableKeyT | KeyT], KeyT] = <function passthrough>)
keys() Iterable[KeyT]

Get an iterable over the collection’s keys.

class betty.collections.keyed.adapter.MutableKeyedCollectionAdapter

Bases: KeyedCollectionAdapter, MutableKeyedCollection, Generic

A mutable ordered collection of values that are accessible by their primary keys.

__init__(values: Iterable[ResolvableValueT] = (), *, key: Callable[[ValueT], KeyT], key_resolver: Callable[[ResolvableKeyT | KeyT], KeyT] = <function passthrough>, value_resolver: Callable[[ResolvableValueT | ValueT], ValueT] = <function passthrough>)
add(*values: ValueT | ResolvableValueT) None

Add one or more values to the collection.

clear() None

Remove all values from the collection.

remove(*keys: KeyT | ResolvableKeyT) None

Remove one or more keys from the collection.