diff options
author | jctanner <tanner.jc@gmail.com> | 2016-11-09 13:46:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-09 13:46:18 -0500 |
commit | 2de97ac5bddad0e97b5beabdaadc6cd8a4bc6713 (patch) | |
tree | 41334d4a88b8ffe6a5226516d7dba6687607088c | |
parent | 45588171a85c4af70994b0bbc99dcc32ee344711 (diff) | |
download | ansible-modules-core-2de97ac5bddad0e97b5beabdaadc6cd8a4bc6713.tar.gz |
replace type() with isinstance() (#5541)
Replace all use of type() with isintance()
Addresses https://github.com/ansible/ansible/issues/18310
-rw-r--r-- | cloud/amazon/ec2.py | 14 | ||||
-rw-r--r-- | cloud/amazon/rds_param_group.py | 2 | ||||
-rw-r--r-- | cloud/amazon/route53.py | 4 | ||||
-rw-r--r-- | cloud/azure/azure.py | 2 | ||||
-rw-r--r-- | cloud/docker/_docker.py | 2 | ||||
-rw-r--r-- | cloud/openstack/os_server.py | 8 | ||||
-rw-r--r-- | utilities/logic/async_wrapper.py | 2 |
7 files changed, 17 insertions, 17 deletions
diff --git a/cloud/amazon/ec2.py b/cloud/amazon/ec2.py index 0b921c4b..01d105fd 100644 --- a/cloud/amazon/ec2.py +++ b/cloud/amazon/ec2.py @@ -615,7 +615,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] = "" @@ -629,27 +629,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())) @@ -909,7 +909,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) diff --git a/cloud/amazon/rds_param_group.py b/cloud/amazon/rds_param_group.py index a3353cb3..1d863b1a 100644 --- a/cloud/amazon/rds_param_group.py +++ b/cloud/amazon/rds_param_group.py @@ -161,7 +161,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) diff --git a/cloud/amazon/route53.py b/cloud/amazon/route53.py index 107ca757..6e8c2537 100644 --- a/cloud/amazon/route53.py +++ b/cloud/amazon/route53.py @@ -440,10 +440,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:] != '.': diff --git a/cloud/azure/azure.py b/cloud/azure/azure.py index 38e9c2fc..226a8c07 100644 --- a/cloud/azure/azure.py +++ b/cloud/azure/azure.py @@ -594,7 +594,7 @@ class Wrapper(object): raise AttributeError(name) def _wrap(self, func, args, kwargs): - if type(func) == MethodType: + if isinstance(func, MethodType): result = self._handle_temporary_redirects(lambda: func(*args, **kwargs)) else: result = self._handle_temporary_redirects(lambda: func(self.other, *args, **kwargs)) diff --git a/cloud/docker/_docker.py b/cloud/docker/_docker.py index bab50fcb..071e7853 100644 --- a/cloud/docker/_docker.py +++ b/cloud/docker/_docker.py @@ -1303,7 +1303,7 @@ class DockerManager(object): for name, value in self.module.params.get('labels').iteritems(): expected_labels[name] = str(value) - if type(container['Config']['Labels']) is dict: + if isinstance(container['Config']['Labels'], dict): actual_labels = container['Config']['Labels'] else: for container_label in container['Config']['Labels'] or []: diff --git a/cloud/openstack/os_server.py b/cloud/openstack/os_server.py index ec3b4e83..12d8724e 100644 --- a/cloud/openstack/os_server.py +++ b/cloud/openstack/os_server.py @@ -386,7 +386,7 @@ def _exit_hostvars(module, cloud, server, changed=True): def _parse_nics(nics): for net in nics: - if type(net) == str: + if isinstance(net, str): for nic in net.split(','): yield dict((nic.split('='),)) else: @@ -396,11 +396,11 @@ def _network_args(module, cloud): args = [] nics = module.params['nics'] - if type(nics) != list: + if not isinstance(nics, list): module.fail_json(msg='The \'nics\' parameter must be a list.') for net in _parse_nics(nics): - if type(net) != dict: + if not isinstance(net, dict): module.fail_json( msg='Each entry in the \'nics\' parameter must be a dict.') @@ -457,7 +457,7 @@ def _create_server(module, cloud): nics = _network_args(module, cloud) - if type(module.params['meta']) is str: + if isinstance(module.params['meta'], str): metas = {} for kv_str in module.params['meta'].split(","): k, v = kv_str.split("=") diff --git a/utilities/logic/async_wrapper.py b/utilities/logic/async_wrapper.py index b2af4067..0d8c41ac 100644 --- a/utilities/logic/async_wrapper.py +++ b/utilities/logic/async_wrapper.py @@ -143,7 +143,7 @@ def _run_module(wrapped_cmd, jid, job_path): if json_warnings: # merge JSON junk warnings with any existing module 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.extend(json_warnings) result['warnings'] = module_warnings |