From fea59342b988373d6b2af3fabdef520ff7b03741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavol=20=C5=BD=C3=A1=C4=8Dik?= Date: Mon, 15 Apr 2024 16:09:32 +0200 Subject: [PATCH] Do not default global option defaults to None If a global option does not have a default value defined, we should not set the default value to None, because it prevents the users of the config object from supplying their own fallback values. --- tuned/utils/global_config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tuned/utils/global_config.py b/tuned/utils/global_config.py index e0ed4365..1e36f619 100644 --- a/tuned/utils/global_config.py +++ b/tuned/utils/global_config.py @@ -20,8 +20,8 @@ def __init__(self,config_file = consts.GLOBAL_CONFIG_FILE): def get_global_config_spec(): """ Easy validation mimicking configobj - Returns two dicts, first with default values (default None) - global_default[consts.CFG_SOMETHING] = consts.CFG_DEF_SOMETHING or None + Returns two dicts, first with default values (if there is one) + global_default[consts.CFG_SOMETHING] = consts.CFG_DEF_SOMETHING second with configobj function for value type (default "get" for string, others eg getboolean, getint) global_function[consts.CFG_SOMETHING] = consts.CFG_FUNC_SOMETHING or get } @@ -30,7 +30,7 @@ def get_global_config_spec(): if opt.startswith("CFG_") and not opt.startswith("CFG_FUNC_") and not opt.startswith("CFG_DEF_")] - global_default = dict((getattr(consts, opt), getattr(consts, "CFG_DEF_" + opt[4:], None)) for opt in options) + global_default = dict((getattr(consts, opt), getattr(consts, "CFG_DEF_" + opt[4:])) for opt in options if hasattr(consts, "CFG_DEF_" + opt[4:])) global_function = dict((getattr(consts, opt), getattr(consts, "CFG_FUNC_" + opt[4:], "get")) for opt in options) return global_default, global_function