I'm looking to enhance the 'uri' module to accept a list of integer
status_codes. Currently, the argument types are: str, list, dict,
bool,int and float. Currently the status_code parameter is using
'int', but I now need a list of ints. Would a new argument type
'int_list' be accepted? Or should I solve this a different way?
Thanks,
So, started working on the int_list type in the _check_argument_types
function in:
lib/ansible/module_utils/basic.py
I'm noticing some possible problems with the conversion of types. For
example if a type is specified as 'int' this gets called to check and
possibly convert it:
elif wanted == 'int':
if not isinstance(value, int):
if isinstance(value, basestring):
self.params[k] = int(value)
else:
is_invalid = True
This will convert a string to an int fine if someone puts in a string
like "1", but if someone puts in a string like "joey" it causes
ansible to traceback with a ValueError exception. (e.g. ValueError:
invalid literal for int() with base 10: 'joey') The same holds true
for float and possibly others. It works properly if it's wrapped in a
try/except block like so:
elif wanted == 'int':
try:
if not isinstance(value, int):
if isinstance(value, basestring):
self.params[k] = int(value)
else:
is_invalid = True
except ValueError:
is_invalid=True
Would this be an acceptable pull request?