From b33ee3daf6eebc74fb176b1f2d8018e0e2214377 Mon Sep 17 00:00:00 2001 From: Michael McCune Date: Thu, 28 Apr 2016 15:15:57 -0400 Subject: 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 --- openstackclient/common/parseractions.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'openstackclient/common/parseractions.py') 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) -- cgit v1.2.1