From eeaec56ed5bebb3366cc7aa80f63c3bf75436e8a Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 16 Feb 2017 15:47:09 -0800 Subject: [PATCH] Use isinstance instead of type() comparisons. isinstance is more robust --- lib/ansible/executor/stats.py | 6 ++++-- lib/ansible/plugins/strategy/debug.py | 2 +- test/sanity/pep8/legacy-files.txt | 2 -- test/sanity/pep8/legacy-ignore.txt | 1 - 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/ansible/executor/stats.py b/lib/ansible/executor/stats.py index f91874d17a..482a147afb 100644 --- a/lib/ansible/executor/stats.py +++ b/lib/ansible/executor/stats.py @@ -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 diff --git a/lib/ansible/plugins/strategy/debug.py b/lib/ansible/plugins/strategy/debug.py index 61159d5fab..a9159dc1b7 100644 --- a/lib/ansible/plugins/strategy/debug.py +++ b/lib/ansible/plugins/strategy/debug.py @@ -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__ diff --git a/test/sanity/pep8/legacy-files.txt b/test/sanity/pep8/legacy-files.txt index 5e82029b53..01e6e4d2a5 100644 --- a/test/sanity/pep8/legacy-files.txt +++ b/test/sanity/pep8/legacy-files.txt @@ -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 diff --git a/test/sanity/pep8/legacy-ignore.txt b/test/sanity/pep8/legacy-ignore.txt index 14d09ab1ec..9e7f635246 100644 --- a/test/sanity/pep8/legacy-ignore.txt +++ b/test/sanity/pep8/legacy-ignore.txt @@ -4,4 +4,3 @@ E125 E129 E501 E712 -E721