summaryrefslogtreecommitdiff
path: root/openstackclient/common/parseractions.py
diff options
context:
space:
mode:
authorMichael McCune <msm@redhat.com>2016-04-28 15:15:57 -0400
committerMichael McCune <msm@redhat.com>2016-05-02 15:11:45 -0400
commitb33ee3daf6eebc74fb176b1f2d8018e0e2214377 (patch)
treecc2d8caac62370b2e2d16efdf4d2fee2aac131fd /openstackclient/common/parseractions.py
parent9d7ccd9385776c8c0edf90094b8ef323ef1890a6 (diff)
downloadpython-openstackclient-b33ee3daf6eebc74fb176b1f2d8018e0e2214377.tar.gz
remove assert in favor an if/else
the assert usage in the NonNegativeAction has the potential to allow unexpected behavior when the python is byte-compiled with optimization turned on. Changes * remove assert in favor of if/else in NonNegativeAction class * add type specifier to parser arguments for non-negative actions * correct tests for new int based values Change-Id: I093e7440b8beff4f179e2c4ed81daff82704c40e Closes-Bug: #1576375
Diffstat (limited to 'openstackclient/common/parseractions.py')
-rw-r--r--openstackclient/common/parseractions.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/openstackclient/common/parseractions.py b/openstackclient/common/parseractions.py
index c30058c8..77798f90 100644
--- a/openstackclient/common/parseractions.py
+++ b/openstackclient/common/parseractions.py
@@ -155,9 +155,8 @@ class NonNegativeAction(argparse.Action):
"""
def __call__(self, parser, namespace, values, option_string=None):
- try:
- assert(int(values) >= 0)
+ if int(values) >= 0:
setattr(namespace, self.dest, values)
- except Exception:
+ else:
msg = "%s expected a non-negative integer" % (str(option_string))
raise argparse.ArgumentTypeError(msg)