Skip to content

Commit

Permalink
Switch to private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhaq-e committed Sep 2, 2023
1 parent 19c1dfc commit 7bc2a6e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
9 changes: 7 additions & 2 deletions litestar/contrib/sqlalchemy/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)

from litestar.dto.base_dto import AbstractDTO
from litestar.dto.config import SQLAlchemyDTOConfig
from litestar.dto.config import DTOConfig, SQLAlchemyDTOConfig
from litestar.dto.data_structures import DTOFieldDefinition
from litestar.dto.field import DTO_FIELD_META_KEY, DTOField, Mark
from litestar.exceptions import ImproperlyConfiguredException
Expand All @@ -48,12 +48,17 @@ class SQLAlchemyDTO(AbstractDTO[T], Generic[T]):
config: ClassVar[SQLAlchemyDTOConfig]

@staticmethod
def adapt_dto_config(config: Any) -> SQLAlchemyDTOConfig:
def _ensure_sqla_dto_config(config: DTOConfig | SQLAlchemyDTOConfig) -> SQLAlchemyDTOConfig:
if not isinstance(config, SQLAlchemyDTOConfig):
return SQLAlchemyDTOConfig(**asdict(config))

return config

def __init_subclass__(cls, **kwargs: Any) -> None:
super().__init_subclass__(**kwargs)
if hasattr(cls, "config"):
cls.config = cls._ensure_sqla_dto_config(cls.config)

@singledispatchmethod
@classmethod
def handle_orm_descriptor(
Expand Down
9 changes: 0 additions & 9 deletions litestar/dto/base_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ class AbstractDTO(Generic[T]):

_dto_backends: ClassVar[dict[str, _BackendDict]] = {}

def __init_subclass__(cls, **kwargs: Any) -> None:
super().__init_subclass__(**kwargs)
if hasattr(cls, "config"):
cls.config = cls.adapt_dto_config(cls.config)

def __init__(self, asgi_connection: ASGIConnection) -> None:
"""Create an AbstractDTOFactory type.
Expand Down Expand Up @@ -88,10 +83,6 @@ def __class_getitem__(cls, annotation: Any) -> type[Self]:

return type(f"{cls.__name__}[{annotation}]", (cls,), cls_dict)

@staticmethod
def adapt_dto_config(config: DTOConfig) -> Any:
return config

def decode_builtins(self, value: dict[str, Any]) -> Any:
"""Decode a dictionary of Python values into an the DTO's datatype."""

Expand Down
26 changes: 1 addition & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7bc2a6e

Please sign in to comment.