FrozenDefaultDict#

class tqec.plaquette.FrozenDefaultDict(arg=None, *, default_factory=None)[source]#

Bases: Generic[K, V], Mapping[K, V]

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 of Plaquettes through __hash__ and __eq__.

Methods

__init__([arg, default_factory])

get(k[,d])

has_default_factory()

items()

keys()

map_keys(callable)

map_values(callable)

values()

Attributes

default_factory

Detailed methods

Parameters:
  • arg (Mapping[K, V] | Iterable[tuple[K, V]] | None)

  • default_factory (Callable[[], V] | None)

__init__(arg=None, *, default_factory=None)[source]#
Parameters:
  • arg (Mapping[K, V] | Iterable[tuple[K, V]] | None)

  • default_factory (Callable[[], V] | None)

Return type:

None

get(k[, d]) D[k] if k in D, else d.  d defaults to None.#
has_default_factory()[source]#
Return type:

bool

items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
map_keys(callable)[source]#
Parameters:

callable (Callable[[K], K])

Return type:

FrozenDefaultDict[K, V]

map_values(callable)[source]#
Parameters:

callable (Callable[[V], Vp])

Return type:

FrozenDefaultDict[K, Vp]

values() an object providing a view on D's values#