mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 05:12:45 +00:00
Migrate most uses of if type() to if isinstance()
Also convert those checks to use abcs instead of dict and list. Make a sentinel class for strategies to report when they've reache the end
This commit is contained in:
@@ -19,8 +19,7 @@
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.callback.default import CallbackModule as CallbackModule_default
|
||||
from ansible.utils.color import colorize, hostcolor
|
||||
from collections import MutableMapping, MutableSequence
|
||||
|
||||
HAS_OD = False
|
||||
try:
|
||||
@@ -29,6 +28,10 @@ try:
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
from ansible.module_utils.six import binary_type, text_type
|
||||
from ansible.plugins.callback.default import CallbackModule as CallbackModule_default
|
||||
from ansible.utils.color import colorize, hostcolor
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
except ImportError:
|
||||
@@ -235,7 +238,7 @@ class CallbackModule_dense(CallbackModule_default):
|
||||
|
||||
# Remove empty attributes (list, dict, str)
|
||||
for attr in result.copy():
|
||||
if type(result[attr]) in (list, dict, basestring, unicode):
|
||||
if isinstance(result[attr], (MutableSequence, MutableMapping, binary_type, text_type)):
|
||||
if not result[attr]:
|
||||
del(result[attr])
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ __metaclass__ = type
|
||||
import os
|
||||
import time
|
||||
import json
|
||||
from collections import MutableMapping
|
||||
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.plugins.callback import CallbackBase
|
||||
@@ -54,7 +55,7 @@ class CallbackModule(CallbackBase):
|
||||
os.makedirs("/var/log/ansible/hosts")
|
||||
|
||||
def log(self, host, category, data):
|
||||
if type(data) == dict:
|
||||
if isinstance(data, MutableMapping):
|
||||
if '_ansible_verbose_override' in data:
|
||||
# avoid logging extraneous data
|
||||
data = 'omitted'
|
||||
|
||||
Reference in New Issue
Block a user