Use isinstance instead of type() comparisons. isinstance is more robust

This commit is contained in:
Toshio Kuratomi 2017-02-16 15:47:09 -08:00
parent 2192c1eb02
commit eeaec56ed5
4 changed files with 5 additions and 6 deletions

View file

@ -19,6 +19,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from collections import MutableMapping
from ansible.utils.vars import merge_hash
class AggregateStats:
@ -73,10 +75,10 @@ class AggregateStats:
return self.set_custom_stats(which, what, host)
# mismatching types
if type(what) != type(self.custom[host][which]):
if not isinstance(what, type(self.custom[host][which])):
return None
if isinstance(what, dict):
if isinstance(what, MutableMapping):
self.custom[host][which] = merge_hash(self.custom[host][which], what)
else:
# let overloaded + take care of other types

View file

@ -144,7 +144,7 @@ class Debugger(cmd.Cmd):
exec(code, globals(), self.scope)
except:
t, v = sys.exc_info()[:2]
if type(t) == type(''):
if isinstance(t, str):
exc_type_name = t
else:
exc_type_name = t.__name__

View file

@ -5,7 +5,6 @@ lib/ansible/compat/six/__init__.py
lib/ansible/constants.py
lib/ansible/errors/__init__.py
lib/ansible/executor/play_iterator.py
lib/ansible/executor/stats.py
lib/ansible/executor/task_executor.py
lib/ansible/galaxy/role.py
lib/ansible/inventory/dir.py
@ -260,7 +259,6 @@ lib/ansible/plugins/lookup/first_found.py
lib/ansible/plugins/shell/fish.py
lib/ansible/plugins/shell/sh.py
lib/ansible/plugins/strategy/__init__.py
lib/ansible/plugins/strategy/debug.py
lib/ansible/plugins/strategy/linear.py
lib/ansible/template/__init__.py
lib/ansible/utils/encrypt.py

View file

@ -4,4 +4,3 @@ E125
E129
E501
E712
E721