Coverage for pydantic/warnings.py: 97.50%
38 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-20 16:49 +0000
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-20 16:49 +0000
1"""Pydantic-specific warnings."""
3from __future__ import annotations as _annotations 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
5from .version import version_short 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
7__all__ = ( 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
8 'PydanticDeprecatedSince20',
9 'PydanticDeprecatedSince26',
10 'PydanticDeprecatedSince29',
11 'PydanticDeprecatedSince210',
12 'PydanticDeprecatedSince211',
13 'PydanticDeprecationWarning',
14 'PydanticExperimentalWarning',
15 'ArbitraryTypeWarning',
16 'UnsupportedFieldAttributeWarning',
17)
20class PydanticDeprecationWarning(DeprecationWarning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
21 """A Pydantic specific deprecation warning.
23 This warning is raised when using deprecated functionality in Pydantic. It provides information on when the
24 deprecation was introduced and the expected version in which the corresponding functionality will be removed.
26 Attributes:
27 message: Description of the warning.
28 since: Pydantic version in what the deprecation was introduced.
29 expected_removal: Pydantic version in what the corresponding functionality expected to be removed.
30 """
32 message: str 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
33 since: tuple[int, int] 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
34 expected_removal: tuple[int, int] 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
36 def __init__( 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
37 self, message: str, *args: object, since: tuple[int, int], expected_removal: tuple[int, int] | None = None
38 ) -> None:
39 super().__init__(message, *args) 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
40 self.message = message.rstrip('.') 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
41 self.since = since 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
42 self.expected_removal = expected_removal if expected_removal is not None else (since[0] + 1, 0) 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
44 def __str__(self) -> str: 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
45 message = ( 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
46 f'{self.message}. Deprecated in Pydantic V{self.since[0]}.{self.since[1]}'
47 f' to be removed in V{self.expected_removal[0]}.{self.expected_removal[1]}.'
48 )
49 if self.since == (2, 0): 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
50 message += f' See Pydantic V2 Migration Guide at https://errors.pydantic.dev/{version_short()}/migration/' 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
51 return message 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
54class PydanticDeprecatedSince20(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
55 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.0."""
57 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
58 super().__init__(message, *args, since=(2, 0), expected_removal=(3, 0)) 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
61class PydanticDeprecatedSince26(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
62 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.6."""
64 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
65 super().__init__(message, *args, since=(2, 6), expected_removal=(3, 0))
68class PydanticDeprecatedSince29(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
69 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.9."""
71 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
72 super().__init__(message, *args, since=(2, 9), expected_removal=(3, 0)) 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
75class PydanticDeprecatedSince210(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
76 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.10."""
78 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
79 super().__init__(message, *args, since=(2, 10), expected_removal=(3, 0)) 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
82class PydanticDeprecatedSince211(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
83 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.11."""
85 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
86 super().__init__(message, *args, since=(2, 11), expected_removal=(3, 0)) 1abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
89class GenericBeforeBaseModelWarning(Warning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
90 pass 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
93class PydanticExperimentalWarning(Warning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
94 """A Pydantic specific experimental functionality warning.
96 This warning is raised when using experimental functionality in Pydantic.
97 It is raised to warn users that the functionality may change or be removed in future versions of Pydantic.
98 """
101class CoreSchemaGenerationWarning(UserWarning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
102 """A warning raised during core schema generation."""
105class ArbitraryTypeWarning(CoreSchemaGenerationWarning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
106 """A warning raised when Pydantic fails to generate a core schema for an arbitrary type."""
109class UnsupportedFieldAttributeWarning(CoreSchemaGenerationWarning): 1abcdefghijklmnopqrstuvwxyzABPCDEFGHIJKLMNO
110 """A warning raised when a `Field()` attribute isn't supported in the context it is used."""