From ea249da3b3e072da2bc381d5763b5922b3b40382 Mon Sep 17 00:00:00 2001 From: Eberhard Beilharz Date: Mon, 28 Aug 2023 19:24:48 +0200 Subject: [PATCH] refactor(linux): Fix warning Follow-up of #4999 (which mentions different warnings). This change fixes other warnings that we were still getting. --- .../keyman-config/keyman_config/dconf_util.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/linux/keyman-config/keyman_config/dconf_util.py b/linux/keyman-config/keyman_config/dconf_util.py index a2775a45e1..953680209e 100644 --- a/linux/keyman-config/keyman_config/dconf_util.py +++ b/linux/keyman-config/keyman_config/dconf_util.py @@ -3,19 +3,22 @@ from gi.repository import Gio # GSettings path destkop/ibus/keyman/options -GSETTINGS_BASE = "com.keyman.options" +GSETTINGS_BASE = 'com.keyman.options' # Utilities to get and set Keyman options in GSettings: # /desktop/ibus/keyman/options/packageID/keyboardID/options def get_child_schema(info): + if 'packageID' not in info or 'keyboardID' not in info or not info['packageID'] or not info['keyboardID']: + return None + settings = Gio.Settings.new(GSETTINGS_BASE) path = settings.get_property('path') if not path.endswith('/'): path += '/' path += info['packageID'] + '/' + info['keyboardID'] + '/' - return Gio.Settings(f'{GSETTINGS_BASE}.child', path) + return Gio.Settings.new_with_path(f'{GSETTINGS_BASE}.child', path) def get_option(info): @@ -32,10 +35,10 @@ def get_option(info): result (dictionary): Keyboard options """ result = {} - if "packageID" in info and "keyboardID" in info: - child_schema = get_child_schema(info) - list_options = child_schema.get_strv("options") - result = dict(option.split("=") for option in list_options) + if 'packageID' in info and 'keyboardID' in info: + if child_schema := get_child_schema(info): + list_options = child_schema.get_strv('options') + result = dict(option.split("=") for option in list_options) return result @@ -50,11 +53,11 @@ def set_option(info, options): options: dictionary key and values to store """ - if "packageID" in info and "keyboardID" in info and options: + if 'packageID' in info and 'keyboardID' in info and options: # Convert dictionary of options into a list of option strings - list_options = [f"{key}={value}" for key, value in options.items()] - child_schema = get_child_schema(info) - child_schema.set_strv("options", list_options) + list_options = [f'{key}={value}' for key, value in options.items()] + if child_schema := get_child_schema(info): + child_schema.set_strv('options', list_options) if __name__ == '__main__':