Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
config.py73 linesDownload Raw Back to deprecated
1from __future__ import annotations as _annotations2 3import warnings4from typing import TYPE_CHECKING, Any, Literal5 6from typing_extensions import deprecated7 8from .._internal import _config9from ..warnings import PydanticDeprecatedSince2010 11if not TYPE_CHECKING:12    # See PyCharm issues https://youtrack.jetbrains.com/issue/PY-2191513    # and https://youtrack.jetbrains.com/issue/PY-5142814    DeprecationWarning = PydanticDeprecatedSince2015 16__all__ = 'BaseConfig', 'Extra'17 18 19class _ConfigMetaclass(type):20    def __getattr__(self, item: str) -> Any:21        try:22            obj = _config.config_defaults[item]23            warnings.warn(_config.DEPRECATION_MESSAGE, DeprecationWarning)24            return obj25        except KeyError as exc:26            raise AttributeError(f"type object '{self.__name__}' has no attribute {exc}") from exc27 28 29@deprecated('BaseConfig is deprecated. Use the `pydantic.ConfigDict` instead.', category=PydanticDeprecatedSince20)30class BaseConfig(metaclass=_ConfigMetaclass):31    """This class is only retained for backwards compatibility.32 33    !!! Warning "Deprecated"34        BaseConfig is deprecated. Use the [`pydantic.ConfigDict`][pydantic.ConfigDict] instead.35    """36 37    def __getattr__(self, item: str) -> Any:38        try:39            obj = super().__getattribute__(item)40            warnings.warn(_config.DEPRECATION_MESSAGE, DeprecationWarning)41            return obj42        except AttributeError as exc:43            try:44                return getattr(type(self), item)45            except AttributeError:46                # re-raising changes the displayed text to reflect that `self` is not a type47                raise AttributeError(str(exc)) from exc48 49    def __init_subclass__(cls, **kwargs: Any) -> None:50        warnings.warn(_config.DEPRECATION_MESSAGE, DeprecationWarning)51        return super().__init_subclass__(**kwargs)52 53 54class _ExtraMeta(type):55    def __getattribute__(self, __name: str) -> Any:56        # The @deprecated decorator accesses other attributes, so we only emit a warning for the expected ones57        if __name in {'allow', 'ignore', 'forbid'}:58            warnings.warn(59                "`pydantic.config.Extra` is deprecated, use literal values instead (e.g. `extra='allow'`)",60                DeprecationWarning,61                stacklevel=2,62            )63        return super().__getattribute__(__name)64 65 66@deprecated(67    "Extra is deprecated. Use literal values instead (e.g. `extra='allow'`)", category=PydanticDeprecatedSince2068)69class Extra(metaclass=_ExtraMeta):70    allow: Literal['allow'] = 'allow'71    ignore: Literal['ignore'] = 'ignore'72    forbid: Literal['forbid'] = 'forbid'73 
codekingpro/portable-devtools · Team Ai