cadrumo.core.frozen_mapping module¶
A read-only mapping that frozen models can share across consumers.
A frozen pydantic model refuses attribute assignment, but a Mapping field
still validates to a plain dict that any holder can mutate in place. That
single hole is what forces a model graph to be rebuilt per consumer.
FROZEN_MAPPING closes it at the defining field: annotate
Annotated[Mapping[K, V], FROZEN_MAPPING] and the validated value is a
FrozenMapping, while construction still accepts any mapping and
serialisation still emits the same JSON object the dict did.
- class FrozenMapping(items)[source]¶
-
An immutable mapping whose copy, shallow or deep, is itself.
Sharing by copy is correct only because nothing reachable through the mapping can change: it has no mutating methods, its storage is a read-only proxy, and
FROZEN_MAPPINGis applied only to fields whose values are themselves frozen. A deep copy of a model holding one therefore shares the mapping instead of failing on it, which a bareMappingProxyTypedoes.- Parameters:
items (Mapping[K, V])
- class FrozenMappingMarker[source]¶
Bases:
objectPydantic annotation that validates a mapping field into a
FrozenMapping.