diff options
author | Erovia <erovia@users.noreply.github.com> | 2019-11-24 20:24:47 +0100 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2020-01-19 21:29:36 -0800 |
commit | 20290a1cffc074ae41a550fa6468cb2ed1dd3027 (patch) | |
tree | 67ef21616ee56b042889dff8ef813fc1b545c91e /lib/python/milc.py | |
parent | 80d329bb554f69630cda0376a51314698ad0ccdd (diff) | |
download | qmk_firmware-20290a1cffc074ae41a550fa6468cb2ed1dd3027.tar.gz |
MILC: Fix/complete attribute heritance
If an undefined attribute of a submodule is accessed, fall back to
same attribute of the submodule's parent.
Diffstat (limited to 'lib/python/milc.py')
-rw-r--r-- | lib/python/milc.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/python/milc.py b/lib/python/milc.py index 4392c8376..92b1278f4 100644 --- a/lib/python/milc.py +++ b/lib/python/milc.py @@ -178,8 +178,9 @@ class ConfigurationSection(Configuration): def __getitem__(self, key): """Returns a config value, pulling from the `user` section as a fallback. + This is called when the attribute is accessed either via the get method or through [ ] index. """ - if key in self._config: + if key in self._config and self._config[key]: return self._config[key] elif key in self.parent.user: @@ -187,6 +188,15 @@ class ConfigurationSection(Configuration): return None + def __getattr__(self, key): + """Returns the config value from the `user` section. + This is called when the attribute is accessed via dot notation but does not exists. + """ + if key in self.parent.user: + return self.parent.user[key] + + return None + def handle_store_boolean(self, *args, **kwargs): """Does the add_argument for action='store_boolean'. @@ -519,7 +529,10 @@ class MILC(object): self.config[section][argument] = arg_value else: if argument not in self.config[section]: - self.config[section][argument] = getattr(self.args, argument) + # Check if the argument exist for this section + arg = getattr(self.args, argument) + if arg: + self.config[section][argument] = arg self.release_lock() |