mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 13:22:48 +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:
@@ -1378,7 +1378,7 @@ class Ec2Inventory(object):
|
||||
elif key == 'ec2__previous_state':
|
||||
instance_vars['ec2_previous_state'] = instance.previous_state or ''
|
||||
instance_vars['ec2_previous_state_code'] = instance.previous_state_code
|
||||
elif type(value) in [int, bool]:
|
||||
elif isinstance(value, (int, bool)):
|
||||
instance_vars[key] = value
|
||||
elif isinstance(value, six.string_types):
|
||||
instance_vars[key] = value.strip()
|
||||
@@ -1483,7 +1483,7 @@ class Ec2Inventory(object):
|
||||
|
||||
# Target: Everything
|
||||
# Preserve booleans and integers
|
||||
elif type(value) in [int, bool]:
|
||||
elif isinstance(value, (int, bool)):
|
||||
host_info[key] = value
|
||||
|
||||
# Target: Everything
|
||||
|
||||
@@ -385,7 +385,7 @@ class PacketInventory(object):
|
||||
device_vars[key] = device.state or ''
|
||||
elif key == 'packet_hostname':
|
||||
device_vars[key] = value
|
||||
elif type(value) in [int, bool]:
|
||||
elif isinstance(value, (int, bool)):
|
||||
device_vars[key] = value
|
||||
elif isinstance(value, six.string_types):
|
||||
device_vars[key] = value.strip()
|
||||
|
||||
@@ -43,13 +43,16 @@
|
||||
import argparse
|
||||
import os.path
|
||||
import sys
|
||||
import paramiko
|
||||
from collections import MutableSequence
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
import paramiko
|
||||
|
||||
|
||||
SSH_CONF = '~/.ssh/config'
|
||||
|
||||
_key = 'ssh_config'
|
||||
@@ -68,7 +71,7 @@ def get_config():
|
||||
cfg.parse(f)
|
||||
ret_dict = {}
|
||||
for d in cfg._config:
|
||||
if type(d['host']) is list:
|
||||
if isinstance(d['host'], MutableSequence):
|
||||
alias = d['host'][0]
|
||||
else:
|
||||
alias = d['host']
|
||||
@@ -93,7 +96,7 @@ def print_list():
|
||||
# If the attribute is a list, just take the first element.
|
||||
# Private key is returned in a list for some reason.
|
||||
attr = attributes[ssh_opt]
|
||||
if type(attr) is list:
|
||||
if isinstance(attr, MutableSequence):
|
||||
attr = attr[0]
|
||||
tmp_dict[ans_opt] = attr
|
||||
if tmp_dict:
|
||||
|
||||
Reference in New Issue
Block a user