tqec.plaquette.frozendefaultdict.FrozenDefaultDict#
- class FrozenDefaultDict(arg: Mapping[K, V] | Iterable[tuple[K, V]] | None = None, *, default_factory: Callable[[], V] | None = None)[source]#
A defaultdict implementation that cannot be mutated.
This class re-defines all the mutating methods of defaultdict (i.e., all the mutating methods of dict and __missing__) in order to make any instance immutable.
Note on re-defining __missing__:
The standard defaultdict implementation is entirely based on the __missing__ method (described here https://docs.python.org/3/library/collections.html#collections.defaultdict.__missing__) that is called when a user-provided key was not found in the defined keys. This __missing__ method try to use self.default_factory to create a new value and inserts that new value in the dictionary. That last part is problematic for
Plaquettes
and in particular to compare collections ofPlaquettes
through __hash__ and __eq__.- __init__(arg: Mapping[K, V] | Iterable[tuple[K, V]] | None = None, *, default_factory: Callable[[], V] | None = None) None [source]#
Methods
__init__
([arg, default_factory])get
(k[,d])has_default_factory
()items
()keys
()map_keys
(callable)values
()Attributes
default_factory