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

43 statements  

1"""Pydantic-specific warnings.""" 

2 

3from __future__ import annotations as _annotations 

4 

5from .version import version_short 

6 

7__all__ = ( 

8 'PydanticDeprecatedSince20', 

9 'PydanticDeprecatedSince26', 

10 'PydanticDeprecatedSince29', 

11 'PydanticDeprecatedSince210', 

12 'PydanticDeprecatedSince211', 

13 'PydanticDeprecatedSince212', 

14 'PydanticDeprecatedSince214', 

15 'PydanticDeprecationWarning', 

16 'PydanticExperimentalWarning', 

17 'ArbitraryTypeWarning', 

18 'UnsupportedFieldAttributeWarning', 

19 'TypedDictExtraConfigWarning', 

20) 

21 

22 

23class PydanticDeprecationWarning(DeprecationWarning): 

24 """A Pydantic specific deprecation warning. 

25 

26 This warning is raised when using deprecated functionality in Pydantic. It provides information on when the 

27 deprecation was introduced and the expected version in which the corresponding functionality will be removed. 

28 

29 Attributes: 

30 message: Description of the warning. 

31 since: Pydantic version in what the deprecation was introduced. 

32 expected_removal: Pydantic version in what the corresponding functionality expected to be removed. 

33 """ 

34 

35 message: str 

36 since: tuple[int, int] 

37 expected_removal: tuple[int, int] 

38 

39 def __init__( 

40 self, message: str, *args: object, since: tuple[int, int], expected_removal: tuple[int, int] | None = None 

41 ) -> None: 

42 super().__init__(message, *args) 

43 self.message = message.rstrip('.') 

44 self.since = since 

45 self.expected_removal = expected_removal if expected_removal is not None else (since[0] + 1, 0) 

46 

47 def __str__(self) -> str: 

48 message = ( 

49 f'{self.message}. Deprecated in Pydantic V{self.since[0]}.{self.since[1]}' 

50 f' to be removed in V{self.expected_removal[0]}.{self.expected_removal[1]}.' 

51 ) 

52 if self.since == (2, 0): 

53 message += f' See Pydantic V2 Migration Guide at https://errors.pydantic.dev/{version_short()}/migration/' 

54 return message 

55 

56 

57class PydanticDeprecatedSince20(PydanticDeprecationWarning): 

58 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.0.""" 

59 

60 def __init__(self, message: str, *args: object) -> None: 

61 super().__init__(message, *args, since=(2, 0), expected_removal=(3, 0)) 

62 

63 

64class PydanticDeprecatedSince26(PydanticDeprecationWarning): # pragma: no cover 

65 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.6.""" 

66 

67 def __init__(self, message: str, *args: object) -> None: 

68 super().__init__(message, *args, since=(2, 6), expected_removal=(3, 0)) 

69 

70 

71class PydanticDeprecatedSince29(PydanticDeprecationWarning): 

72 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.9.""" 

73 

74 def __init__(self, message: str, *args: object) -> None: 

75 super().__init__(message, *args, since=(2, 9), expected_removal=(3, 0)) 

76 

77 

78class PydanticDeprecatedSince210(PydanticDeprecationWarning): 

79 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.10.""" 

80 

81 def __init__(self, message: str, *args: object) -> None: 

82 super().__init__(message, *args, since=(2, 10), expected_removal=(3, 0)) 

83 

84 

85class PydanticDeprecatedSince211(PydanticDeprecationWarning): 

86 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.11.""" 

87 

88 def __init__(self, message: str, *args: object) -> None: 

89 super().__init__(message, *args, since=(2, 11), expected_removal=(3, 0)) 

90 

91 

92class PydanticDeprecatedSince212(PydanticDeprecationWarning): 

93 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.12.""" 

94 

95 def __init__(self, message: str, *args: object) -> None: 

96 super().__init__(message, *args, since=(2, 12), expected_removal=(3, 0)) 

97 

98 

99class PydanticDeprecatedSince214(PydanticDeprecationWarning): 

100 """A specific `PydanticDeprecationWarning` subclass defining functionality deprecated since Pydantic 2.14.""" 

101 

102 def __init__(self, message: str, *args: object) -> None: 

103 super().__init__(message, *args, since=(2, 14), expected_removal=(3, 0)) 

104 

105 

106class GenericBeforeBaseModelWarning(Warning): 

107 pass 

108 

109 

110class PydanticExperimentalWarning(Warning): 

111 """A Pydantic specific experimental functionality warning. 

112 

113 It is raised to warn users that the functionality may change or be removed in future versions of Pydantic. 

114 """ 

115 

116 

117class CoreSchemaGenerationWarning(UserWarning): 

118 """A warning raised during core schema generation.""" 

119 

120 

121class ArbitraryTypeWarning(CoreSchemaGenerationWarning): 

122 """A warning raised when Pydantic fails to generate a core schema for an arbitrary type.""" 

123 

124 

125class UnsupportedFieldAttributeWarning(CoreSchemaGenerationWarning): 

126 """A warning raised when a `Field()` attribute isn't supported in the context it is used.""" 

127 

128 

129class TypedDictExtraConfigWarning(CoreSchemaGenerationWarning): 

130 """A warning raised when the [`extra`][pydantic.ConfigDict.extra] configuration is incompatible with the `closed` or `extra_items` specification."""