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:
Toshio Kuratomi 2017-03-26 09:24:30 -07:00
commit 6bad4e57bd
12 changed files with 49 additions and 34 deletions

View file

@ -19,6 +19,7 @@ __metaclass__ = type
import codecs
import csv
from collections import MutableSequence
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
@ -102,7 +103,7 @@ class LookupModule(LookupBase):
lookupfile = self.find_file_in_search_path(variables, 'files', paramvals['file'])
var = self.read_csv(lookupfile, key, paramvals['delimiter'], paramvals['encoding'], paramvals['default'], paramvals['col'])
if var is not None:
if type(var) is list:
if isinstance(var, MutableSequence):
for v in var:
ret.append(v)
else:

View file

@ -22,11 +22,12 @@ from ansible.plugins.lookup import LookupBase
import socket
try:
import dns.exception
import dns.name
import dns.resolver
import dns.reversename
from dns.rdatatype import (A, AAAA, CNAME, DLV, DNAME, DNSKEY, DS, HINFO, LOC,
MX, NAPTR, NS, NSEC3PARAM, PTR, RP, SOA, SPF, SRV, SSHFP, TLSA, TXT)
import dns.exception
HAVE_DNS = True
except ImportError:
HAVE_DNS = False
@ -70,7 +71,7 @@ def make_rdata_dict(rdata):
for f in fields:
val = rdata.__getattribute__(f)
if type(val) == dns.name.Name:
if isinstance(val, dns.name.Name):
val = dns.name.Name.to_text(val)
if rdata.rdtype == DLV and f == 'digest':

View file

@ -17,9 +17,10 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from io import StringIO
import os
import re
from collections import MutableSequence
from io import StringIO
from ansible.errors import AnsibleError
from ansible.module_utils.six.moves import configparser
@ -110,7 +111,7 @@ class LookupModule(LookupBase):
else:
var = self.read_ini(path, key, paramvals['section'], paramvals['default'], paramvals['re'])
if var is not None:
if type(var) is list:
if isinstance(var, MutableSequence):
for v in var:
ret.append(v)
else: