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 DeterministicJsonSerializer or FastJsonSerializer.

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 in ImportPathClassTagger.

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 DeterministicJsonSerializer or FastJsonSerializer. That is, there are default (de)serialization hooks registered for them and they are pre-registered with any new NameClassTagger instance. 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:

type

alias of Callable[[T], 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 ClassGetterHook that 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:

bool

alias of Callable[[T], bool]

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:

str

alias of Callable[[type[T]], str]

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 TagGetterHook that 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:

bool

alias of Callable[[type[T]], bool]

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 SerializeHook that 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:

bool

alias of Callable[[T], bool]

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 DeserializeHook that 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:

bool

alias of Callable[[T, type], bool]

class parityos_serialization.utils.typedefs.TypedDataDict

Bases: TypedDict

Type 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 data with class information from a class_tag as (data, class_tag).

Parameters:
  • _data (Any) – serialized data

  • _cls (str) – class tag

alias of tuple[str, Any]

parityos_serialization.utils.typedefs.TypedDataTypes: TypeAlias = parityos_serialization.utils.typedefs.TypedDataDict | tuple[str, typing.Any]

Union of supported typed data types.

class parityos_serialization.utils.typedefs.GenericAliasDict

Bases: TypedDict

exception parityos_serialization.utils.typedefs.ClassError

Bases: TypeError

Error related to types and classes during (de)serialization.

exception parityos_serialization.utils.typedefs.DataError

Bases: TypeError

Error related to data content and format during (de)serialization.