Skip to content

Commit

Permalink
replace type() with isinstance() (ansible#3404)
Browse files Browse the repository at this point in the history
Replace use of type() with isinstance()

Addresses ansible#18310
  • Loading branch information
jctanner authored and mattclay committed Dec 8, 2016
1 parent 81286b8 commit 6cfb44b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions lib/ansible/modules/extras/cloud/misc/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def core(module):

if state and command=='list_vms':
res = v.list_vms(state=state)
if type(res) != dict:
if not isinstance(res, dict):
res = { command: res }
return VIRT_SUCCESS, res

Expand Down Expand Up @@ -477,13 +477,13 @@ def core(module):
res = {'changed': True, 'created': guest}
return VIRT_SUCCESS, res
res = getattr(v, command)(guest)
if type(res) != dict:
if not isinstance(res, dict):
res = { command: res }
return VIRT_SUCCESS, res

elif hasattr(v, command):
res = getattr(v, command)()
if type(res) != dict:
if not isinstance(res, dict):
res = { command: res }
return VIRT_SUCCESS, res

Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/extras/cloud/misc/virt_net.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def core(module):

if state and command == 'list_nets':
res = v.list_nets(state=state)
if type(res) != dict:
if not isinstance(res, dict):
res = { command: res }
return VIRT_SUCCESS, res

Expand Down Expand Up @@ -523,13 +523,13 @@ def core(module):
res = {'changed': mod, 'modified': name}
return VIRT_SUCCESS, res
res = getattr(v, command)(name)
if type(res) != dict:
if not isinstance(res, dict):
res = { command: res }
return VIRT_SUCCESS, res

elif hasattr(v, command):
res = getattr(v, command)()
if type(res) != dict:
if not isinstance(res, dict):
res = { command: res }
return VIRT_SUCCESS, res

Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/modules/extras/cloud/misc/virt_pool.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def core(module):

if state and command == 'list_pools':
res = v.list_pools(state=state)
if type(res) != dict:
if not isinstance(res, dict):
res = { command: res }
return VIRT_SUCCESS, res

Expand Down Expand Up @@ -623,22 +623,22 @@ def core(module):
return VIRT_SUCCESS, res
elif command == 'build':
res = v.build(name, mode)
if type(res) != dict:
if not isinstance(res, dict):
res = { 'changed': True, command: res }
return VIRT_SUCCESS, res
elif command == 'delete':
res = v.delete(name, mode)
if type(res) != dict:
if not isinstance(res, dict):
res = { 'changed': True, command: res }
return VIRT_SUCCESS, res
res = getattr(v, command)(name)
if type(res) != dict:
if not isinstance(res, dict):
res = { command: res }
return VIRT_SUCCESS, res

elif hasattr(v, command):
res = getattr(v, command)()
if type(res) != dict:
if not isinstance(res, dict):
res = { command: res }
return VIRT_SUCCESS, res

Expand Down
16 changes: 8 additions & 8 deletions lib/ansible/modules/extras/cloud/vmware/vmware_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,13 @@ def _build_folder_tree(self, folder, tree={}, treepath=None):
for child in children:
if child == folder or child in tree:
continue
if type(child) == vim.Folder:
if isinstance(child, vim.Folder):
ctree = self._build_folder_tree(child)
tree['subfolders'][child] = dict.copy(ctree)
elif type(child) == vim.VirtualMachine:
elif isinstance(child, vim.VirtualMachine):
tree['virtualmachines'].append(child)
else:
if type(folder) == vim.VirtualMachine:
if isinstance(folder, vim.VirtualMachine):
return folder
return tree

Expand All @@ -214,7 +214,7 @@ def _build_folder_map(self, folder, vmap={}, inpath='/'):

''' Build a searchable index for vms+uuids+folders '''

if type(folder) == tuple:
if isinstance(folder, tuple):
folder = folder[1]

if not 'names' in vmap:
Expand Down Expand Up @@ -284,13 +284,13 @@ def getfolders(self):
def compile_folder_path_for_object(self, vobj):
''' make a /vm/foo/bar/baz like folder path for an object '''
paths = []
if type(vobj) == vim.Folder:
if isinstance(vobj, vim.Folder):
paths.append(vobj.name)

thisobj = vobj
while hasattr(thisobj, 'parent'):
thisobj = thisobj.parent
if type(thisobj) == vim.Folder:
if isinstance(thisobj, vim.Folder):
paths.append(thisobj.name)
paths.reverse()
if paths[0] == 'Datacenters':
Expand Down Expand Up @@ -343,7 +343,7 @@ def getvm(self, name=None, uuid=None, folder=None, name_match=None):
if isinstance(fObj, vim.Datacenter):
fObj = fObj.vmFolder
for cObj in fObj.childEntity:
if not type(cObj) == vim.VirtualMachine:
if not isinstance(cObj, vim.VirtualMachine):
continue
if cObj.name == name:
vm = cObj
Expand All @@ -362,7 +362,7 @@ def getvm(self, name=None, uuid=None, folder=None, name_match=None):
# compare the folder path of each VM against the search path
for item in vmList.items():
vobj = item[0]
if not type(vobj.parent) == vim.Folder:
if not isinstance(vobj.parent, vim.Folder):
continue
if self.compile_folder_path_for_object(vobj) == searchpath:
return vobj
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/extras/database/misc/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def set_master_mode(client):

def flush(client, db=None):
try:
if type(db) != int:
if not isinstance(db, int):
return client.flushall()
else:
# The passed client has been connected to the database already
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/extras/system/osx_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def read(self):
def write(self):

# We need to convert some values so the defaults commandline understands it
if type(self.value) is bool:
if isinstance(self.value, bool):
if self.value:
value = "TRUE"
else:
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/extras/system/zfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def main():
# All freestyle params are zfs properties
if prop not in module.argument_spec:
# Reverse the boolification of freestyle zfs properties
if type(value) == bool:
if isinstance(value, bool):
if value is True:
properties[prop] = 'on'
else:
Expand Down

0 comments on commit 6cfb44b

Please sign in to comment.