Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move getattr warning in deprecated BaseConfig #7183

Merged
merged 2 commits into from Nov 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions pydantic/deprecated/config.py
Expand Up @@ -18,10 +18,11 @@

class _ConfigMetaclass(type):
def __getattr__(self, item: str) -> Any:
warnings.warn(_config.DEPRECATION_MESSAGE, DeprecationWarning)

tlambert03 marked this conversation as resolved.
Show resolved Hide resolved
try:
return _config.config_defaults[item]
obj = _config.config_defaults[item]
warnings.warn(_config.DEPRECATION_MESSAGE, DeprecationWarning)
return obj
except KeyError as exc:
raise AttributeError(f"type object '{self.__name__}' has no attribute {exc}") from exc

Expand All @@ -35,9 +36,10 @@ class BaseConfig(metaclass=_ConfigMetaclass):
"""

def __getattr__(self, item: str) -> Any:
warnings.warn(_config.DEPRECATION_MESSAGE, DeprecationWarning)
try:
return super().__getattribute__(item)
obj = super().__getattribute__(item)
warnings.warn(_config.DEPRECATION_MESSAGE, DeprecationWarning)
return obj
except AttributeError as exc:
try:
return getattr(type(self), item)
Expand Down