From fb3780b3bdf2fc2c41805ec72680bf3c68fa32fb Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 15 Oct 2024 18:19:58 +0300 Subject: [PATCH 1/2] docs: change the `ExperimentalFeatures.DTO_CODEGEN` description --- docs/usage/dto/0-basic-use.rst | 87 ++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 30 deletions(-) diff --git a/docs/usage/dto/0-basic-use.rst b/docs/usage/dto/0-basic-use.rst index 46693489e6..bca940e8bd 100644 --- a/docs/usage/dto/0-basic-use.rst +++ b/docs/usage/dto/0-basic-use.rst @@ -76,15 +76,14 @@ DTOs can similarly be defined on :class:`Routers ` and Improving performance with the codegen backend -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. note:: - This feature was introduced in ``2.2.0`` and hidden behind the ``DTO_CODEGEN`` - feature flag. As of ``2.8.0`` it is considered stable and enabled by default. It can - still be disabled selectively by using the - ``DTOConfig(experimental_codegen_backend=True)`` override. - + This feature was introduced in ``2.2.0`` and was hidden behind the ``DTO_CODEGEN`` + feature flag. As of ``2.8.0`` it is considered stable and is enabled by default. + It can still be disabled selectively by using the + ``DTOConfig(experimental_codegen_backend=False)`` override. The DTO backend is the part that does the heavy lifting for all the DTO features. It is responsible for the transforming, validation and parsing. Because of this, @@ -93,21 +92,11 @@ introduced by the DTOs, the DTO codegen backend was introduced; A DTO backend th increases efficiency by generating optimized Python code at runtime to perform all the necessary operations. -Enabling the backend --------------------- - -You can enable this backend globally for all DTOs by passing the appropriate feature -flag to your Litestar application: - -.. code-block:: python - - from litestar import Litestar - from litestar.config.app import ExperimentalFeatures - - app = Litestar(experimental_features=[ExperimentalFeatures.DTO_CODEGEN]) - +Disabling the backend +--------------------- -or selectively for individual DTOs: +You can use ``experimental_codegen_backend=False`` +to disable the codegen backend selectively: .. code-block:: python @@ -121,23 +110,61 @@ or selectively for individual DTOs: class FooDTO(DataclassDTO[Foo]): - config = DTOConfig(experimental_codegen_backend=True) + config = DTOConfig(experimental_codegen_backend=False) -The same flag can be used to disable the backend selectively: +Enabling the backend +-------------------- -.. code-block:: python +.. note:: This is a historical document meant for Litestar versions prior to 2.8.0 + This backend was enabled bu default since 2.8.0 - from dataclasses import dataclass - from litestar.dto import DTOConfig, DataclassDTO +.. warning:: ``ExperimentalFeatures.DTO_CODEGEN`` is deprecated and will be removed in 3.0.0 +.. dropdown:: Enabling DTO codegen backend + :icon: git-pull-request-closed - @dataclass - class Foo: - name: str + You can enable this backend globally for all DTOs by passing the appropriate feature + flag to your Litestar application: + .. code-block:: python - class FooDTO(DataclassDTO[Foo]): - config = DTOConfig(experimental_codegen_backend=False) + from litestar import Litestar + from litestar.config.app import ExperimentalFeatures + + app = Litestar(experimental_features=[ExperimentalFeatures.DTO_CODEGEN]) + + + or selectively for individual DTOs: + + .. code-block:: python + + from dataclasses import dataclass + from litestar.dto import DTOConfig, DataclassDTO + + + @dataclass + class Foo: + name: str + + + class FooDTO(DataclassDTO[Foo]): + config = DTOConfig(experimental_codegen_backend=True) + + The same flag can be used to disable the backend selectively: + + .. code-block:: python + + from dataclasses import dataclass + from litestar.dto import DTOConfig, DataclassDTO + + + @dataclass + class Foo: + name: str + + + class FooDTO(DataclassDTO[Foo]): + config = DTOConfig(experimental_codegen_backend=False) Performance improvements From 9a77b304d10a264b32cfd7e8f9359683ffc2214d Mon Sep 17 00:00:00 2001 From: sobolevn Date: Tue, 15 Oct 2024 18:21:33 +0300 Subject: [PATCH 2/2] docs: change the `ExperimentalFeatures.DTO_CODEGEN` description --- docs/usage/dto/0-basic-use.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/dto/0-basic-use.rst b/docs/usage/dto/0-basic-use.rst index bca940e8bd..621e655df2 100644 --- a/docs/usage/dto/0-basic-use.rst +++ b/docs/usage/dto/0-basic-use.rst @@ -116,7 +116,7 @@ Enabling the backend -------------------- .. note:: This is a historical document meant for Litestar versions prior to 2.8.0 - This backend was enabled bu default since 2.8.0 + This backend was enabled by default since 2.8.0 .. warning:: ``ExperimentalFeatures.DTO_CODEGEN`` is deprecated and will be removed in 3.0.0