From ad5f59ba49326e5a73c0c3e803aa4c8040c577c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Sun, 23 Sep 2018 14:40:49 +0200 Subject: [PATCH] configpaths: Add get_plugin_dirs() method This helps with mypy because otherwise get() has multiple return types This reduces our usage of cast() --- gajim/common/configpaths.py | 17 +++++++++-------- gajim/gtkexcepthook.py | 4 +--- gajim/plugins/pluginmanager.py | 2 +- gajim/plugins/plugins_i18n.py | 4 +--- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/gajim/common/configpaths.py b/gajim/common/configpaths.py index 0649d6f2a..77729cd92 100644 --- a/gajim/common/configpaths.py +++ b/gajim/common/configpaths.py @@ -24,7 +24,6 @@ from typing import List from typing import Generator from typing import Optional # pylint: disable=unused-import from typing import Tuple -from typing import Union import os import sys @@ -37,16 +36,18 @@ from gajim.common.const import PathType, PathLocation from gajim.common.types import PathTuple -def get(key: str) -> Union[str, List[str]]: - if key == 'PLUGINS_DIRS': - if gajim.IS_FLATPAK: - return ['/app/plugins', - _paths['PLUGINS_BASE']] - return [_paths['PLUGINS_BASE'], - _paths['PLUGINS_USER']] +def get(key: str) -> str: return _paths[key] +def get_plugin_dirs() -> List[str]: + if gajim.IS_FLATPAK: + return ['/app/plugins', + _paths['PLUGINS_BASE']] + return [_paths['PLUGINS_BASE'], + _paths['PLUGINS_USER']] + + def get_paths(type_: PathType) -> Generator[str, None, None]: for key, value in _paths.items(): path_type = value[2] diff --git a/gajim/gtkexcepthook.py b/gajim/gtkexcepthook.py index 5c8dd17f8..963717f39 100644 --- a/gajim/gtkexcepthook.py +++ b/gajim/gtkexcepthook.py @@ -17,8 +17,6 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see . -from typing import cast - import sys import os import traceback @@ -42,7 +40,7 @@ if __name__ == '__main__': glade_file = os.path.join('data', 'gui', 'exception_dialog.ui') else: from gajim.common import configpaths - gui_path = cast(str, configpaths.get('GUI')) + gui_path = configpaths.get('GUI') glade_file = os.path.join(gui_path, 'exception_dialog.ui') diff --git a/gajim/plugins/pluginmanager.py b/gajim/plugins/pluginmanager.py index 72941ca50..72bd1a5b4 100644 --- a/gajim/plugins/pluginmanager.py +++ b/gajim/plugins/pluginmanager.py @@ -107,7 +107,7 @@ class PluginManager(metaclass=Singleton): Registered names with instances of encryption Plugins. ''' - for path in reversed(configpaths.get('PLUGINS_DIRS')): + for path in reversed(configpaths.get_plugin_dirs()): pc = PluginManager.scan_dir_for_plugins(path) self.add_plugins(pc) diff --git a/gajim/plugins/plugins_i18n.py b/gajim/plugins/plugins_i18n.py index e962553e3..91d67d7f8 100644 --- a/gajim/plugins/plugins_i18n.py +++ b/gajim/plugins/plugins_i18n.py @@ -14,8 +14,6 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see . -from typing import cast - import os import locale import gettext @@ -23,7 +21,7 @@ import gettext from gajim.common import configpaths APP = 'gajim_plugins' -plugin_user_dir = cast(str, configpaths.get('PLUGINS_USER')) +plugin_user_dir = configpaths.get('PLUGINS_USER') plugins_locale_dir = os.path.join(plugin_user_dir, 'locale') if os.name != 'nt':