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
This commit is contained in:
Michael McCune
2016-04-28 15:15:57 -04:00
parent f3176b04d4
commit 183154c9a2

View File

@@ -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)