From e72b83b240fc37abe369f9a800718ba89ad06d87 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Thu, 10 May 2018 15:50:17 -0500 Subject: Make PluginConfig getattr compatible with Python 3 __getattr__ is expected to raise AttributeError, not KeyError. The removal of the call to hasattr() also speeds up fetch_setting(). --- wee_slack.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/wee_slack.py b/wee_slack.py index 66f1c22..33aa919 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4391,17 +4391,20 @@ class PluginConfig(object): return w.WEECHAT_RC_OK def fetch_setting(self, key): - if hasattr(self, 'get_' + key): - try: - return getattr(self, 'get_' + key)(key) - except: - return self.settings[key] - else: + try: + return getattr(self, 'get_' + key)(key) + except AttributeError: # Most settings are on/off, so make get_boolean the default return self.get_boolean(key) + except: + # There was setting-specific getter, but it failed. + return self.settings[key] def __getattr__(self, key): - return self.settings[key] + try: + return self.settings[key] + except KeyError: + raise AttributeError(key) def get_boolean(self, key): return w.config_string_to_boolean(w.config_get_plugin(key)) -- cgit