This commit is contained in:
Iliyan Angelov
2025-12-01 06:50:10 +02:00
parent 91f51bc6fe
commit 62c1fe5951
4682 changed files with 544807 additions and 31208 deletions

View File

@@ -2,7 +2,7 @@ from __future__ import annotations
import json
import warnings
from typing import TYPE_CHECKING, Any, Callable, Type, TypeVar, Union
from typing import TYPE_CHECKING, Any, Callable, TypeVar, Union
from typing_extensions import deprecated
@@ -17,19 +17,20 @@ if not TYPE_CHECKING:
__all__ = 'parse_obj_as', 'schema_of', 'schema_json_of'
NameFactory = Union[str, Callable[[Type[Any]], str]]
NameFactory = Union[str, Callable[[type[Any]], str]]
T = TypeVar('T')
@deprecated(
'parse_obj_as is deprecated. Use pydantic.TypeAdapter.validate_python instead.', category=PydanticDeprecatedSince20
'`parse_obj_as` is deprecated. Use `pydantic.TypeAdapter.validate_python` instead.',
category=None,
)
def parse_obj_as(type_: type[T], obj: Any, type_name: NameFactory | None = None) -> T:
warnings.warn(
'parse_obj_as is deprecated. Use pydantic.TypeAdapter.validate_python instead.',
DeprecationWarning,
'`parse_obj_as` is deprecated. Use `pydantic.TypeAdapter.validate_python` instead.',
category=PydanticDeprecatedSince20,
stacklevel=2,
)
if type_name is not None: # pragma: no cover
@@ -42,7 +43,8 @@ def parse_obj_as(type_: type[T], obj: Any, type_name: NameFactory | None = None)
@deprecated(
'schema_of is deprecated. Use pydantic.TypeAdapter.json_schema instead.', category=PydanticDeprecatedSince20
'`schema_of` is deprecated. Use `pydantic.TypeAdapter.json_schema` instead.',
category=None,
)
def schema_of(
type_: Any,
@@ -54,7 +56,9 @@ def schema_of(
) -> dict[str, Any]:
"""Generate a JSON schema (as dict) for the passed model or dynamically generated one."""
warnings.warn(
'schema_of is deprecated. Use pydantic.TypeAdapter.json_schema instead.', DeprecationWarning, stacklevel=2
'`schema_of` is deprecated. Use `pydantic.TypeAdapter.json_schema` instead.',
category=PydanticDeprecatedSince20,
stacklevel=2,
)
res = TypeAdapter(type_).json_schema(
by_alias=by_alias,
@@ -75,7 +79,8 @@ def schema_of(
@deprecated(
'schema_json_of is deprecated. Use pydantic.TypeAdapter.json_schema instead.', category=PydanticDeprecatedSince20
'`schema_json_of` is deprecated. Use `pydantic.TypeAdapter.json_schema` instead.',
category=None,
)
def schema_json_of(
type_: Any,
@@ -88,7 +93,9 @@ def schema_json_of(
) -> str:
"""Generate a JSON schema (as JSON) for the passed model or dynamically generated one."""
warnings.warn(
'schema_json_of is deprecated. Use pydantic.TypeAdapter.json_schema instead.', DeprecationWarning, stacklevel=2
'`schema_json_of` is deprecated. Use `pydantic.TypeAdapter.json_schema` instead.',
category=PydanticDeprecatedSince20,
stacklevel=2,
)
return json.dumps(
schema_of(type_, title=title, by_alias=by_alias, ref_template=ref_template, schema_generator=schema_generator),