python_dto_mappers.base ======================= .. py:module:: python_dto_mappers.base .. autoapi-nested-parse:: Base mapper protocol and class. Attributes ---------- .. autoapisummary:: python_dto_mappers.base.TSource python_dto_mappers.base.TTarget Classes ------- .. autoapisummary:: python_dto_mappers.base.Mapper python_dto_mappers.base.BaseMapper Module Contents --------------- .. py:data:: TSource .. py:data:: TTarget .. py:class:: Mapper Bases: :py:obj:`Protocol`\ [\ :py:obj:`TSource`\ , :py:obj:`TTarget`\ ] Protocol for type-safe mapping between types. Use this protocol to define mappers with type safety. Example: >>> class UserMapper(Mapper[UserEntity, UserDTO]): ... def map(self, source: UserEntity) -> UserDTO: ... return UserDTO(id=source.id, name=source.name) .. py:method:: map(source: TSource) -> TTarget Map source object to target type. Args: source: Source object to map Returns: Mapped target object .. py:class:: BaseMapper(source_type: Type[TSource], target_type: Type[TTarget]) Bases: :py:obj:`Generic`\ [\ :py:obj:`TSource`\ , :py:obj:`TTarget`\ ] Base mapper with common functionality. Extend this class to create concrete mappers with type information. Example: >>> class UserMapper(BaseMapper[UserEntity, UserDTO]): ... def map(self, source: UserEntity) -> UserDTO: ... return UserDTO(id=source.id, name=source.name) .. py:attribute:: source_type .. py:attribute:: target_type .. py:method:: map(source: TSource) -> TTarget :abstractmethod: Map source to target. Override in subclasses to implement mapping logic. Args: source: Source object Returns: Mapped target object Raises: NotImplementedError: If not overridden in subclass