mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 20:01:25 -07:00
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:
parent
2744fde7c9
commit
06e1141106
7 changed files with 17 additions and 17 deletions
|
@ -612,7 +612,7 @@ def find_running_instances_by_count_tag(module, ec2, count_tag, zone=None):
|
||||||
def _set_none_to_blank(dictionary):
|
def _set_none_to_blank(dictionary):
|
||||||
result = dictionary
|
result = dictionary
|
||||||
for k in result.iterkeys():
|
for k in result.iterkeys():
|
||||||
if type(result[k]) == dict:
|
if isinstance(result[k], dict):
|
||||||
result[k] = _set_none_to_blank(result[k])
|
result[k] = _set_none_to_blank(result[k])
|
||||||
elif not result[k]:
|
elif not result[k]:
|
||||||
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 tags is not None:
|
||||||
|
|
||||||
if type(tags) is str:
|
if isinstance(tags, str):
|
||||||
try:
|
try:
|
||||||
tags = literal_eval(tags)
|
tags = literal_eval(tags)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# if string, we only care that a tag of that name exists
|
# 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})
|
filters.update({"tag-key": tags})
|
||||||
|
|
||||||
# if list, append each item to filters
|
# if list, append each item to filters
|
||||||
if type(tags) is list:
|
if isinstance(tags, list):
|
||||||
for x in tags:
|
for x in tags:
|
||||||
if type(x) is dict:
|
if isinstance(x, dict):
|
||||||
x = _set_none_to_blank(x)
|
x = _set_none_to_blank(x)
|
||||||
filters.update(dict(("tag:"+tn, tv) for (tn,tv) in x.iteritems()))
|
filters.update(dict(("tag:"+tn, tv) for (tn,tv) in x.iteritems()))
|
||||||
else:
|
else:
|
||||||
filters.update({"tag-key": x})
|
filters.update({"tag-key": x})
|
||||||
|
|
||||||
# if dict, add the key and value to the filter
|
# 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)
|
tags = _set_none_to_blank(tags)
|
||||||
filters.update(dict(("tag:"+tn, tv) for (tn,tv) in tags.iteritems()))
|
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
|
# ensure all instances are dictionaries
|
||||||
all_instances = []
|
all_instances = []
|
||||||
for inst in instances:
|
for inst in instances:
|
||||||
if type(inst) is not dict:
|
if not isinstance(inst, dict):
|
||||||
inst = get_instance_info(inst)
|
inst = get_instance_info(inst)
|
||||||
all_instances.append(inst)
|
all_instances.append(inst)
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ def set_parameter(param, value, immediate):
|
||||||
# may be based on a variable (ie. {foo*3/4}) so
|
# may be based on a variable (ie. {foo*3/4}) so
|
||||||
# just pass it on through to boto
|
# just pass it on through to boto
|
||||||
converted_value = str(value)
|
converted_value = str(value)
|
||||||
elif type(value) == bool:
|
elif isinstance(value, bool):
|
||||||
converted_value = 1 if value else 0
|
converted_value = 1 if value else 0
|
||||||
else:
|
else:
|
||||||
converted_value = int(value)
|
converted_value = int(value)
|
||||||
|
|
|
@ -450,10 +450,10 @@ def main():
|
||||||
|
|
||||||
value_list = ()
|
value_list = ()
|
||||||
|
|
||||||
if type(value_in) is str:
|
if isinstance(value_in, str):
|
||||||
if value_in:
|
if value_in:
|
||||||
value_list = sorted([s.strip() for s in value_in.split(',')])
|
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)
|
value_list = sorted(value_in)
|
||||||
|
|
||||||
if zone_in[-1:] != '.':
|
if zone_in[-1:] != '.':
|
||||||
|
|
|
@ -602,7 +602,7 @@ class Wrapper(object):
|
||||||
raise AttributeError(name)
|
raise AttributeError(name)
|
||||||
|
|
||||||
def _wrap(self, func, args, kwargs):
|
def _wrap(self, func, args, kwargs):
|
||||||
if type(func) == MethodType:
|
if isinstance(func, MethodType):
|
||||||
result = self._handle_temporary_redirects(lambda: func(*args, **kwargs))
|
result = self._handle_temporary_redirects(lambda: func(*args, **kwargs))
|
||||||
else:
|
else:
|
||||||
result = self._handle_temporary_redirects(lambda: func(self.other, *args, **kwargs))
|
result = self._handle_temporary_redirects(lambda: func(self.other, *args, **kwargs))
|
||||||
|
|
|
@ -1307,7 +1307,7 @@ class DockerManager(object):
|
||||||
for name, value in self.module.params.get('labels').iteritems():
|
for name, value in self.module.params.get('labels').iteritems():
|
||||||
expected_labels[name] = str(value)
|
expected_labels[name] = str(value)
|
||||||
|
|
||||||
if type(container['Config']['Labels']) is dict:
|
if isinstance(container['Config']['Labels'], dict):
|
||||||
actual_labels = container['Config']['Labels']
|
actual_labels = container['Config']['Labels']
|
||||||
else:
|
else:
|
||||||
for container_label in container['Config']['Labels'] or []:
|
for container_label in container['Config']['Labels'] or []:
|
||||||
|
|
|
@ -388,7 +388,7 @@ def _exit_hostvars(module, cloud, server, changed=True):
|
||||||
|
|
||||||
def _parse_nics(nics):
|
def _parse_nics(nics):
|
||||||
for net in nics:
|
for net in nics:
|
||||||
if type(net) == str:
|
if isinstance(net, str):
|
||||||
for nic in net.split(','):
|
for nic in net.split(','):
|
||||||
yield dict((nic.split('='),))
|
yield dict((nic.split('='),))
|
||||||
else:
|
else:
|
||||||
|
@ -398,11 +398,11 @@ def _network_args(module, cloud):
|
||||||
args = []
|
args = []
|
||||||
nics = module.params['nics']
|
nics = module.params['nics']
|
||||||
|
|
||||||
if type(nics) != list:
|
if not isinstance(nics, list):
|
||||||
module.fail_json(msg='The \'nics\' parameter must be a list.')
|
module.fail_json(msg='The \'nics\' parameter must be a list.')
|
||||||
|
|
||||||
for net in _parse_nics(nics):
|
for net in _parse_nics(nics):
|
||||||
if type(net) != dict:
|
if not isinstance(net, dict):
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg='Each entry in the \'nics\' parameter must be a dict.')
|
msg='Each entry in the \'nics\' parameter must be a dict.')
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ def _create_server(module, cloud):
|
||||||
|
|
||||||
nics = _network_args(module, cloud)
|
nics = _network_args(module, cloud)
|
||||||
|
|
||||||
if type(module.params['meta']) is str:
|
if isinstance(module.params['meta'], str):
|
||||||
metas = {}
|
metas = {}
|
||||||
for kv_str in module.params['meta'].split(","):
|
for kv_str in module.params['meta'].split(","):
|
||||||
k, v = kv_str.split("=")
|
k, v = kv_str.split("=")
|
||||||
|
|
|
@ -143,7 +143,7 @@ def _run_module(wrapped_cmd, jid, job_path):
|
||||||
if json_warnings:
|
if json_warnings:
|
||||||
# merge JSON junk warnings with any existing module warnings
|
# merge JSON junk warnings with any existing module warnings
|
||||||
module_warnings = result.get('warnings', [])
|
module_warnings = result.get('warnings', [])
|
||||||
if type(module_warnings) is not list:
|
if not isinstance(module_warnings, list):
|
||||||
module_warnings = [module_warnings]
|
module_warnings = [module_warnings]
|
||||||
module_warnings.extend(json_warnings)
|
module_warnings.extend(json_warnings)
|
||||||
result['warnings'] = module_warnings
|
result['warnings'] = module_warnings
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue