Coverage for pydantic / warnings.py: 96.30%
27 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-11-21 11:56 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-11-21 11:56 +0000
1"""Pydantic-specific warnings."""
3from __future__ import annotations as _annotations 1abcdefghijklsmnopqr
5__all__ = ( 1abcdefghijklsmnopqr
6 'PydanticDeprecatedSince20',
7 'PydanticDeprecatedSince211',
8 'PydanticDeprecationWarning',
9 'PydanticExperimentalWarning',
10 'ArbitraryTypeWarning',
11 'UnsupportedFieldAttributeWarning',
12 'TypedDictExtraConfigWarning',
13)
16class PydanticDeprecationWarning(DeprecationWarning): 1abcdefghijklsmnopqr
17 """A Pydantic specific deprecation warning.
19 This warning is raised when using deprecated functionality in Pydantic. It provides information on when the
20 deprecation was introduced and the expected version in which the corresponding functionality will be removed.
22 Attributes:
23 message: Description of the warning.
24 since: Pydantic version in what the deprecation was introduced.
25 expected_removal: Pydantic version in what the corresponding functionality expected to be removed.
26 """
28 message: str 1abcdefghijklsmnopqr
29 since: tuple[int, int] 1abcdefghijklsmnopqr
30 expected_removal: tuple[int, int] 1abcdefghijklsmnopqr
32 def __init__( 1abcdefghijklsmnopqr
33 self, message: str, *args: object, since: tuple[int, int], expected_removal: tuple[int, int] | None = None
34 ) -> None:
35 super().__init__(message, *args) 1abcdefghijklmnopqr
36 self.message = message.rstrip('.') 1abcdefghijklmnopqr
37 self.since = since 1abcdefghijklmnopqr
38 self.expected_removal = expected_removal if expected_removal is not None else (since[0] + 1, 0) 1abcdefghijklmnopqr
40 def __str__(self) -> str: 1abcdefghijklsmnopqr
41 message = ( 1abcdefghijklmnopqr
42 f'{self.message}. Deprecated in Pydantic V{self.since[0]}.{self.since[1]}'
43 f' to be removed in V{self.expected_removal[0]}.{self.expected_removal[1]}.'
44 )
45 return message 1abcdefghijklmnopqr
48class PydanticDeprecatedSince20(PydanticDeprecationWarning): 1abcdefghijklsmnopqr
49 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.0."""
51 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklsmnopqr
52 super().__init__(message, *args, since=(2, 0), expected_removal=(3, 0)) 1abcdefghijklmnopqr
55class PydanticDeprecatedSince211(PydanticDeprecationWarning): 1abcdefghijklsmnopqr
56 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.11."""
58 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklsmnopqr
59 super().__init__(message, *args, since=(2, 11), expected_removal=(3, 0))
62class GenericBeforeBaseModelWarning(Warning): 1abcdefghijklsmnopqr
63 pass 1abcdefghijklsmnopqr
66class PydanticExperimentalWarning(Warning): 1abcdefghijklsmnopqr
67 """A Pydantic specific experimental functionality warning.
69 It is raised to warn users that the functionality may change or be removed in future versions of Pydantic.
70 """
73class CoreSchemaGenerationWarning(UserWarning): 1abcdefghijklsmnopqr
74 """A warning raised during core schema generation."""
77class ArbitraryTypeWarning(CoreSchemaGenerationWarning): 1abcdefghijklsmnopqr
78 """A warning raised when Pydantic fails to generate a core schema for an arbitrary type."""
81class UnsupportedFieldAttributeWarning(CoreSchemaGenerationWarning): 1abcdefghijklsmnopqr
82 """A warning raised when a `Field()` attribute isn't supported in the context it is used."""
85class TypedDictExtraConfigWarning(CoreSchemaGenerationWarning): 1abcdefghijklsmnopqr
86 """A warning raised when the [`extra`][pydantic.ConfigDict.extra] configuration is incompatible with the `closed` or `extra_items` specification."""