codekingpro/portable-devtools
114k
1"""Pydantic-specific warnings."""2 3from __future__ import annotations as _annotations4 5from .version import version_short6 7__all__ = (8 'PydanticDeprecatedSince20',9 'PydanticDeprecatedSince26',10 'PydanticDeprecatedSince29',11 'PydanticDeprecatedSince210',12 'PydanticDeprecatedSince211',13 'PydanticDeprecatedSince212',14 'PydanticDeprecationWarning',15 'PydanticExperimentalWarning',16 'ArbitraryTypeWarning',17 'UnsupportedFieldAttributeWarning',18 'TypedDictExtraConfigWarning',19)20 21 22class PydanticDeprecationWarning(DeprecationWarning):23 """A Pydantic specific deprecation warning.24 25 This warning is raised when using deprecated functionality in Pydantic. It provides information on when the26 deprecation was introduced and the expected version in which the corresponding functionality will be removed.27 28 Attributes:29 message: Description of the warning.30 since: Pydantic version in what the deprecation was introduced.31 expected_removal: Pydantic version in what the corresponding functionality expected to be removed.32 """33 34 message: str35 since: tuple[int, int]36 expected_removal: tuple[int, int]37 38 def __init__(39 self, message: str, *args: object, since: tuple[int, int], expected_removal: tuple[int, int] | None = None40 ) -> None:41 super().__init__(message, *args)42 self.message = message.rstrip('.')43 self.since = since44 self.expected_removal = expected_removal if expected_removal is not None else (since[0] + 1, 0)45 46 def __str__(self) -> str:47 message = (48 f'{self.message}. Deprecated in Pydantic V{self.since[0]}.{self.since[1]}'49 f' to be removed in V{self.expected_removal[0]}.{self.expected_removal[1]}.'50 )51 if self.since == (2, 0):52 message += f' See Pydantic V2 Migration Guide at https://errors.pydantic.dev/{version_short()}/migration/'53 return message54 55 56class PydanticDeprecatedSince20(PydanticDeprecationWarning):57 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.0."""58 59 def __init__(self, message: str, *args: object) -> None:60 super().__init__(message, *args, since=(2, 0), expected_removal=(3, 0))61 62 63class PydanticDeprecatedSince26(PydanticDeprecationWarning): # pragma: no cover64 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.6."""65 66 def __init__(self, message: str, *args: object) -> None:67 super().__init__(message, *args, since=(2, 6), expected_removal=(3, 0))68 69 70class PydanticDeprecatedSince29(PydanticDeprecationWarning):71 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.9."""72 73 def __init__(self, message: str, *args: object) -> None:74 super().__init__(message, *args, since=(2, 9), expected_removal=(3, 0))75 76 77class PydanticDeprecatedSince210(PydanticDeprecationWarning):78 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.10."""79 80 def __init__(self, message: str, *args: object) -> None:81 super().__init__(message, *args, since=(2, 10), expected_removal=(3, 0))82 83 84class PydanticDeprecatedSince211(PydanticDeprecationWarning):85 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.11."""86 87 def __init__(self, message: str, *args: object) -> None:88 super().__init__(message, *args, since=(2, 11), expected_removal=(3, 0))89 90 91class PydanticDeprecatedSince212(PydanticDeprecationWarning):92 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.12."""93 94 def __init__(self, message: str, *args: object) -> None:95 super().__init__(message, *args, since=(2, 12), expected_removal=(3, 0))96 97 98class GenericBeforeBaseModelWarning(Warning):99 pass100 101 102class PydanticExperimentalWarning(Warning):103 """A Pydantic specific experimental functionality warning.104 105 It is raised to warn users that the functionality may change or be removed in future versions of Pydantic.106 """107 108 109class CoreSchemaGenerationWarning(UserWarning):110 """A warning raised during core schema generation."""111 112 113class ArbitraryTypeWarning(CoreSchemaGenerationWarning):114 """A warning raised when Pydantic fails to generate a core schema for an arbitrary type."""115 116 117class UnsupportedFieldAttributeWarning(CoreSchemaGenerationWarning):118 """A warning raised when a `Field()` attribute isn't supported in the context it is used."""119 120 121class TypedDictExtraConfigWarning(CoreSchemaGenerationWarning):122 """A warning raised when the [`extra`][pydantic.ConfigDict.extra] configuration is incompatible with the `closed` or `extra_items` specification."""123 