diff options
author | Philippe Pepiot <philippe.pepiot@logilab.fr> | 2019-09-12 16:25:16 +0200 |
---|---|---|
committer | Philippe Pepiot <philippe.pepiot@logilab.fr> | 2019-09-12 16:25:16 +0200 |
commit | bd0b147cea7f916a3ceffcba11b15429a31d4264 (patch) | |
tree | 2f4719bb8529f0270f07918a7496edfe1cf622c6 | |
parent | 43fa2a92f8d8538a75ebbc56196ae8c068837211 (diff) | |
download | logilab-common-bd0b147cea7f916a3ceffcba11b15429a31d4264.tar.gz |
Make "configuration" classes get call __getitem__
In both ConfigurationMixIn and OptionsManager2ConfigurationAdapter.
Otherwise a child-class defining it's own __getitem__ wouldn't be called.
In ConfigurationMixIn.get, also catch for OptionError like before.
We could think about caching OptionError in __getitem__ but there's test
asserting this method can raise OptionError, so...
-rw-r--r-- | logilab/common/configuration.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/logilab/common/configuration.py b/logilab/common/configuration.py index 1137332..7f4299c 100644 --- a/logilab/common/configuration.py +++ b/logilab/common/configuration.py @@ -970,8 +970,8 @@ class ConfigurationMixIn(OptionsManagerMixIn, OptionsProviderMixIn): def get(self, key, default=None): try: - return getattr(self.config, self.option_attrname(key)) - except (OptionError, AttributeError): + return self[key] + except (OptionError, KeyError): return default @@ -1014,10 +1014,9 @@ class OptionsManager2ConfigurationAdapter(object): self.config.global_set_option(self.config.option_attrname(key), value) def get(self, key, default=None): - provider = self.config._all_options[key] try: - return getattr(provider.config, provider.option_attrname(key)) - except AttributeError: + return self[key] + except KeyError: return default # other functions ############################################################## |