Skip to content

Commit

Permalink
Do not default global option defaults to None
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zacikpa committed Apr 15, 2024
1 parent 1fb7c80 commit fea5934
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tuned/utils/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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

Expand Down

0 comments on commit fea5934

Please sign in to comment.