From ef6f9bc46a33a677df702e4dc9cfc53d03c49628 Mon Sep 17 00:00:00 2001 From: David Stanek Date: Fri, 13 Jun 2014 03:10:34 +0000 Subject: 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 --- oslo/config/cfg.py | 17 ++++++++--------- 1 file 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): -- cgit v1.2.1