readonlydict package#
- class readonlydict.HashableMapping[source]#
Bases:
Hashable,Mapping[K,V]Abstract base class for mapping objects that are also hashable.
- abstractmethod __getitem__(key)#
- abstractmethod __hash__()#
Return hash(self).
- abstractmethod __iter__()#
- abstractmethod __len__()#
- __reversed__ = None#
- 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#
- values() an object providing a view on D's values#
- readonlydict.Item#
Type alias of a key-value pair for mapping.
alias of
tuple[K,V]
- readonlydict.Items#
Type alias of key-value pairs for mapping.
alias of
Iterable[tuple[K,V]]
- class readonlydict.ReadonlyDict(*args: Any, **kwargs: Any)[source]#
Bases:
HashableMapping[K,V]Drop-in read-only dictionary with 100% typing and runtime compatibility.
ReadonlyDict()-> New empty read-only dictionary.ReadonlyDict(mapping)-> New read-only dictionary initialized from a mapping object’s(key, value)pairs.ReadonlyDict(iterable)-> New read-only dictionary initialized as if via:d = {}; for k, v in iterable: d[k] = v.ReadonlyDict(**kwargs)-> New read-only dictionary initialized with thename=valuepairs in the keyword argument list. For example:ReadonlyDict(one=1, two=2).
Note
While this dictionary is immutable, calling
hash()on it requires that all of its values are also hashable. If the dictionary contains unhashable values (e.g., lists or standard dicts), aTypeErrorwill be raised when the hash is computed.- __init__(*args: Any, **kwargs: Any) None[source]#
Initialize
self. Seehelp(type(self))for accurate signature.
- __or__(value: Mapping[K2, V2], /) ReadonlyDict[K | K2, V | V2][source]#
Return
self|value.
- classmethod fromkeys(iterable: Iterable[K2], /) ReadonlyDict[K2, None][source]#
- classmethod fromkeys(iterable: Iterable[K2], value: V2, /) ReadonlyDict[K2, V2]
Create a new read-only dictionary with keys from
iterableand values set tovalue.
- 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#
- values() an object providing a view on D's values#