medkit.core.dict_conv
=====================

.. py:module:: medkit.core.dict_conv


Classes
-------

.. autoapisummary::

   medkit.core.dict_conv.DictConvertible
   medkit.core.dict_conv.SubclassMapping


Functions
---------

.. autoapisummary::

   medkit.core.dict_conv.get_class_name
   medkit.core.dict_conv.add_class_name_to_data_dict
   medkit.core.dict_conv.get_class_name_from_data_dict


Module Contents
---------------

.. py:function:: get_class_name(class_: type) -> str

.. py:function:: add_class_name_to_data_dict(instance: object, data_dict: dict[str, Any])

   
   Add a class name to a data dict returned by a `to_dict()` method.


   :Parameters:

       **instance: object**
           The instance of class to which `data_dict` corresponds

       **data_dict: dict of str to Any**
           The data dict on which to add the class name














   ..
       !! processed by numpydoc !!

.. py:function:: get_class_name_from_data_dict(data_dict: dict[str, Any])

   
   Get the class name written in the data_dict by the `to_dict` method.


   :Parameters:

       **data_dict**
           The data dict returned by `to_dict` of the class to extract



   :Returns:

       class_name
           The name of the class which has generated the data_dict











   ..
       !! processed by numpydoc !!

.. py:class:: DictConvertible

   Bases: :py:obj:`typing_extensions.Protocol`


   
   Base protocol to support conversion to and from a data dictionary.
















   ..
       !! processed by numpydoc !!

   .. py:method:: to_dict() -> dict[str, Any]

      
      Convert current instance to a data dictionary.





      :Returns:

          dict of str to Any:
              A data dict containing all the information needed to re-instantiate the object











      ..
          !! processed by numpydoc !!


   .. py:method:: from_dict(data_dict: dict[str, Any]) -> typing_extensions.Self
      :classmethod:


      
      Instantiate an object from a data dictionary.


      :Parameters:

          **data_dict: dict of str to Any**
              Data dict returned by `to_dict()`



      :Returns:

          Self:
              An instance of the class `to_dict()` was called on.











      ..
          !! processed by numpydoc !!


.. py:class:: SubclassMapping

   
   Base class for managing subclasses.
















   ..
       !! processed by numpydoc !!

   .. py:attribute:: _subclasses
      :type:  dict[str, type[typing_extensions.Self]]


   .. py:method:: __init_subclass__()
      :classmethod:



   .. py:method:: register_subclass(subclass: type[typing_extensions.Self])
      :classmethod:



   .. py:method:: get_subclass(name: str) -> type[typing_extensions.Self] | None
      :classmethod:



   .. py:method:: get_subclass_for_data_dict(data_dict: dict[str, Any]) -> type[typing_extensions.Self] | None
      :classmethod:


      
      Return the subclass corresponding to the class name found in a data dictionary.


      :Parameters:

          **data_dict: dict of str to Any**
              Data dict returned by the `to_dict()` method of a subclass
              (or of the base class itself).



      :Returns:

          subclass
              Subclass that generated `data_dict`, or None if `data_dict`
              correspond to the base class itself.











      ..
          !! processed by numpydoc !!


