mirror of
https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git
synced 2025-08-14 00:25:46 +02:00
Проверка 09.02.2025
This commit is contained in:
@@ -11,7 +11,7 @@ import weakref
|
||||
from abc import ABCMeta
|
||||
from functools import lru_cache, partial
|
||||
from types import FunctionType
|
||||
from typing import Any, Callable, Generic, Literal, NoReturn, TypeVar, cast
|
||||
from typing import Any, Callable, Generic, Literal, NoReturn, cast
|
||||
|
||||
from pydantic_core import PydanticUndefined, SchemaSerializer
|
||||
from typing_extensions import TypeAliasType, dataclass_transform, deprecated, get_args
|
||||
@@ -131,8 +131,6 @@ class ModelMetaclass(ABCMeta):
|
||||
|
||||
namespace['__class_vars__'] = class_vars
|
||||
namespace['__private_attributes__'] = {**base_private_attributes, **private_attributes}
|
||||
if __pydantic_generic_metadata__:
|
||||
namespace['__pydantic_generic_metadata__'] = __pydantic_generic_metadata__
|
||||
|
||||
cls = cast('type[BaseModel]', super().__new__(mcs, cls_name, bases, namespace, **kwargs))
|
||||
BaseModel_ = import_cached_base_model()
|
||||
@@ -255,60 +253,6 @@ class ModelMetaclass(ABCMeta):
|
||||
namespace.get('__annotations__', {}).clear()
|
||||
return super().__new__(mcs, cls_name, bases, namespace, **kwargs)
|
||||
|
||||
def mro(cls) -> list[type[Any]]:
|
||||
original_mro = super().mro()
|
||||
|
||||
if cls.__bases__ == (object,):
|
||||
return original_mro
|
||||
|
||||
generic_metadata: PydanticGenericMetadata | None = cls.__dict__.get('__pydantic_generic_metadata__')
|
||||
if not generic_metadata:
|
||||
return original_mro
|
||||
|
||||
assert_err_msg = 'Unexpected error occurred when generating MRO of generic subclass. Please report this issue on GitHub: https://github.com/pydantic/pydantic/issues.'
|
||||
|
||||
origin: type[BaseModel] | None
|
||||
origin, args = (
|
||||
generic_metadata['origin'],
|
||||
generic_metadata['args'],
|
||||
)
|
||||
if not origin:
|
||||
return original_mro
|
||||
|
||||
target_params = origin.__pydantic_generic_metadata__['parameters']
|
||||
param_dict = dict(zip(target_params, args))
|
||||
|
||||
indexed_origins = {origin}
|
||||
|
||||
new_mro: list[type[Any]] = [cls]
|
||||
for base in original_mro[1:]:
|
||||
base_origin: type[BaseModel] | None = getattr(base, '__pydantic_generic_metadata__', {}).get('origin')
|
||||
base_params: tuple[TypeVar, ...] = getattr(base, '__pydantic_generic_metadata__', {}).get('parameters', ())
|
||||
|
||||
if base_origin in indexed_origins:
|
||||
continue
|
||||
elif base not in indexed_origins and base_params:
|
||||
assert set(base_params) <= param_dict.keys(), assert_err_msg
|
||||
new_base_args = tuple(param_dict[param] for param in base_params)
|
||||
new_base = base[new_base_args] # type: ignore
|
||||
new_mro.append(new_base)
|
||||
|
||||
indexed_origins.add(base_origin or base)
|
||||
|
||||
if base_origin is not None:
|
||||
# dropped previous indexed origins
|
||||
continue
|
||||
else:
|
||||
indexed_origins.add(base_origin or base)
|
||||
|
||||
# Avoid redundunt case such as
|
||||
# class A(BaseModel, Generic[T]): ...
|
||||
# A[T] is A # True
|
||||
if base is not new_mro[-1]:
|
||||
new_mro.append(base)
|
||||
|
||||
return new_mro
|
||||
|
||||
if not typing.TYPE_CHECKING: # pragma: no branch
|
||||
# We put `__getattr__` in a non-TYPE_CHECKING block because otherwise, mypy allows arbitrary attribute access
|
||||
|
||||
|
@@ -2554,8 +2554,13 @@ def _get_all_json_refs(item: Any) -> set[JsonRef]:
|
||||
current = stack.pop()
|
||||
if isinstance(current, dict):
|
||||
for key, value in current.items():
|
||||
if key == 'examples':
|
||||
continue # skip examples, allow arbitrary values / refs
|
||||
if key == 'examples' and isinstance(value, list):
|
||||
# Skip examples that may contain arbitrary values and references
|
||||
# (e.g. `{"examples": [{"$ref": "..."}]}`). Note: checking for value
|
||||
# of type list is necessary to avoid skipping valid portions of the schema,
|
||||
# for instance when "examples" is used as a property key. A more robust solution
|
||||
# could be found, but would require more advanced JSON Schema parsing logic.
|
||||
continue
|
||||
if key == '$ref' and isinstance(value, str):
|
||||
refs.add(JsonRef(value))
|
||||
elif isinstance(value, dict):
|
||||
|
@@ -786,7 +786,6 @@ class BaseModel(metaclass=_model_construction.ModelMetaclass):
|
||||
) # use dict as ordered set
|
||||
|
||||
with _generics.generic_recursion_self_type(origin, args) as maybe_self_type:
|
||||
# Check cached first otherwise `mro` may return `PydanticRecursiveRef`
|
||||
cached = _generics.get_cached_generic_type_late(cls, typevar_values, origin, args)
|
||||
if cached is not None:
|
||||
return cached
|
||||
|
@@ -10,7 +10,13 @@ from importlib.metadata import version
|
||||
from ipaddress import IPv4Address, IPv4Interface, IPv4Network, IPv6Address, IPv6Interface, IPv6Network
|
||||
from typing import TYPE_CHECKING, Any, ClassVar
|
||||
|
||||
from pydantic_core import MultiHostHost, PydanticCustomError, SchemaSerializer, core_schema
|
||||
from pydantic_core import (
|
||||
MultiHostHost,
|
||||
PydanticCustomError,
|
||||
PydanticSerializationUnexpectedValue,
|
||||
SchemaSerializer,
|
||||
core_schema,
|
||||
)
|
||||
from pydantic_core import MultiHostUrl as _CoreMultiHostUrl
|
||||
from pydantic_core import Url as _CoreUrl
|
||||
from typing_extensions import Annotated, Self, TypeAlias
|
||||
@@ -283,6 +289,16 @@ class _BaseUrl:
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def serialize_url(cls, url: Any, info: core_schema.SerializationInfo) -> str | Self:
|
||||
if not isinstance(url, cls):
|
||||
raise PydanticSerializationUnexpectedValue(
|
||||
f"Expected `{cls}` but got `{type(url)}` with value `'{url}'` - serialized value may not be as expected."
|
||||
)
|
||||
if info.mode == 'json':
|
||||
return str(url)
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def __get_pydantic_core_schema__(
|
||||
cls, source: type[_BaseUrl], handler: GetCoreSchemaHandler
|
||||
@@ -300,7 +316,9 @@ class _BaseUrl:
|
||||
return core_schema.no_info_wrap_validator_function(
|
||||
wrap_val,
|
||||
schema=core_schema.url_schema(**cls._constraints.defined_constraints),
|
||||
serialization=core_schema.to_string_ser_schema(),
|
||||
serialization=core_schema.plain_serializer_function_ser_schema(
|
||||
cls.serialize_url, info_arg=True, when_used='always'
|
||||
),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -450,6 +468,16 @@ class _BaseMultiHostUrl:
|
||||
)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def serialize_url(cls, url: Any, info: core_schema.SerializationInfo) -> str | Self:
|
||||
if not isinstance(url, cls):
|
||||
raise PydanticSerializationUnexpectedValue(
|
||||
f"Expected `{cls}` but got `{type(url)}` with value `'{url}'` - serialized value may not be as expected."
|
||||
)
|
||||
if info.mode == 'json':
|
||||
return str(url)
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def __get_pydantic_core_schema__(
|
||||
cls, source: type[_BaseMultiHostUrl], handler: GetCoreSchemaHandler
|
||||
@@ -467,7 +495,9 @@ class _BaseMultiHostUrl:
|
||||
return core_schema.no_info_wrap_validator_function(
|
||||
wrap_val,
|
||||
schema=core_schema.multi_host_url_schema(**cls._constraints.defined_constraints),
|
||||
serialization=core_schema.to_string_ser_schema(),
|
||||
serialization=core_schema.plain_serializer_function_ser_schema(
|
||||
cls.serialize_url, info_arg=True, when_used='always'
|
||||
),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
@@ -4,7 +4,7 @@ from __future__ import annotations as _annotations
|
||||
|
||||
__all__ = 'VERSION', 'version_info'
|
||||
|
||||
VERSION = '2.10.4'
|
||||
VERSION = '2.10.6'
|
||||
"""The version of Pydantic."""
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user