Make an immutable dictionary from the specified dictionary. If *no_copy* is `True`, then *dictionary* will be wrapped instead of copied. Only set this if you are sure there will be no external references to the dictionary.
(
self,
dictionary: Any,
no_copy: bool = False,
map_factory: Callable[[], collections.abc.MutableMapping] = dict,
)
| 9 | @immutable |
| 10 | class Dict(collections.abc.Mapping): # lgtm[py/missing-equals] |
| 11 | def __init__( |
| 12 | self, |
| 13 | dictionary: Any, |
| 14 | no_copy: bool = False, |
| 15 | map_factory: Callable[[], collections.abc.MutableMapping] = dict, |
| 16 | ): |
| 17 | """Make an immutable dictionary from the specified dictionary. |
| 18 | |
| 19 | If *no_copy* is `True`, then *dictionary* will be wrapped instead |
| 20 | of copied. Only set this if you are sure there will be no external |
| 21 | references to the dictionary. |
| 22 | """ |
| 23 | if no_copy and isinstance(dictionary, collections.abc.MutableMapping): |
| 24 | self._odict = dictionary |
| 25 | else: |
| 26 | self._odict = map_factory() |
| 27 | self._odict.update(dictionary) |
| 28 | self._hash = None |
| 29 | |
| 30 | def __getitem__(self, key): |
| 31 | return self._odict.__getitem__(key) |