ds_common_serde_py_lib._serializable_deserialize ================================================ .. py:module:: ds_common_serde_py_lib._serializable_deserialize .. autoapi-nested-parse:: **File:** ``_serializable_deserialize.py`` **Region:** ``ds_common_serde_py_lib`` Description ----------- Defines internal helpers used by ``Serializable.deserialize()`` for inspecting dataclass fields and type hints, resolving type variables, converting field values, and setting ``init=False`` fields after construction. .. rubric:: Example .. code-block:: python from dataclasses import dataclass, field from ds_common_serde_py_lib import Serializable @dataclass class WithInitFalse(Serializable): name: str computed: str = field(init=False, default="computed") obj = WithInitFalse.deserialize({"name": "x"}) assert obj.computed == "computed" Attributes ---------- .. autoapisummary:: ds_common_serde_py_lib._serializable_deserialize.logger ds_common_serde_py_lib._serializable_deserialize.TypeVarType ds_common_serde_py_lib._serializable_deserialize.T Functions --------- .. autoapisummary:: ds_common_serde_py_lib._serializable_deserialize._build_type_var_map ds_common_serde_py_lib._serializable_deserialize._get_class_type_hints ds_common_serde_py_lib._serializable_deserialize._get_dataclass_fields ds_common_serde_py_lib._serializable_deserialize._resolve_type_hint_for_field ds_common_serde_py_lib._serializable_deserialize._process_field ds_common_serde_py_lib._serializable_deserialize._set_init_false_fields Module Contents --------------- .. py:data:: logger .. py:data:: TypeVarType .. py:data:: T .. py:function:: _build_type_var_map(cls: type) -> dict[Any, Any] Build a mapping from TypeVars to their concrete types. :param cls: The class to build the type var map for. :returns: A mapping from TypeVars to their concrete types. .. py:function:: _get_class_type_hints(cls: type) -> dict[str, Any] Get type hints from the class itself (best-effort). :param cls: The class to get the type hints for. :returns: A dictionary of type hints. .. py:function:: _get_dataclass_fields(cls: type) -> tuple[Any, Ellipsis] Get dataclass fields for the given class. :param cls: The class to get the dataclass fields for. :returns: A tuple of dataclass fields. .. py:function:: _resolve_type_hint_for_field(field: Any, field_name: str, cls_own_hints: dict[str, Any], type_var_map: dict[Any, Any], cls: type) -> Any Resolve the type hint for a dataclass field. :param field: The field to resolve the type hint for. :param field_name: The name of the field. :param cls_own_hints: The type hints for the class. :param type_var_map: A mapping from TypeVars to their concrete types. :param cls: The class to resolve the type hint for. :returns: The resolved type hint. .. py:function:: _process_field(field: Any, raw_value: Any, deserializers: dict[str, Any], cls_own_hints: dict[str, Any], type_var_map: dict[Any, Any], cls: type) -> Any Process a single field during deserialization. :param field: The field to process. :param raw_value: The raw value of the field. :param deserializers: A dictionary of deserializers. :param cls_own_hints: The type hints for the class. :param type_var_map: A mapping from TypeVars to their concrete types. :param cls: The class to process the field for. :returns: The processed value. .. py:function:: _set_init_false_fields(instance: Any, class_fields: tuple[Any, Ellipsis]) -> None Set fields with init=False and defaults after instance creation. :param instance: The instance to set the fields for. :param class_fields: A tuple of dataclass fields.