typedefs¶
Package level constants, protocols and type definitions.
- parityos_serialization.utils.typedefs.DEFAULT_PASS_THROUGH_CLASSES: tuple[type, ...] = (<class 'bool'>, <class 'int'>, <class 'float'>, <class 'str'>, <class 'bytes'>, <class 'NoneType'>)¶
Default list of classes that are passed through serialization and deserialization unaltered in pre-configured serializers like
DeterministicJsonSerializerorFastJsonSerializer.
- parityos_serialization.utils.typedefs.DEFAULT_CLASS_TO_IMPORT_PATH: dict[type, str] = {<class 'NoneType'>: 'types.NoneType', <class 'mappingproxy'>: 'types.MappingProxyType'}¶
Mapping of classes to their import paths for which
f"{cls.__module__}.{cls.__qualname__}"does not give the correct import path. Used inImportPathClassTagger.
- parityos_serialization.utils.typedefs.BUILTIN_CLASSES: tuple[type, ...] = (<class 'object'>, <class 'type'>, <class 'types.GenericAlias'>, <class 'set'>, <class 'frozenset'>, <class 'list'>, <class 'tuple'>, <class 'dict'>, <class 'mappingproxy'>)¶
Classes for which (de)serialization is built-in and supported out of the box in preconfigured Serializers, such as
DeterministicJsonSerializerorFastJsonSerializer. That is, there are default (de)serialization hooks registered for them and they are pre-registered with any newNameClassTaggerinstance. The default hooks can be overwritten by registering new ones.
- parityos_serialization.utils.typedefs.ClassGetterHook¶
Type for callables for getting the type of an object.
This can also be something more elaborate than just
return type(obj).- Parameters:
obj (
T) – Object for which to get the class.- Returns:
Class of the object.
- Return type:
- parityos_serialization.utils.typedefs.ClassGetterPredicate¶
Type for callables for checking whether an object qualifies for a class getter hook.
A predicate function is always associated with a
ClassGetterHookthat gets called if the object qualifies according to this function.- Parameters:
obj (
T) – Object to check.- Returns:
Whether the object qualifies for the associated hook.
- Return type:
- parityos_serialization.utils.typedefs.TagGetterHook¶
Type for callables for getting a tag string for an object.
- Parameters:
cls (
type[T]) – Class for which to get a tag string.- Returns:
Tag string for the class.
- Return type:
- parityos_serialization.utils.typedefs.TagGetterPredicate¶
Type for callables for checking whether an object qualifies for a tag getter hook.
A predicate function is always associated with a
TagGetterHookthat gets called if the object qualifies according to this function.- Parameters:
cls (
type[T]) – Class to check.- Returns:
Whether the class qualifies for the associated hook.
- Return type:
- parityos_serialization.utils.typedefs.SerializePredicate¶
Type for callables for checking whether an object qualifies for a serialization hook.
A predicate function is always associated with a
SerializeHookthat gets called if the object qualifies according to this function.- Parameters:
obj (
T) – Object to check.- Returns:
Whether the object qualifies for the associated hook.
- Return type:
- parityos_serialization.utils.typedefs.DeserializePredicate¶
Type for callables for checking whether an object qualifies for a deserialization hook.
A predicate function is always associated with a
DeserializeHookthat gets called if the object qualifies according to this function.- Parameters:
data (
Any) – Serialized data.cls (
type) – Class to deserialize to.
- Returns:
Whether the object qualifies for the associated hook.
- Return type:
- class parityos_serialization.utils.typedefs.TypedDataDict¶
Bases:
TypedDictType for dict representations of serialized data with class information from a class tag.
Examples
>>> {"_cls": tuple, "_data": [1, 2, 3]} >>> {"_cls": MappingProxyType, "_data": {"first": 1, "second": 2}}
- parityos_serialization.utils.typedefs.TypedDataPair¶
Pair representation of serialized
datawith class information from aclass_tagas (data, class_tag).- Parameters:
_data (
Any) – serialized data_cls (
str) – class tag
- parityos_serialization.utils.typedefs.TypedDataTypes: TypeAlias = parityos_serialization.utils.typedefs.TypedDataDict | tuple[str, typing.Any]¶
Union of supported typed data types.