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
Argument | Type | Required | |
---|---|---|---|
data | Mapping[K, T] | Mutable data internal storage of BackDict . | |
back_data | Mapping[K2, T] | Backup immutable data internal storage of BackDict . | |
key_mapper | (K) -> K2 | Use this mapper to convert K to K2 when the key is not found in data . | |
key_back_mapper | (K2) -> K | Use 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
Argument | Type | |
---|---|---|
vlen | int | The 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
Argument | Type | Required | |
---|---|---|---|
key | K | The keyword to be checked. |
Returns
Argument | Type | |
---|---|---|
flag | bool | If 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
Argument | Type | |
---|---|---|
keys | Iterator[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
Argument | Type | Required | |
---|---|---|---|
key | K | The keyword used for locating the value. If the value is in the back level. Will use key_mapper(key) to locate the value. |
Returns
Argument | Type | |
---|---|---|
val | V | The value located by key . |