Skip to content

Commit

Permalink
Fix: move getattr warning in deprecated BaseConfig (#7183)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Hall <alex.mojaki@gmail.com>
  • Loading branch information
tlambert03 and alexmojaki committed Nov 13, 2023
1 parent d465ec5 commit d6140fa
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pydantic/deprecated/config.py
Expand Up @@ -18,10 +18,10 @@

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

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 +35,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

0 comments on commit d6140fa

Please sign in to comment.