arg_validator: normalize numeric value for ArgValidatorNum

In python, bool is a subclass of int. Thus,
isinstance(value, self.numeric_type) would be True, with value being a
bool and numeric_type an int.

ArgValidatorNum should normalize the input values to be of type
self.numeric_type, except the default_value, which might be None (or
anything really).

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
Wen Liang 2021-04-18 09:39:44 -04:00 committed by Gris Ge
parent 93e509b533
commit dfacbf72f7

View file

@ -272,7 +272,9 @@ class ArgValidatorNum(ArgValidator):
v = None
try:
if isinstance(value, self.numeric_type):
v = value
# ArgValidatorNum should normalize the input values to be of type
# self.numeric_type, except the default_value
v = self.numeric_type(value)
else:
v2 = self.numeric_type(value)
if isinstance(value, Util.STRING_TYPE) or v2 == value: