From 5d865ec1efd529db7eb7d02aefbf60b453123d48 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Wed, 24 Aug 2016 10:37:15 -0700 Subject: [PATCH] Cleanup debug.py (#17222) * Use isinstance instead of comparing to type. * Change check against unicode type to check against six.string_types for python3 compatibility. --- lib/ansible/plugins/action/debug.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ansible/plugins/action/debug.py b/lib/ansible/plugins/action/debug.py index ac3cb235fac..aa2bee47689 100644 --- a/lib/ansible/plugins/action/debug.py +++ b/lib/ansible/plugins/action/debug.py @@ -1,4 +1,5 @@ # Copyright 2012, Dag Wieers +# Copyright 2016, Toshio Kuratomi # # This file is part of Ansible # @@ -17,15 +18,17 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +from ansible.compat.six import string_types +from ansible.errors import AnsibleUndefinedVariable from ansible.plugins.action import ActionBase from ansible.utils.unicode import to_unicode -from ansible.errors import AnsibleUndefinedVariable + class ActionModule(ActionBase): ''' Print statements during execution ''' TRANSFERS_FILES = False - VALID_ARGS = set(['msg', 'var', 'verbosity']) + VALID_ARGS = frozenset(('msg', 'var', 'verbosity')) def run(self, tmp=None, task_vars=None): if task_vars is None: @@ -54,14 +57,14 @@ class ActionModule(ActionBase): results = self._templar.template(self._task.args['var'], convert_bare=True, fail_on_undefined=True, bare_deprecated=False) if results == self._task.args['var']: # if results is not str/unicode type, raise an exception - if type(results) not in [str, unicode]: + if not isinstance(results, string_types): raise AnsibleUndefinedVariable # If var name is same as result, try to template it results = self._templar.template("{{" + results + "}}", convert_bare=True, fail_on_undefined=True) except AnsibleUndefinedVariable: results = "VARIABLE IS NOT DEFINED!" - if type(self._task.args['var']) in (list, dict): + if isinstance(self._task.args['var'], (list, dict)): # If var is a list or dict, use the type as key to display result[to_unicode(type(self._task.args['var']))] = results else: