Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
__init__.py457 linesDownload Raw Back to pydantic
1from importlib import import_module2from typing import TYPE_CHECKING3from warnings import warn4 5from ._migration import getattr_migration6from .version import VERSION, _ensure_pydantic_core_version7 8_ensure_pydantic_core_version()9del _ensure_pydantic_core_version10 11if TYPE_CHECKING:12    # import of virtually everything is supported via `__getattr__` below,13    # but we need them here for type checking and IDE support14    import pydantic_core15    from pydantic_core.core_schema import (16        FieldSerializationInfo,17        SerializationInfo,18        SerializerFunctionWrapHandler,19        ValidationInfo,20        ValidatorFunctionWrapHandler,21    )22 23    from . import dataclasses24    from .aliases import AliasChoices, AliasGenerator, AliasPath25    from .annotated_handlers import GetCoreSchemaHandler, GetJsonSchemaHandler26    from .config import ConfigDict, with_config27    from .errors import *28    from .fields import Field, PrivateAttr, computed_field29    from .functional_serializers import (30        PlainSerializer,31        SerializeAsAny,32        WrapSerializer,33        field_serializer,34        model_serializer,35    )36    from .functional_validators import (37        AfterValidator,38        BeforeValidator,39        InstanceOf,40        ModelWrapValidatorHandler,41        PlainValidator,42        SkipValidation,43        ValidateAs,44        WrapValidator,45        field_validator,46        model_validator,47    )48    from .json_schema import WithJsonSchema49    from .main import *50    from .networks import *51    from .type_adapter import TypeAdapter52    from .types import *53    from .validate_call_decorator import validate_call54    from .warnings import (55        PydanticDeprecatedSince20,56        PydanticDeprecatedSince26,57        PydanticDeprecatedSince29,58        PydanticDeprecatedSince210,59        PydanticDeprecatedSince211,60        PydanticDeprecatedSince212,61        PydanticDeprecationWarning,62        PydanticExperimentalWarning,63    )64 65    # this encourages pycharm to import `ValidationError` from here, not pydantic_core66    ValidationError = pydantic_core.ValidationError67    from .deprecated.class_validators import root_validator, validator68    from .deprecated.config import BaseConfig, Extra69    from .deprecated.tools import *70    from .root_model import RootModel71 72__version__ = VERSION73__all__ = (74    # dataclasses75    'dataclasses',76    # functional validators77    'field_validator',78    'model_validator',79    'AfterValidator',80    'BeforeValidator',81    'PlainValidator',82    'WrapValidator',83    'SkipValidation',84    'ValidateAs',85    'InstanceOf',86    'ModelWrapValidatorHandler',87    # JSON Schema88    'WithJsonSchema',89    # deprecated V1 functional validators, these are imported via `__getattr__` below90    'root_validator',91    'validator',92    # functional serializers93    'field_serializer',94    'model_serializer',95    'PlainSerializer',96    'SerializeAsAny',97    'WrapSerializer',98    # config99    'ConfigDict',100    'with_config',101    # deprecated V1 config, these are imported via `__getattr__` below102    'BaseConfig',103    'Extra',104    # validate_call105    'validate_call',106    # errors107    'PydanticErrorCodes',108    'PydanticUserError',109    'PydanticSchemaGenerationError',110    'PydanticImportError',111    'PydanticUndefinedAnnotation',112    'PydanticInvalidForJsonSchema',113    'PydanticForbiddenQualifier',114    # fields115    'Field',116    'computed_field',117    'PrivateAttr',118    # alias119    'AliasChoices',120    'AliasGenerator',121    'AliasPath',122    # main123    'BaseModel',124    'create_model',125    # network126    'AnyUrl',127    'AnyHttpUrl',128    'FileUrl',129    'HttpUrl',130    'FtpUrl',131    'WebsocketUrl',132    'AnyWebsocketUrl',133    'UrlConstraints',134    'EmailStr',135    'NameEmail',136    'IPvAnyAddress',137    'IPvAnyInterface',138    'IPvAnyNetwork',139    'PostgresDsn',140    'CockroachDsn',141    'AmqpDsn',142    'RedisDsn',143    'MongoDsn',144    'KafkaDsn',145    'NatsDsn',146    'MySQLDsn',147    'MariaDBDsn',148    'ClickHouseDsn',149    'SnowflakeDsn',150    'validate_email',151    # root_model152    'RootModel',153    # deprecated tools, these are imported via `__getattr__` below154    'parse_obj_as',155    'schema_of',156    'schema_json_of',157    # types158    'Strict',159    'StrictStr',160    'conbytes',161    'conlist',162    'conset',163    'confrozenset',164    'constr',165    'StringConstraints',166    'ImportString',167    'conint',168    'PositiveInt',169    'NegativeInt',170    'NonNegativeInt',171    'NonPositiveInt',172    'confloat',173    'PositiveFloat',174    'NegativeFloat',175    'NonNegativeFloat',176    'NonPositiveFloat',177    'FiniteFloat',178    'condecimal',179    'condate',180    'UUID1',181    'UUID3',182    'UUID4',183    'UUID5',184    'UUID6',185    'UUID7',186    'UUID8',187    'FilePath',188    'DirectoryPath',189    'NewPath',190    'Json',191    'Secret',192    'SecretStr',193    'SecretBytes',194    'SocketPath',195    'StrictBool',196    'StrictBytes',197    'StrictInt',198    'StrictFloat',199    'PaymentCardNumber',200    'ByteSize',201    'PastDate',202    'FutureDate',203    'PastDatetime',204    'FutureDatetime',205    'AwareDatetime',206    'NaiveDatetime',207    'AllowInfNan',208    'EncoderProtocol',209    'EncodedBytes',210    'EncodedStr',211    'Base64Encoder',212    'Base64Bytes',213    'Base64Str',214    'Base64UrlBytes',215    'Base64UrlStr',216    'GetPydanticSchema',217    'Tag',218    'Discriminator',219    'JsonValue',220    'FailFast',221    # type_adapter222    'TypeAdapter',223    # version224    '__version__',225    'VERSION',226    # warnings227    'PydanticDeprecatedSince20',228    'PydanticDeprecatedSince26',229    'PydanticDeprecatedSince29',230    'PydanticDeprecatedSince210',231    'PydanticDeprecatedSince211',232    'PydanticDeprecatedSince212',233    'PydanticDeprecationWarning',234    'PydanticExperimentalWarning',235    # annotated handlers236    'GetCoreSchemaHandler',237    'GetJsonSchemaHandler',238    # pydantic_core239    'ValidationError',240    'ValidationInfo',241    'SerializationInfo',242    'ValidatorFunctionWrapHandler',243    'FieldSerializationInfo',244    'SerializerFunctionWrapHandler',245    'OnErrorOmit',246)247 248# A mapping of {<member name>: (package, <module name>)} defining dynamic imports249_dynamic_imports: 'dict[str, tuple[str, str]]' = {250    'dataclasses': (__spec__.parent, '__module__'),251    # functional validators252    'field_validator': (__spec__.parent, '.functional_validators'),253    'model_validator': (__spec__.parent, '.functional_validators'),254    'AfterValidator': (__spec__.parent, '.functional_validators'),255    'BeforeValidator': (__spec__.parent, '.functional_validators'),256    'PlainValidator': (__spec__.parent, '.functional_validators'),257    'WrapValidator': (__spec__.parent, '.functional_validators'),258    'SkipValidation': (__spec__.parent, '.functional_validators'),259    'InstanceOf': (__spec__.parent, '.functional_validators'),260    'ValidateAs': (__spec__.parent, '.functional_validators'),261    'ModelWrapValidatorHandler': (__spec__.parent, '.functional_validators'),262    # JSON Schema263    'WithJsonSchema': (__spec__.parent, '.json_schema'),264    # functional serializers265    'field_serializer': (__spec__.parent, '.functional_serializers'),266    'model_serializer': (__spec__.parent, '.functional_serializers'),267    'PlainSerializer': (__spec__.parent, '.functional_serializers'),268    'SerializeAsAny': (__spec__.parent, '.functional_serializers'),269    'WrapSerializer': (__spec__.parent, '.functional_serializers'),270    # config271    'ConfigDict': (__spec__.parent, '.config'),272    'with_config': (__spec__.parent, '.config'),273    # validate call274    'validate_call': (__spec__.parent, '.validate_call_decorator'),275    # errors276    'PydanticErrorCodes': (__spec__.parent, '.errors'),277    'PydanticUserError': (__spec__.parent, '.errors'),278    'PydanticSchemaGenerationError': (__spec__.parent, '.errors'),279    'PydanticImportError': (__spec__.parent, '.errors'),280    'PydanticUndefinedAnnotation': (__spec__.parent, '.errors'),281    'PydanticInvalidForJsonSchema': (__spec__.parent, '.errors'),282    'PydanticForbiddenQualifier': (__spec__.parent, '.errors'),283    # fields284    'Field': (__spec__.parent, '.fields'),285    'computed_field': (__spec__.parent, '.fields'),286    'PrivateAttr': (__spec__.parent, '.fields'),287    # alias288    'AliasChoices': (__spec__.parent, '.aliases'),289    'AliasGenerator': (__spec__.parent, '.aliases'),290    'AliasPath': (__spec__.parent, '.aliases'),291    # main292    'BaseModel': (__spec__.parent, '.main'),293    'create_model': (__spec__.parent, '.main'),294    # network295    'AnyUrl': (__spec__.parent, '.networks'),296    'AnyHttpUrl': (__spec__.parent, '.networks'),297    'FileUrl': (__spec__.parent, '.networks'),298    'HttpUrl': (__spec__.parent, '.networks'),299    'FtpUrl': (__spec__.parent, '.networks'),300    'WebsocketUrl': (__spec__.parent, '.networks'),301    'AnyWebsocketUrl': (__spec__.parent, '.networks'),302    'UrlConstraints': (__spec__.parent, '.networks'),303    'EmailStr': (__spec__.parent, '.networks'),304    'NameEmail': (__spec__.parent, '.networks'),305    'IPvAnyAddress': (__spec__.parent, '.networks'),306    'IPvAnyInterface': (__spec__.parent, '.networks'),307    'IPvAnyNetwork': (__spec__.parent, '.networks'),308    'PostgresDsn': (__spec__.parent, '.networks'),309    'CockroachDsn': (__spec__.parent, '.networks'),310    'AmqpDsn': (__spec__.parent, '.networks'),311    'RedisDsn': (__spec__.parent, '.networks'),312    'MongoDsn': (__spec__.parent, '.networks'),313    'KafkaDsn': (__spec__.parent, '.networks'),314    'NatsDsn': (__spec__.parent, '.networks'),315    'MySQLDsn': (__spec__.parent, '.networks'),316    'MariaDBDsn': (__spec__.parent, '.networks'),317    'ClickHouseDsn': (__spec__.parent, '.networks'),318    'SnowflakeDsn': (__spec__.parent, '.networks'),319    'validate_email': (__spec__.parent, '.networks'),320    # root_model321    'RootModel': (__spec__.parent, '.root_model'),322    # types323    'Strict': (__spec__.parent, '.types'),324    'StrictStr': (__spec__.parent, '.types'),325    'conbytes': (__spec__.parent, '.types'),326    'conlist': (__spec__.parent, '.types'),327    'conset': (__spec__.parent, '.types'),328    'confrozenset': (__spec__.parent, '.types'),329    'constr': (__spec__.parent, '.types'),330    'StringConstraints': (__spec__.parent, '.types'),331    'ImportString': (__spec__.parent, '.types'),332    'conint': (__spec__.parent, '.types'),333    'PositiveInt': (__spec__.parent, '.types'),334    'NegativeInt': (__spec__.parent, '.types'),335    'NonNegativeInt': (__spec__.parent, '.types'),336    'NonPositiveInt': (__spec__.parent, '.types'),337    'confloat': (__spec__.parent, '.types'),338    'PositiveFloat': (__spec__.parent, '.types'),339    'NegativeFloat': (__spec__.parent, '.types'),340    'NonNegativeFloat': (__spec__.parent, '.types'),341    'NonPositiveFloat': (__spec__.parent, '.types'),342    'FiniteFloat': (__spec__.parent, '.types'),343    'condecimal': (__spec__.parent, '.types'),344    'condate': (__spec__.parent, '.types'),345    'UUID1': (__spec__.parent, '.types'),346    'UUID3': (__spec__.parent, '.types'),347    'UUID4': (__spec__.parent, '.types'),348    'UUID5': (__spec__.parent, '.types'),349    'UUID6': (__spec__.parent, '.types'),350    'UUID7': (__spec__.parent, '.types'),351    'UUID8': (__spec__.parent, '.types'),352    'FilePath': (__spec__.parent, '.types'),353    'DirectoryPath': (__spec__.parent, '.types'),354    'NewPath': (__spec__.parent, '.types'),355    'Json': (__spec__.parent, '.types'),356    'Secret': (__spec__.parent, '.types'),357    'SecretStr': (__spec__.parent, '.types'),358    'SecretBytes': (__spec__.parent, '.types'),359    'StrictBool': (__spec__.parent, '.types'),360    'StrictBytes': (__spec__.parent, '.types'),361    'StrictInt': (__spec__.parent, '.types'),362    'StrictFloat': (__spec__.parent, '.types'),363    'PaymentCardNumber': (__spec__.parent, '.types'),364    'ByteSize': (__spec__.parent, '.types'),365    'PastDate': (__spec__.parent, '.types'),366    'SocketPath': (__spec__.parent, '.types'),367    'FutureDate': (__spec__.parent, '.types'),368    'PastDatetime': (__spec__.parent, '.types'),369    'FutureDatetime': (__spec__.parent, '.types'),370    'AwareDatetime': (__spec__.parent, '.types'),371    'NaiveDatetime': (__spec__.parent, '.types'),372    'AllowInfNan': (__spec__.parent, '.types'),373    'EncoderProtocol': (__spec__.parent, '.types'),374    'EncodedBytes': (__spec__.parent, '.types'),375    'EncodedStr': (__spec__.parent, '.types'),376    'Base64Encoder': (__spec__.parent, '.types'),377    'Base64Bytes': (__spec__.parent, '.types'),378    'Base64Str': (__spec__.parent, '.types'),379    'Base64UrlBytes': (__spec__.parent, '.types'),380    'Base64UrlStr': (__spec__.parent, '.types'),381    'GetPydanticSchema': (__spec__.parent, '.types'),382    'Tag': (__spec__.parent, '.types'),383    'Discriminator': (__spec__.parent, '.types'),384    'JsonValue': (__spec__.parent, '.types'),385    'OnErrorOmit': (__spec__.parent, '.types'),386    'FailFast': (__spec__.parent, '.types'),387    # type_adapter388    'TypeAdapter': (__spec__.parent, '.type_adapter'),389    # warnings390    'PydanticDeprecatedSince20': (__spec__.parent, '.warnings'),391    'PydanticDeprecatedSince26': (__spec__.parent, '.warnings'),392    'PydanticDeprecatedSince29': (__spec__.parent, '.warnings'),393    'PydanticDeprecatedSince210': (__spec__.parent, '.warnings'),394    'PydanticDeprecatedSince211': (__spec__.parent, '.warnings'),395    'PydanticDeprecatedSince212': (__spec__.parent, '.warnings'),396    'PydanticDeprecationWarning': (__spec__.parent, '.warnings'),397    'PydanticExperimentalWarning': (__spec__.parent, '.warnings'),398    # annotated handlers399    'GetCoreSchemaHandler': (__spec__.parent, '.annotated_handlers'),400    'GetJsonSchemaHandler': (__spec__.parent, '.annotated_handlers'),401    # pydantic_core stuff402    'ValidationError': ('pydantic_core', '.'),403    'ValidationInfo': ('pydantic_core', '.core_schema'),404    'SerializationInfo': ('pydantic_core', '.core_schema'),405    'ValidatorFunctionWrapHandler': ('pydantic_core', '.core_schema'),406    'FieldSerializationInfo': ('pydantic_core', '.core_schema'),407    'SerializerFunctionWrapHandler': ('pydantic_core', '.core_schema'),408    # deprecated, mostly not included in __all__409    'root_validator': (__spec__.parent, '.deprecated.class_validators'),410    'validator': (__spec__.parent, '.deprecated.class_validators'),411    'BaseConfig': (__spec__.parent, '.deprecated.config'),412    'Extra': (__spec__.parent, '.deprecated.config'),413    'parse_obj_as': (__spec__.parent, '.deprecated.tools'),414    'schema_of': (__spec__.parent, '.deprecated.tools'),415    'schema_json_of': (__spec__.parent, '.deprecated.tools'),416    # deprecated dynamic imports417    'FieldValidationInfo': ('pydantic_core', '.core_schema'),418    'GenerateSchema': (__spec__.parent, '._internal._generate_schema'),419}420_deprecated_dynamic_imports = {'FieldValidationInfo', 'GenerateSchema'}421 422_getattr_migration = getattr_migration(__name__)423 424 425def __getattr__(attr_name: str) -> object:426    if attr_name in _deprecated_dynamic_imports:427        from pydantic.warnings import PydanticDeprecatedSince20428 429        warn(430            f'Importing {attr_name} from `pydantic` is deprecated. This feature is either no longer supported, or is not public.',431            PydanticDeprecatedSince20,432            stacklevel=2,433        )434 435    dynamic_attr = _dynamic_imports.get(attr_name)436    if dynamic_attr is None:437        return _getattr_migration(attr_name)438 439    package, module_name = dynamic_attr440 441    if module_name == '__module__':442        result = import_module(f'.{attr_name}', package=package)443        globals()[attr_name] = result444        return result445    else:446        module = import_module(module_name, package=package)447        result = getattr(module, attr_name)448        g = globals()449        for k, (_, v_module_name) in _dynamic_imports.items():450            if v_module_name == module_name and k not in _deprecated_dynamic_imports:451                g[k] = getattr(module, k)452        return result453 454 455def __dir__() -> list[str]:456    return list(__all__)457 
codekingpro/portable-devtools · Team Ai