Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pydantic/warnings.py: 67%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""Pydantic-specific warnings."""
3from __future__ import annotations as _annotations
5from .version import version_short
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)
22class PydanticDeprecationWarning(DeprecationWarning):
23 """A Pydantic specific deprecation warning.
25 This warning is raised when using deprecated functionality in Pydantic. It provides information on when the
26 deprecation was introduced and the expected version in which the corresponding functionality will be removed.
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 """
34 message: str
35 since: tuple[int, int]
36 expected_removal: tuple[int, int]
38 def __init__(
39 self, message: str, *args: object, since: tuple[int, int], expected_removal: tuple[int, int] | None = None
40 ) -> None:
41 super().__init__(message, *args)
42 self.message = message.rstrip('.')
43 self.since = since
44 self.expected_removal = expected_removal if expected_removal is not None else (since[0] + 1, 0)
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 message
56class PydanticDeprecatedSince20(PydanticDeprecationWarning):
57 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.0."""
59 def __init__(self, message: str, *args: object) -> None:
60 super().__init__(message, *args, since=(2, 0), expected_removal=(3, 0))
63class PydanticDeprecatedSince26(PydanticDeprecationWarning):
64 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.6."""
66 def __init__(self, message: str, *args: object) -> None:
67 super().__init__(message, *args, since=(2, 6), expected_removal=(3, 0))
70class PydanticDeprecatedSince29(PydanticDeprecationWarning):
71 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.9."""
73 def __init__(self, message: str, *args: object) -> None:
74 super().__init__(message, *args, since=(2, 9), expected_removal=(3, 0))
77class PydanticDeprecatedSince210(PydanticDeprecationWarning):
78 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.10."""
80 def __init__(self, message: str, *args: object) -> None:
81 super().__init__(message, *args, since=(2, 10), expected_removal=(3, 0))
84class PydanticDeprecatedSince211(PydanticDeprecationWarning):
85 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.11."""
87 def __init__(self, message: str, *args: object) -> None:
88 super().__init__(message, *args, since=(2, 11), expected_removal=(3, 0))
91class PydanticDeprecatedSince212(PydanticDeprecationWarning):
92 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.12."""
94 def __init__(self, message: str, *args: object) -> None:
95 super().__init__(message, *args, since=(2, 12), expected_removal=(3, 0))
98class GenericBeforeBaseModelWarning(Warning):
99 pass
102class PydanticExperimentalWarning(Warning):
103 """A Pydantic specific experimental functionality warning.
105 It is raised to warn users that the functionality may change or be removed in future versions of Pydantic.
106 """
109class CoreSchemaGenerationWarning(UserWarning):
110 """A warning raised during core schema generation."""
113class ArbitraryTypeWarning(CoreSchemaGenerationWarning):
114 """A warning raised when Pydantic fails to generate a core schema for an arbitrary type."""
117class UnsupportedFieldAttributeWarning(CoreSchemaGenerationWarning):
118 """A warning raised when a `Field()` attribute isn't supported in the context it is used."""
121class TypedDictExtraConfigWarning(CoreSchemaGenerationWarning):
122 """A warning raised when the [`extra`][pydantic.ConfigDict.extra] configuration is incompatible with the `closed` or `extra_items` specification."""