summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Stanek <dstanek@dstanek.com>2014-06-13 03:10:34 +0000
committerDavid Stanek <dstanek@dstanek.com>2014-06-27 01:20:07 +0000
commitef6f9bc46a33a677df702e4dc9cfc53d03c49628 (patch)
treebfca43edafee66ea8ec9532bd2c2e79b3d711d0d
parentf18797ab7d068663b37f4e25558c624f44e4b099 (diff)
downloadoslo-config-ef6f9bc46a33a677df702e4dc9cfc53d03c49628.tar.gz
Refactors _Namespace to make the code clearer
The original implentation of _Namespace._get_cli_value relied on the fact that _Namespace.default doesn't exist and accessing it would raise an AttributeError. This attribute was being caught for another reason so the logic just worked. The more correct thing to do would have been to just raise a KeyError. This change does that and removes the need to catch an AttributeErrors. Change-Id: I963b31ea6ea8ab5180314be7cd2450395263e1af Closes-bug: #1284968
-rw-r--r--oslo/config/cfg.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/oslo/config/cfg.py b/oslo/config/cfg.py
index 98507b4..21ec818 100644
--- a/oslo/config/cfg.py
+++ b/oslo/config/cfg.py
@@ -1447,15 +1447,14 @@ class _Namespace(argparse.Namespace):
"""
for group_name, name in names:
name = name if group_name is None else group_name + '_' + name
- try:
- value = getattr(self, name)
- if value is not None:
- # argparse ignores default=None for nargs='*'
- if positional and not value:
- value = self.default
- return value
- except AttributeError:
- pass
+ value = getattr(self, name, None)
+ if value is not None:
+ # argparse ignores default=None for nargs='*' and returns []
+ if positional and not value:
+ continue
+
+ return value
+
raise KeyError
def _get_value(self, names, multi, positional):