Skip to main content

BackDictView

ClassPrivateSource

bdict_view = BackDictView[K, V](
data: Mapping[K, V],
back_data: Mapping[K2, V],
key_mapper: Callable[[K], K2],
key_back_mapper: Callable[[K2], K],
)

Internal class. The read-only proxy used by MappingView of BackDict.

danger

This class should be initialized by methods of BackDict. Users should not explicitly initialize it.

Arguments

ArgumentTypeRequired
Description
dataMapping[K, T]Mutable data internal storage of BackDict.
back_dataMapping[K2, T]Backup immutable data internal storage of BackDict.
key_mapper(K) -> K2Use this mapper to convert K to K2 when the key is not found in data.
key_back_mapper(K2) -> KUse this mapper to convert K2 to K when the key needs to be listed to users.

Operators

__len__

vlen: int = len(bdict_view)

Get the length of the dictionary. This length is also the number of items in this view.

Returns

ArgumentType
Description
vlenintThe number of the keys in the union of the first level dictionary keys and the back-level dictionary keys.

__contains__

flag: bool = key in bdict_view

Check whether key is in the dictionary view.

Requires

ArgumentTypeRequired
Description
keyKThe keyword to be checked.

Returns

ArgumentType
Description
flagboolIf True, the given key value exists in the dictionary view. If the key is not found in the first level but found in the back level, this value is also True.

__iter__

keys: Iterator[K] = iter(bdict_view)

Iterate each key in the dictionary view.

Returns

ArgumentType
Description
keysIterator[K]An iterator. For each iteration, it will return a key in the dicionary view. For any key in the back-level, the iterator will return the key post-processed by key_back_mapper.

__getitem__

val: V = bdict_view[key]

Locate one value in the dictionary view. Raise KeyError if the keyword is not found.

Requires

ArgumentTypeRequired
Description
keyKThe keyword used for locating the value. If the value is in the back level. Will use key_mapper(key) to locate the value.

Returns

ArgumentType
Description
valVThe value located by key.