Coverage for pydantic/__init__.py: 91.30%
19 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
1import typing 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
3from ._migration import getattr_migration 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
4from .version import VERSION 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
6if typing.TYPE_CHECKING: 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
7 # import of virtually everything is supported via `__getattr__` below,
8 # but we need them here for type checking and IDE support
9 import pydantic_core
10 from pydantic_core.core_schema import (
11 FieldSerializationInfo,
12 SerializationInfo,
13 SerializerFunctionWrapHandler,
14 ValidationInfo,
15 ValidatorFunctionWrapHandler,
16 )
18 from . import dataclasses
19 from ._internal._generate_schema import GenerateSchema as GenerateSchema
20 from .aliases import AliasChoices, AliasGenerator, AliasPath
21 from .annotated_handlers import GetCoreSchemaHandler, GetJsonSchemaHandler
22 from .config import ConfigDict, with_config
23 from .errors import *
24 from .fields import Field, PrivateAttr, computed_field
25 from .functional_serializers import (
26 PlainSerializer,
27 SerializeAsAny,
28 WrapSerializer,
29 field_serializer,
30 model_serializer,
31 )
32 from .functional_validators import (
33 AfterValidator,
34 BeforeValidator,
35 InstanceOf,
36 PlainValidator,
37 SkipValidation,
38 WrapValidator,
39 field_validator,
40 model_validator,
41 )
42 from .json_schema import WithJsonSchema
43 from .main import *
44 from .networks import *
45 from .type_adapter import TypeAdapter
46 from .types import *
47 from .validate_call_decorator import validate_call
48 from .warnings import (
49 PydanticDeprecatedSince20,
50 PydanticDeprecatedSince26,
51 PydanticDeprecationWarning,
52 PydanticExperimentalWarning,
53 )
55 # this encourages pycharm to import `ValidationError` from here, not pydantic_core
56 ValidationError = pydantic_core.ValidationError
57 from .deprecated.class_validators import root_validator, validator
58 from .deprecated.config import BaseConfig, Extra
59 from .deprecated.tools import *
60 from .root_model import RootModel
62__version__ = VERSION 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
63__all__ = ( 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
64 # dataclasses
65 'dataclasses',
66 # functional validators
67 'field_validator',
68 'model_validator',
69 'AfterValidator',
70 'BeforeValidator',
71 'PlainValidator',
72 'WrapValidator',
73 'SkipValidation',
74 'InstanceOf',
75 # JSON Schema
76 'WithJsonSchema',
77 # deprecated V1 functional validators, these are imported via `__getattr__` below
78 'root_validator',
79 'validator',
80 # functional serializers
81 'field_serializer',
82 'model_serializer',
83 'PlainSerializer',
84 'SerializeAsAny',
85 'WrapSerializer',
86 # config
87 'ConfigDict',
88 'with_config',
89 # deprecated V1 config, these are imported via `__getattr__` below
90 'BaseConfig',
91 'Extra',
92 # validate_call
93 'validate_call',
94 # errors
95 'PydanticErrorCodes',
96 'PydanticUserError',
97 'PydanticSchemaGenerationError',
98 'PydanticImportError',
99 'PydanticUndefinedAnnotation',
100 'PydanticInvalidForJsonSchema',
101 # fields
102 'Field',
103 'computed_field',
104 'PrivateAttr',
105 # alias
106 'AliasChoices',
107 'AliasGenerator',
108 'AliasPath',
109 # main
110 'BaseModel',
111 'create_model',
112 # network
113 'AnyUrl',
114 'AnyHttpUrl',
115 'FileUrl',
116 'HttpUrl',
117 'FtpUrl',
118 'WebsocketUrl',
119 'AnyWebsocketUrl',
120 'UrlConstraints',
121 'EmailStr',
122 'NameEmail',
123 'IPvAnyAddress',
124 'IPvAnyInterface',
125 'IPvAnyNetwork',
126 'PostgresDsn',
127 'CockroachDsn',
128 'AmqpDsn',
129 'RedisDsn',
130 'MongoDsn',
131 'KafkaDsn',
132 'NatsDsn',
133 'MySQLDsn',
134 'MariaDBDsn',
135 'ClickHouseDsn',
136 'validate_email',
137 # root_model
138 'RootModel',
139 # deprecated tools, these are imported via `__getattr__` below
140 'parse_obj_as',
141 'schema_of',
142 'schema_json_of',
143 # types
144 'Strict',
145 'StrictStr',
146 'conbytes',
147 'conlist',
148 'conset',
149 'confrozenset',
150 'constr',
151 'StringConstraints',
152 'ImportString',
153 'conint',
154 'PositiveInt',
155 'NegativeInt',
156 'NonNegativeInt',
157 'NonPositiveInt',
158 'confloat',
159 'PositiveFloat',
160 'NegativeFloat',
161 'NonNegativeFloat',
162 'NonPositiveFloat',
163 'FiniteFloat',
164 'condecimal',
165 'condate',
166 'UUID1',
167 'UUID3',
168 'UUID4',
169 'UUID5',
170 'FilePath',
171 'DirectoryPath',
172 'NewPath',
173 'Json',
174 'Secret',
175 'SecretStr',
176 'SecretBytes',
177 'StrictBool',
178 'StrictBytes',
179 'StrictInt',
180 'StrictFloat',
181 'PaymentCardNumber',
182 'ByteSize',
183 'PastDate',
184 'FutureDate',
185 'PastDatetime',
186 'FutureDatetime',
187 'AwareDatetime',
188 'NaiveDatetime',
189 'AllowInfNan',
190 'EncoderProtocol',
191 'EncodedBytes',
192 'EncodedStr',
193 'Base64Encoder',
194 'Base64Bytes',
195 'Base64Str',
196 'Base64UrlBytes',
197 'Base64UrlStr',
198 'GetPydanticSchema',
199 'Tag',
200 'Discriminator',
201 'JsonValue',
202 # type_adapter
203 'TypeAdapter',
204 # version
205 '__version__',
206 'VERSION',
207 # warnings
208 'PydanticDeprecatedSince20',
209 'PydanticDeprecatedSince26',
210 'PydanticDeprecationWarning',
211 'PydanticExperimentalWarning',
212 # annotated handlers
213 'GetCoreSchemaHandler',
214 'GetJsonSchemaHandler',
215 # generate schema from ._internal
216 'GenerateSchema',
217 # pydantic_core
218 'ValidationError',
219 'ValidationInfo',
220 'SerializationInfo',
221 'ValidatorFunctionWrapHandler',
222 'FieldSerializationInfo',
223 'SerializerFunctionWrapHandler',
224 'OnErrorOmit',
225)
227# A mapping of {<member name>: (package, <module name>)} defining dynamic imports
228_dynamic_imports: 'dict[str, tuple[str, str]]' = { 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
229 'dataclasses': (__spec__.parent, '__module__'),
230 # functional validators
231 'field_validator': (__spec__.parent, '.functional_validators'),
232 'model_validator': (__spec__.parent, '.functional_validators'),
233 'AfterValidator': (__spec__.parent, '.functional_validators'),
234 'BeforeValidator': (__spec__.parent, '.functional_validators'),
235 'PlainValidator': (__spec__.parent, '.functional_validators'),
236 'WrapValidator': (__spec__.parent, '.functional_validators'),
237 'SkipValidation': (__spec__.parent, '.functional_validators'),
238 'InstanceOf': (__spec__.parent, '.functional_validators'),
239 # JSON Schema
240 'WithJsonSchema': (__spec__.parent, '.json_schema'),
241 # functional serializers
242 'field_serializer': (__spec__.parent, '.functional_serializers'),
243 'model_serializer': (__spec__.parent, '.functional_serializers'),
244 'PlainSerializer': (__spec__.parent, '.functional_serializers'),
245 'SerializeAsAny': (__spec__.parent, '.functional_serializers'),
246 'WrapSerializer': (__spec__.parent, '.functional_serializers'),
247 # config
248 'ConfigDict': (__spec__.parent, '.config'),
249 'with_config': (__spec__.parent, '.config'),
250 # validate call
251 'validate_call': (__spec__.parent, '.validate_call_decorator'),
252 # errors
253 'PydanticErrorCodes': (__spec__.parent, '.errors'),
254 'PydanticUserError': (__spec__.parent, '.errors'),
255 'PydanticSchemaGenerationError': (__spec__.parent, '.errors'),
256 'PydanticImportError': (__spec__.parent, '.errors'),
257 'PydanticUndefinedAnnotation': (__spec__.parent, '.errors'),
258 'PydanticInvalidForJsonSchema': (__spec__.parent, '.errors'),
259 # fields
260 'Field': (__spec__.parent, '.fields'),
261 'computed_field': (__spec__.parent, '.fields'),
262 'PrivateAttr': (__spec__.parent, '.fields'),
263 # alias
264 'AliasChoices': (__spec__.parent, '.aliases'),
265 'AliasGenerator': (__spec__.parent, '.aliases'),
266 'AliasPath': (__spec__.parent, '.aliases'),
267 # main
268 'BaseModel': (__spec__.parent, '.main'),
269 'create_model': (__spec__.parent, '.main'),
270 # network
271 'AnyUrl': (__spec__.parent, '.networks'),
272 'AnyHttpUrl': (__spec__.parent, '.networks'),
273 'FileUrl': (__spec__.parent, '.networks'),
274 'HttpUrl': (__spec__.parent, '.networks'),
275 'FtpUrl': (__spec__.parent, '.networks'),
276 'WebsocketUrl': (__spec__.parent, '.networks'),
277 'AnyWebsocketUrl': (__spec__.parent, '.networks'),
278 'UrlConstraints': (__spec__.parent, '.networks'),
279 'EmailStr': (__spec__.parent, '.networks'),
280 'NameEmail': (__spec__.parent, '.networks'),
281 'IPvAnyAddress': (__spec__.parent, '.networks'),
282 'IPvAnyInterface': (__spec__.parent, '.networks'),
283 'IPvAnyNetwork': (__spec__.parent, '.networks'),
284 'PostgresDsn': (__spec__.parent, '.networks'),
285 'CockroachDsn': (__spec__.parent, '.networks'),
286 'AmqpDsn': (__spec__.parent, '.networks'),
287 'RedisDsn': (__spec__.parent, '.networks'),
288 'MongoDsn': (__spec__.parent, '.networks'),
289 'KafkaDsn': (__spec__.parent, '.networks'),
290 'NatsDsn': (__spec__.parent, '.networks'),
291 'MySQLDsn': (__spec__.parent, '.networks'),
292 'MariaDBDsn': (__spec__.parent, '.networks'),
293 'ClickHouseDsn': (__spec__.parent, '.networks'),
294 'validate_email': (__spec__.parent, '.networks'),
295 # root_model
296 'RootModel': (__spec__.parent, '.root_model'),
297 # types
298 'Strict': (__spec__.parent, '.types'),
299 'StrictStr': (__spec__.parent, '.types'),
300 'conbytes': (__spec__.parent, '.types'),
301 'conlist': (__spec__.parent, '.types'),
302 'conset': (__spec__.parent, '.types'),
303 'confrozenset': (__spec__.parent, '.types'),
304 'constr': (__spec__.parent, '.types'),
305 'StringConstraints': (__spec__.parent, '.types'),
306 'ImportString': (__spec__.parent, '.types'),
307 'conint': (__spec__.parent, '.types'),
308 'PositiveInt': (__spec__.parent, '.types'),
309 'NegativeInt': (__spec__.parent, '.types'),
310 'NonNegativeInt': (__spec__.parent, '.types'),
311 'NonPositiveInt': (__spec__.parent, '.types'),
312 'confloat': (__spec__.parent, '.types'),
313 'PositiveFloat': (__spec__.parent, '.types'),
314 'NegativeFloat': (__spec__.parent, '.types'),
315 'NonNegativeFloat': (__spec__.parent, '.types'),
316 'NonPositiveFloat': (__spec__.parent, '.types'),
317 'FiniteFloat': (__spec__.parent, '.types'),
318 'condecimal': (__spec__.parent, '.types'),
319 'condate': (__spec__.parent, '.types'),
320 'UUID1': (__spec__.parent, '.types'),
321 'UUID3': (__spec__.parent, '.types'),
322 'UUID4': (__spec__.parent, '.types'),
323 'UUID5': (__spec__.parent, '.types'),
324 'FilePath': (__spec__.parent, '.types'),
325 'DirectoryPath': (__spec__.parent, '.types'),
326 'NewPath': (__spec__.parent, '.types'),
327 'Json': (__spec__.parent, '.types'),
328 'Secret': (__spec__.parent, '.types'),
329 'SecretStr': (__spec__.parent, '.types'),
330 'SecretBytes': (__spec__.parent, '.types'),
331 'StrictBool': (__spec__.parent, '.types'),
332 'StrictBytes': (__spec__.parent, '.types'),
333 'StrictInt': (__spec__.parent, '.types'),
334 'StrictFloat': (__spec__.parent, '.types'),
335 'PaymentCardNumber': (__spec__.parent, '.types'),
336 'ByteSize': (__spec__.parent, '.types'),
337 'PastDate': (__spec__.parent, '.types'),
338 'FutureDate': (__spec__.parent, '.types'),
339 'PastDatetime': (__spec__.parent, '.types'),
340 'FutureDatetime': (__spec__.parent, '.types'),
341 'AwareDatetime': (__spec__.parent, '.types'),
342 'NaiveDatetime': (__spec__.parent, '.types'),
343 'AllowInfNan': (__spec__.parent, '.types'),
344 'EncoderProtocol': (__spec__.parent, '.types'),
345 'EncodedBytes': (__spec__.parent, '.types'),
346 'EncodedStr': (__spec__.parent, '.types'),
347 'Base64Encoder': (__spec__.parent, '.types'),
348 'Base64Bytes': (__spec__.parent, '.types'),
349 'Base64Str': (__spec__.parent, '.types'),
350 'Base64UrlBytes': (__spec__.parent, '.types'),
351 'Base64UrlStr': (__spec__.parent, '.types'),
352 'GetPydanticSchema': (__spec__.parent, '.types'),
353 'Tag': (__spec__.parent, '.types'),
354 'Discriminator': (__spec__.parent, '.types'),
355 'JsonValue': (__spec__.parent, '.types'),
356 'OnErrorOmit': (__spec__.parent, '.types'),
357 # type_adapter
358 'TypeAdapter': (__spec__.parent, '.type_adapter'),
359 # warnings
360 'PydanticDeprecatedSince20': (__spec__.parent, '.warnings'),
361 'PydanticDeprecatedSince26': (__spec__.parent, '.warnings'),
362 'PydanticDeprecationWarning': (__spec__.parent, '.warnings'),
363 'PydanticExperimentalWarning': (__spec__.parent, '.warnings'),
364 # annotated handlers
365 'GetCoreSchemaHandler': (__spec__.parent, '.annotated_handlers'),
366 'GetJsonSchemaHandler': (__spec__.parent, '.annotated_handlers'),
367 # generate schema from ._internal
368 'GenerateSchema': (__spec__.parent, '._internal._generate_schema'),
369 # pydantic_core stuff
370 'ValidationError': ('pydantic_core', '.'),
371 'ValidationInfo': ('pydantic_core', '.core_schema'),
372 'SerializationInfo': ('pydantic_core', '.core_schema'),
373 'ValidatorFunctionWrapHandler': ('pydantic_core', '.core_schema'),
374 'FieldSerializationInfo': ('pydantic_core', '.core_schema'),
375 'SerializerFunctionWrapHandler': ('pydantic_core', '.core_schema'),
376 # deprecated, mostly not included in __all__
377 'root_validator': (__spec__.parent, '.deprecated.class_validators'),
378 'validator': (__spec__.parent, '.deprecated.class_validators'),
379 'BaseConfig': (__spec__.parent, '.deprecated.config'),
380 'Extra': (__spec__.parent, '.deprecated.config'),
381 'parse_obj_as': (__spec__.parent, '.deprecated.tools'),
382 'schema_of': (__spec__.parent, '.deprecated.tools'),
383 'schema_json_of': (__spec__.parent, '.deprecated.tools'),
384 'FieldValidationInfo': ('pydantic_core', '.core_schema'),
385}
387_getattr_migration = getattr_migration(__name__) 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
390def __getattr__(attr_name: str) -> object: 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
391 dynamic_attr = _dynamic_imports.get(attr_name) 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
392 if dynamic_attr is None: 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
393 return _getattr_migration(attr_name) 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
395 package, module_name = dynamic_attr 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
397 from importlib import import_module 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
399 if module_name == '__module__': 399 ↛ 400line 399 didn't jump to line 400, because the condition on line 399 was never true1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
400 return import_module(f'.{attr_name}', package=package)
401 else:
402 module = import_module(module_name, package=package) 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
403 return getattr(module, attr_name) 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
406def __dir__() -> 'list[str]': 1abcdefghijklmnopqrstuvGHIJKLMNOwxyzABCDEF
407 return list(__all__) 1abcdefghijklmnopqrstuvwxyzABCDEF