betty.collection.keyed.adapter module

Adapters between keyed collections and Python data types.

class betty.collection.keyed.adapter.KeyedCollectionAdapter

Bases: KeyedCollection, Generic

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

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

Get an iterable over the collection’s keys.

class betty.collection.keyed.adapter.MutableKeyedCollectionAdapter

Bases: KeyedCollectionAdapter, MutableKeyedCollection, Generic

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

__init__(values: ~collections.abc.Iterable = (), *, key: ~collections.abc.Callable[[ValueT], KeyT], key_resolver: ~collections.abc.Callable[[ResolvableKeyT | KeyT], KeyT] = <function passthrough>, value_resolver: ~collections.abc.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.