-
-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deprecate
litestar.contrib.pydantic
(#3852)
* feat: deprecate `litestar.contrib.pydantic`
- Loading branch information
Showing
38 changed files
with
1,773 additions
and
1,440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,6 @@ plugins | |
flash_messages | ||
htmx | ||
problem_details | ||
pydantic | ||
structlog | ||
sqlalchemy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pydantic | ||
======== | ||
|
||
.. automodule:: litestar.plugins.pydantic | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
# ruff: noqa: TCH004, F401 | ||
from __future__ import annotations | ||
|
||
import inspect | ||
from inspect import Signature | ||
from typing import Any | ||
from typing import TYPE_CHECKING # pragma: no cover | ||
|
||
from litestar.contrib.pydantic.utils import is_pydantic_model_class | ||
from litestar.plugins import DIPlugin | ||
from litestar.utils import warn_deprecation # pragma: no cover | ||
|
||
__all__ = ("PydanticDIPlugin",) # pragma: no cover | ||
|
||
class PydanticDIPlugin(DIPlugin): | ||
def has_typed_init(self, type_: Any) -> bool: | ||
return is_pydantic_model_class(type_) | ||
|
||
def get_typed_init(self, type_: Any) -> tuple[Signature, dict[str, Any]]: | ||
try: | ||
model_fields = dict(type_.model_fields) | ||
except AttributeError: | ||
model_fields = {k: model_field.field_info for k, model_field in type_.__fields__.items()} | ||
def __getattr__(attr_name: str) -> object: # pragma: no cover | ||
if attr_name in __all__: | ||
from litestar.plugins.pydantic.plugins.di import PydanticDIPlugin | ||
|
||
parameters = [ | ||
inspect.Parameter(name=field_name, kind=inspect.Parameter.KEYWORD_ONLY, annotation=Any) | ||
for field_name in model_fields | ||
] | ||
type_hints = {field_name: Any for field_name in model_fields} | ||
return Signature(parameters), type_hints | ||
warn_deprecation( | ||
deprecated_name=f"litestar.contrib.pydantic.pydantic_di_plugin.{attr_name}", | ||
version="2.12", | ||
kind="import", | ||
removal_in="3.0", | ||
info=f"importing {attr_name} from 'litestar.contrib.pydantic.pydantic_di_plugin' is deprecated, please " | ||
f"import it from 'litestar.plugins.pydantic' instead", | ||
) | ||
value = globals()[attr_name] = locals()[attr_name] | ||
return value | ||
|
||
raise AttributeError(f"module {__name__!r} has no attribute {attr_name!r}") | ||
|
||
|
||
if TYPE_CHECKING: | ||
from litestar.plugins.pydantic.plugins.di import PydanticDIPlugin |
Oops, something went wrong.