aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Holland <samuel@sholland.org>2018-05-10 15:50:17 -0500
committerTrygve Aaberge <trygveaa@gmail.com>2019-04-08 15:11:57 +0200
commite72b83b240fc37abe369f9a800718ba89ad06d87 (patch)
tree16fac33dcbdf504b322cf3258092e5856eb5a06c
parentdc3c25d13f9bb150bd22e367f8416113cb57f295 (diff)
downloadwee-slack-e72b83b240fc37abe369f9a800718ba89ad06d87.tar.gz
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().
-rw-r--r--wee_slack.py17
1 files 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))