Coverage for pydantic/warnings.py: 97.30%
35 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 15:12 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-04-17 15:12 +0000
1"""Pydantic-specific warnings."""
3from __future__ import annotations as _annotations 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
5from .version import version_short 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
7__all__ = ( 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
8 'PydanticDeprecatedSince20',
9 'PydanticDeprecatedSince26',
10 'PydanticDeprecatedSince29',
11 'PydanticDeprecatedSince210',
12 'PydanticDeprecatedSince211',
13 'PydanticDeprecationWarning',
14 'PydanticExperimentalWarning',
15)
18class PydanticDeprecationWarning(DeprecationWarning): 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
19 """A Pydantic specific deprecation warning.
21 This warning is raised when using deprecated functionality in Pydantic. It provides information on when the
22 deprecation was introduced and the expected version in which the corresponding functionality will be removed.
24 Attributes:
25 message: Description of the warning.
26 since: Pydantic version in what the deprecation was introduced.
27 expected_removal: Pydantic version in what the corresponding functionality expected to be removed.
28 """
30 message: str 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
31 since: tuple[int, int] 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
32 expected_removal: tuple[int, int] 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
34 def __init__( 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
35 self, message: str, *args: object, since: tuple[int, int], expected_removal: tuple[int, int] | None = None
36 ) -> None:
37 super().__init__(message, *args) 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
38 self.message = message.rstrip('.') 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
39 self.since = since 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
40 self.expected_removal = expected_removal if expected_removal is not None else (since[0] + 1, 0) 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
42 def __str__(self) -> str: 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
43 message = ( 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
44 f'{self.message}. Deprecated in Pydantic V{self.since[0]}.{self.since[1]}'
45 f' to be removed in V{self.expected_removal[0]}.{self.expected_removal[1]}.'
46 )
47 if self.since == (2, 0): 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
48 message += f' See Pydantic V2 Migration Guide at https://errors.pydantic.dev/{version_short()}/migration/' 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
49 return message 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
52class PydanticDeprecatedSince20(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
53 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.0."""
55 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
56 super().__init__(message, *args, since=(2, 0), expected_removal=(3, 0)) 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
59class PydanticDeprecatedSince26(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
60 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.6."""
62 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
63 super().__init__(message, *args, since=(2, 6), expected_removal=(3, 0))
66class PydanticDeprecatedSince29(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
67 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.9."""
69 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
70 super().__init__(message, *args, since=(2, 9), expected_removal=(3, 0)) 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
73class PydanticDeprecatedSince210(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
74 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.10."""
76 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
77 super().__init__(message, *args, since=(2, 10), expected_removal=(3, 0)) 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
80class PydanticDeprecatedSince211(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
81 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.11."""
83 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
84 super().__init__(message, *args, since=(2, 11), expected_removal=(3, 0)) 1abcdefghijklmnopqrstuvwxyzABCDEFGHI
87class GenericBeforeBaseModelWarning(Warning): 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
88 pass 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
91class PydanticExperimentalWarning(Warning): 1abcdefghijklmnopqrstuvwxJKLMNOPyzABCDEFGHI
92 """A Pydantic specific experimental functionality warning.
94 This warning is raised when using experimental functionality in Pydantic.
95 It is raised to warn users that the functionality may change or be removed in future versions of Pydantic.
96 """