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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user