Coverage for pydantic/warnings.py: 96.43%
26 statements
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-21 17:00 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-21 17:00 +0000
1"""Pydantic-specific warnings."""
3from __future__ import annotations as _annotations 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
5from .version import version_short 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
7__all__ = ( 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
8 'PydanticDeprecatedSince20',
9 'PydanticDeprecationWarning',
10 'PydanticDeprecatedSince26',
11 'PydanticExperimentalWarning',
12)
15class PydanticDeprecationWarning(DeprecationWarning): 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
16 """A Pydantic specific deprecation warning.
18 This warning is raised when using deprecated functionality in Pydantic. It provides information on when the
19 deprecation was introduced and the expected version in which the corresponding functionality will be removed.
21 Attributes:
22 message: Description of the warning.
23 since: Pydantic version in what the deprecation was introduced.
24 expected_removal: Pydantic version in what the corresponding functionality expected to be removed.
25 """
27 message: str 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
28 since: tuple[int, int] 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
29 expected_removal: tuple[int, int] 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
31 def __init__( 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
32 self, message: str, *args: object, since: tuple[int, int], expected_removal: tuple[int, int] | None = None
33 ) -> None:
34 super().__init__(message, *args) 1abcdefghijklmnopqrstuvwxyzABCDEF
35 self.message = message.rstrip('.') 1abcdefghijklmnopqrstuvwxyzABCDEF
36 self.since = since 1abcdefghijklmnopqrstuvwxyzABCDEF
37 self.expected_removal = expected_removal if expected_removal is not None else (since[0] + 1, 0) 1abcdefghijklmnopqrstuvwxyzABCDEF
39 def __str__(self) -> str: 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
40 message = ( 1abcdefghijklmnopqrstuvwxyzABCDEF
41 f'{self.message}. Deprecated in Pydantic V{self.since[0]}.{self.since[1]}'
42 f' to be removed in V{self.expected_removal[0]}.{self.expected_removal[1]}.'
43 )
44 if self.since == (2, 0): 1abcdefghijklmnopqrstuvwxyzABCDEF
45 message += f' See Pydantic V2 Migration Guide at https://errors.pydantic.dev/{version_short()}/migration/' 1abcdefghijklmnopqrstuvwxyzABCDEF
46 return message 1abcdefghijklmnopqrstuvwxyzABCDEF
49class PydanticDeprecatedSince20(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
50 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.0."""
52 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
53 super().__init__(message, *args, since=(2, 0), expected_removal=(3, 0)) 1abcdefghijklmnopqrstuvwxyzABCDEF
56class PydanticDeprecatedSince26(PydanticDeprecationWarning): 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
57 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.6."""
59 def __init__(self, message: str, *args: object) -> None: 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
60 super().__init__(message, *args, since=(2, 0), expected_removal=(3, 0))
63class GenericBeforeBaseModelWarning(Warning): 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
64 pass 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
67class PydanticExperimentalWarning(Warning): 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
68 """A Pydantic specific experimental functionality warning.
70 This warning is raised when using experimental functionality in Pydantic.
71 It is raised to warn users that the functionality may change or be removed in future versions of Pydantic.
72 """