replace type() with isinstance() (#5541)

Replace all use of type() with isintance()

Addresses https://github.com/ansible/ansible/issues/18310
This commit is contained in:
jctanner 2016-11-09 13:46:18 -05:00 committed by Matt Clay
commit 06e1141106
7 changed files with 17 additions and 17 deletions

View file

@ -612,7 +612,7 @@ def find_running_instances_by_count_tag(module, ec2, count_tag, zone=None):
def _set_none_to_blank(dictionary):
result = dictionary
for k in result.iterkeys():
if type(result[k]) == dict:
if isinstance(result[k], dict):
result[k] = _set_none_to_blank(result[k])
elif not result[k]:
result[k] = ""
@ -626,27 +626,27 @@ def get_reservations(module, ec2, tags=None, state=None, zone=None):
if tags is not None:
if type(tags) is str:
if isinstance(tags, str):
try:
tags = literal_eval(tags)
except:
pass
# if string, we only care that a tag of that name exists
if type(tags) is str:
if isinstance(tags, str):
filters.update({"tag-key": tags})
# if list, append each item to filters
if type(tags) is list:
if isinstance(tags, list):
for x in tags:
if type(x) is dict:
if isinstance(x, dict):
x = _set_none_to_blank(x)
filters.update(dict(("tag:"+tn, tv) for (tn,tv) in x.iteritems()))
else:
filters.update({"tag-key": x})
# if dict, add the key and value to the filter
if type(tags) is dict:
if isinstance(tags, dict):
tags = _set_none_to_blank(tags)
filters.update(dict(("tag:"+tn, tv) for (tn,tv) in tags.iteritems()))
@ -906,7 +906,7 @@ def enforce_count(module, ec2, vpc):
# ensure all instances are dictionaries
all_instances = []
for inst in instances:
if type(inst) is not dict:
if not isinstance(inst, dict):
inst = get_instance_info(inst)
all_instances.append(inst)

View file

@ -159,7 +159,7 @@ def set_parameter(param, value, immediate):
# may be based on a variable (ie. {foo*3/4}) so
# just pass it on through to boto
converted_value = str(value)
elif type(value) == bool:
elif isinstance(value, bool):
converted_value = 1 if value else 0
else:
converted_value = int(value)

View file

@ -450,10 +450,10 @@ def main():
value_list = ()
if type(value_in) is str:
if isinstance(value_in, str):
if value_in:
value_list = sorted([s.strip() for s in value_in.split(',')])
elif type(value_in) is list:
elif isinstance(value_in, list):
value_list = sorted(value_in)
if zone_in[-1:] != '.':