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