From 3f84c3768af16993c01300a049da4aecefec700c Mon Sep 17 00:00:00 2001 From: hadrianl <137150224@qq.com> Date: Thu, 17 Dec 2020 09:47:25 +0800 Subject: [PATCH] Make __getattr__ to raise AttributeError instead of return it.Avoid using try except. --- qlib/config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/qlib/config.py b/qlib/config.py index 869ea99c9..c213df9c4 100644 --- a/qlib/config.py +++ b/qlib/config.py @@ -27,10 +27,10 @@ class Config: return self.__dict__["_config"][key] def __getattr__(self, attr): - try: + if attr in self.__dict__["_config"]: return self.__dict__["_config"][attr] - except KeyError: - return AttributeError(f"No such {attr} in self._config") + + raise AttributeError(f"No such {attr} in self._config") def __setitem__(self, key, value): self.__dict__["_config"][key] = value