Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DTO): Add DTO codegen backend #2388

Merged
merged 34 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3fe6a7b
feat(dto): optimise _transfer_instance_data
provinzkraut Aug 6, 2023
058f660
wip
provinzkraut Aug 7, 2023
886a6d3
some refactoring
provinzkraut Aug 7, 2023
84b7a4f
use localized names only
provinzkraut Aug 7, 2023
f64e39a
reduce creation of temporary variables
provinzkraut Aug 8, 2023
909c399
inline all _transfer_instance_data calls
provinzkraut Aug 8, 2023
4cef153
fix extraction for empty DTOs
provinzkraut Aug 12, 2023
edebd67
optimise field access
provinzkraut Aug 12, 2023
c6c56e2
refactor and inline nested _transfer_type_data
provinzkraut Aug 13, 2023
613764e
refactor _transfer_data
provinzkraut Aug 13, 2023
70d7a9f
inline _transfer_data
provinzkraut Aug 13, 2023
94b76f3
pre-compute generated functions
provinzkraut Aug 13, 2023
bb9556f
optimise transfer to dicts
provinzkraut Aug 15, 2023
197e09c
formatting
provinzkraut Aug 15, 2023
75ed7dc
inline transfer_nested_union_type_data
provinzkraut Aug 17, 2023
2989d50
feat(DT): Improve performance with codegeneration - WIP (Sourcery ref…
sourcery-ai[bot] Aug 17, 2023
052ce63
formatting
provinzkraut Aug 17, 2023
b99c3f6
add feature flag for DTO codegen
provinzkraut Aug 21, 2023
92adf02
remove duplicated implementation
provinzkraut Aug 24, 2023
7c2b4fd
implement more tests for codegen backend
provinzkraut Aug 24, 2023
3e00ac8
fix test typing
provinzkraut Aug 24, 2023
5f5884a
don't pass locals to fn explicitly
provinzkraut Aug 24, 2023
42b6e73
optimise nested attribute access
provinzkraut Aug 25, 2023
2a4054c
feat(DTO): Improve performance with code generation - WIP (Sourcery r…
sourcery-ai[bot] Aug 26, 2023
cee3f81
fix pyproject.toml
provinzkraut Aug 26, 2023
af4e336
simplify nested blocks
provinzkraut Aug 27, 2023
9d3ce10
fix rebase error :)
provinzkraut Aug 27, 2023
764f434
add app level feature flag
provinzkraut Sep 29, 2023
30b495b
some refactoring
provinzkraut Sep 29, 2023
e7f563b
fix StrEnum
provinzkraut Sep 29, 2023
1bbb2ef
Merge branch 'main' into dto-codegen
provinzkraut Sep 30, 2023
7ca5bb7
use unique_name_for_scope
provinzkraut Sep 30, 2023
62a5ff8
Merge branch 'main' into dto-codegen
provinzkraut Oct 3, 2023
81d39b0
Merge branch 'main' into dto-codegen
provinzkraut Oct 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions litestar/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import partial
from itertools import chain
from pathlib import Path
from typing import TYPE_CHECKING, Any, AsyncGenerator, Callable, Mapping, Sequence, TypedDict, cast
from typing import TYPE_CHECKING, Any, AsyncGenerator, Callable, Iterable, Mapping, Sequence, TypedDict, cast

from litestar._asgi import ASGIRouter
from litestar._asgi.utils import get_route_handlers, wrap_in_exception_handler
Expand Down Expand Up @@ -51,6 +51,7 @@
if TYPE_CHECKING:
from typing_extensions import Self

from litestar.config.app import ExperimentalFeatures
from litestar.config.compression import CompressionConfig
from litestar.config.cors import CORSConfig
from litestar.config.csrf import CSRFConfig
Expand Down Expand Up @@ -160,6 +161,7 @@ class Litestar(Router):
"template_engine",
"websocket_class",
"pdb_on_exception",
"experimental_features",
)

def __init__(
Expand Down Expand Up @@ -214,6 +216,7 @@ def __init__(
lifespan: Sequence[Callable[[Litestar], AbstractAsyncContextManager] | AbstractAsyncContextManager]
| None = None,
pdb_on_exception: bool | None = None,
experimental_features: Iterable[ExperimentalFeatures] | None = None,
) -> None:
"""Initialize a ``Litestar`` application.

Expand Down Expand Up @@ -298,9 +301,11 @@ def __init__(
application.
template_config: An instance of :class:`TemplateConfig <.template.TemplateConfig>`
type_encoders: A mapping of types to callables that transform them into types supported for serialization.
type_decoders: A sequence of tuples, each composed of a predicate testing for type identity and a msgspec hook for deserialization.
type_decoders: A sequence of tuples, each composed of a predicate testing for type identity and a msgspec
hook for deserialization.
websocket_class: An optional subclass of :class:`WebSocket <.connection.WebSocket>` to use for websocket
connections.
experimental_features: An iterable of experimental features to enable
"""
if logging_config is Empty:
logging_config = LoggingConfig()
Expand Down Expand Up @@ -359,6 +364,7 @@ def __init__(
type_encoders=type_encoders,
type_decoders=type_decoders,
websocket_class=websocket_class,
experimental_features=list(experimental_features or []),
)
for handler in chain(
on_app_init or [],
Expand All @@ -371,6 +377,7 @@ def __init__(
self._openapi_schema: OpenAPI | None = None
self._debug: bool = True
self._lifespan_managers = config.lifespan
self.experimental_features = frozenset(config.experimental_features or [])

self.get_logger: GetLogger = get_logger_placeholder
self.logger: Logger | None = None
Expand Down
11 changes: 10 additions & 1 deletion litestar/config/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import enum
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, Callable, Sequence

Expand Down Expand Up @@ -51,7 +52,10 @@
from litestar.types.empty import EmptyType


__all__ = ("AppConfig",)
__all__ = (
"AppConfig",
"ExperimentalFeatures",
)


@dataclass
Expand Down Expand Up @@ -198,6 +202,7 @@ class AppConfig:
multipart_form_part_limit: int = field(default=1000)
"""The maximal number of allowed parts in a multipart/formdata request. This limit is intended to protect from
DoS attacks."""
experimental_features: list[ExperimentalFeatures] | None = None

def __post_init__(self) -> None:
"""Normalize the allowed hosts to be a config or None.
Expand All @@ -207,3 +212,7 @@ def __post_init__(self) -> None:
"""
if self.allowed_hosts and isinstance(self.allowed_hosts, list):
self.allowed_hosts = AllowedHostsConfig(allowed_hosts=self.allowed_hosts)


class ExperimentalFeatures(str, enum.Enum):
DTO_CODEGEN = "DTO_CODEGEN"
Loading