mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 11:21:25 -07: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:
parent
64fe7402ff
commit
6bad4e57bd
12 changed files with 49 additions and 34 deletions
|
@ -21,6 +21,7 @@ __metaclass__ = type
|
|||
|
||||
import re
|
||||
import operator as py_operator
|
||||
from collections import MutableMapping, MutableSequence
|
||||
from distutils.version import LooseVersion, StrictVersion
|
||||
|
||||
from ansible import errors
|
||||
|
@ -28,7 +29,7 @@ from ansible import errors
|
|||
def failed(*a, **kw):
|
||||
''' Test if task result yields failed '''
|
||||
item = a[0]
|
||||
if type(item) != dict:
|
||||
if not isinstance(item, MutableMapping):
|
||||
raise errors.AnsibleFilterError("|failed expects a dictionary")
|
||||
rc = item.get('rc',0)
|
||||
failed = item.get('failed',False)
|
||||
|
@ -44,13 +45,13 @@ def success(*a, **kw):
|
|||
def changed(*a, **kw):
|
||||
''' Test if task result yields changed '''
|
||||
item = a[0]
|
||||
if type(item) != dict:
|
||||
if not isinstance(item, MutableMapping):
|
||||
raise errors.AnsibleFilterError("|changed expects a dictionary")
|
||||
if not 'changed' in item:
|
||||
changed = False
|
||||
if ('results' in item # some modules return a 'results' key
|
||||
and type(item['results']) == list
|
||||
and type(item['results'][0]) == dict):
|
||||
and isinstance(item['results'], MutableSequence)
|
||||
and isinstance(item['results'][0], MutableMapping)):
|
||||
for result in item['results']:
|
||||
changed = changed or result.get('changed', False)
|
||||
else:
|
||||
|
@ -60,7 +61,7 @@ def changed(*a, **kw):
|
|||
def skipped(*a, **kw):
|
||||
''' Test if task result yields skipped '''
|
||||
item = a[0]
|
||||
if type(item) != dict:
|
||||
if not isinstance(item, MutableMapping):
|
||||
raise errors.AnsibleFilterError("|skipped expects a dictionary")
|
||||
skipped = item.get('skipped', False)
|
||||
return skipped
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue