Coverage for /pythoncovmergedfiles/medio/medio/src/pydantic/pydantic/deprecated/config.py: 63%
27 statements
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-27 07:38 +0000
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-27 07:38 +0000
1from __future__ import annotations as _annotations
3import warnings
4from typing import Any
6from typing_extensions import deprecated
8from .._internal import _config
10__all__ = ('BaseConfig',)
13class _ConfigMetaclass(type):
14 def __getattr__(self, item: str) -> Any:
15 warnings.warn(_config.DEPRECATION_MESSAGE, DeprecationWarning)
17 try:
18 return _config.config_defaults[item]
19 except KeyError as exc:
20 raise AttributeError(f"type object '{self.__name__}' has no attribute {exc}") from exc
23@deprecated('BaseConfig is deprecated. Use the `pydantic.ConfigDict` instead.')
24class BaseConfig(metaclass=_ConfigMetaclass):
25 """
26 This class is only retained for backwards compatibility.
28 The preferred approach going forward is to assign a ConfigDict to the `model_config` attribute of the Model class.
29 """
31 def __getattr__(self, item: str) -> Any:
32 warnings.warn(_config.DEPRECATION_MESSAGE, DeprecationWarning)
33 try:
34 return super().__getattribute__(item)
35 except AttributeError as exc:
36 try:
37 return getattr(type(self), item)
38 except AttributeError:
39 # re-raising changes the displayed text to reflect that `self` is not a type
40 raise AttributeError(str(exc)) from exc
42 def __init_subclass__(cls, **kwargs: Any) -> None:
43 warnings.warn(_config.DEPRECATION_MESSAGE, DeprecationWarning)
44 return super().__init_subclass__(**kwargs)