From 8b5a772e36fb7b7fae42a956bc844e792bec2035 Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Fri, 5 Aug 2016 14:45:28 +0200 Subject: Make APIVersion's null check more pythonic Our current APIVersion object has an is_null method to check when the version instance is null (major=0 and minor=0). While this works it is not very pythonic, since you have to write expressions such as: if not min_version and not max_version: return True elif ((min_version and max_version) and max_version.is_null() and min_version.is_null()): return True This patch removes the is_null method and instead implements the truth value testing to simplify expressions and make code more pythonic. So previous code would just look like: if not min_version and not max_version: return True Because this will work with min_version being None or being an APIVersion instance with major=0 and minor=0. Change-Id: I7497c5dc940c1e726507117cadbad232d8c1d80d --- cinderclient/shell.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'cinderclient/shell.py') diff --git a/cinderclient/shell.py b/cinderclient/shell.py index d756c0c..a05bb53 100644 --- a/cinderclient/shell.py +++ b/cinderclient/shell.py @@ -433,11 +433,11 @@ class OpenStackCinderShell(object): subparser.set_defaults(func=self.do_bash_completion) def _build_versioned_help_message(self, start_version, end_version): - if not start_version.is_null() and not end_version.is_null(): + if start_version and end_version: msg = (_(" (Supported by API versions %(start)s - %(end)s)") % {"start": start_version.get_string(), "end": end_version.get_string()}) - elif not start_version.is_null(): + elif start_version: msg = (_(" (Supported by API version %(start)s and later)") % {"start": start_version.get_string()}) else: @@ -504,8 +504,7 @@ class OpenStackCinderShell(object): start_version = api_versions.APIVersion(start_version) end_version = kwargs.get('end_version', None) end_version = api_versions.APIVersion(end_version) - if do_help and not (start_version.is_null() - and end_version.is_null()): + if do_help and (start_version or end_version): kwargs["help"] = kwargs.get("help", "") + ( self._build_versioned_help_message(start_version, end_version)) -- cgit v1.2.1