SharedStateCollectionView

class narupatools.state.view.collection_view.SharedStateCollectionView(view: MutableMapping[str, Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]], prefix: str, snapshot_type: Optional[Type[narupatools.state.serializable_object.SerializableObject]] = None)

View on a collection of items in a shared state with a given prefix.

Inheritance

Inheritance diagram of SharedStateCollectionView

Methods

__init__

Create a reference to a collection of items with a given prefix.

add

Insert a value into the shared state with an autogenerated key.

clear

Remove all keys in this dictionary.

get

items

keys

modify

Get the current value, and apply changes after it is modified.

set

Insert a value into the shared state dictionary with the given key.

snapshot

Return a snapshot of each of the current items in this collection.

typed_collection

Create a view of a set of keys with values of the specified type.

untyped_collection

Create a view of a set of keys that does not assume any specific type.

update

Update a value by adding the provided key-value pairs.

values

__init__(view: MutableMapping[str, Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]], prefix: str, snapshot_type: Optional[Type[narupatools.state.serializable_object.SerializableObject]] = None)

Create a reference to a collection of items with a given prefix.

Parameters
  • view – A view of the shared state dictionary that handles getting, updating and removing keys

  • prefix – The prefix that keys must have to be considered in this collection. For example, a prefix of ‘selection.’ matches all keys of the form ‘selection.*’

  • snapshot_type – The class that snapshots of its in this collection should implement

add(snapshot: Optional[TValue] = None, /, **kwargs: Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping])narupatools.state.view.reference.SharedStateReference[TValue]

Insert a value into the shared state with an autogenerated key.

clear()None

Remove all keys in this dictionary.

get(k[, d])D[k] if k in D, else d.  d defaults to None.
items()a set-like object providing a view on D’s items
keys()a set-like object providing a view on D’s keys
modify(key: str, /)Generator[TValue, None, None]

Get the current value, and apply changes after it is modified.

set(key: str, snapshot: Optional[TValue] = None, /, **kwargs: Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping])narupatools.state.view.reference.SharedStateReference[TValue]

Insert a value into the shared state dictionary with the given key.

This returns a reference to the item that was inserted into the shared state.

Parameters
  • key – Key to modify.

  • snapshot – Value to set.

  • kwargs – Arbitrary key-value pairs to set on the value.

Raises

ValueError – Can only use kwargs if this is a typed view.

snapshot()Dict[str, TValue]

Return a snapshot of each of the current items in this collection.

classmethod typed_collection(view: MutableMapping[str, Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]], prefix: str, snapshot_class: Type[TSpecificType])narupatools.state.view.collection_view.SharedStateCollectionView[TSpecificType]

Create a view of a set of keys with values of the specified type.

classmethod untyped_collection(view: MutableMapping[str, Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]], prefix: str)narupatools.state.view.collection_view.SharedStateCollectionView[Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping]]

Create a view of a set of keys that does not assume any specific type.

update(key: str, /, **kwargs: Union[None, str, int, float, bool, narupatools.state.typing.SerializableIterable, narupatools.state.typing.SerializableMapping])narupatools.state.view.reference.SharedStateReference[TValue]

Update a value by adding the provided key-value pairs.

This only works if the value supports keyword assignment.

Parameters
  • key – Key to modify.

  • kwargs – Values to add to the value.

values()an object providing a view on D’s values