diff --git a/changelogs/fragments/10903-2to3.yml b/changelogs/fragments/10903-2to3.yml new file mode 100644 index 0000000000..af0b744456 --- /dev/null +++ b/changelogs/fragments/10903-2to3.yml @@ -0,0 +1,8 @@ +minor_changes: + - pickle cache plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903). + - counter_enabled callback plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903). + - wsl connection plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903). + - cobbler inventory plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903). + - linode inventory plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903). + - utm_utils module_utils plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903). + - vexata module_utils plugin - use Python 3 idioms (https://github.com/ansible-collections/community.general/pull/10903). diff --git a/plugins/cache/pickle.py b/plugins/cache/pickle.py index 18153f67aa..6c053138c8 100644 --- a/plugins/cache/pickle.py +++ b/plugins/cache/pickle.py @@ -42,10 +42,7 @@ options: type: float """ -try: - import cPickle as pickle -except ImportError: - import pickle +import pickle from ansible.plugins.cache import BaseFileCacheModule diff --git a/plugins/callback/counter_enabled.py b/plugins/callback/counter_enabled.py index ca10ddd993..d5fe334a49 100644 --- a/plugins/callback/counter_enabled.py +++ b/plugins/callback/counter_enabled.py @@ -67,7 +67,7 @@ class CallbackModule(CallbackBase): def v2_playbook_on_play_start(self, play): name = play.get_name().strip() if not name: - msg = u"play" + msg = "play" else: msg = f"PLAY [{name}]" diff --git a/plugins/connection/wsl.py b/plugins/connection/wsl.py index 9e7bb26eeb..3b768eebf8 100644 --- a/plugins/connection/wsl.py +++ b/plugins/connection/wsl.py @@ -525,9 +525,9 @@ class Connection(ConnectionBase): raise AnsibleAuthenticationFailure(msg) except Exception as e: msg = to_text(e) - if u'PID check failed' in msg: + if 'PID check failed' in msg: raise AnsibleError('paramiko version issue, please upgrade paramiko on the machine running ansible') - elif u'Private key file is encrypted' in msg: + elif 'Private key file is encrypted' in msg: msg = ( f'ssh {self.get_option("remote_user")}@{self.get_options("remote_addr")}:{port} : ' f'{msg}\nTo connect as a different user, use -u .' diff --git a/plugins/inventory/cobbler.py b/plugins/inventory/cobbler.py index 58fc2c7ab7..7374193a74 100644 --- a/plugins/inventory/cobbler.py +++ b/plugins/inventory/cobbler.py @@ -139,14 +139,10 @@ from ansible_collections.community.general.plugins.plugin_utils.unsafe import ma # xmlrpc try: - import xmlrpclib as xmlrpc_client + import xmlrpc.client as xmlrpc_client HAS_XMLRPC_CLIENT = True except ImportError: - try: - import xmlrpc.client as xmlrpc_client - HAS_XMLRPC_CLIENT = True - except ImportError: - HAS_XMLRPC_CLIENT = False + HAS_XMLRPC_CLIENT = False class TimeoutTransport (xmlrpc_client.SafeTransport): diff --git a/plugins/inventory/linode.py b/plugins/inventory/linode.py index 7807284383..fc039b03b5 100644 --- a/plugins/inventory/linode.py +++ b/plugins/inventory/linode.py @@ -167,13 +167,7 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): def _add_groups(self): """Add Linode instance groups to the dynamic inventory.""" - self.linode_groups = set( - filter(None, [ - instance.group - for instance - in self.instances - ]) - ) + self.linode_groups = {instance.group for instance in self.instances if instance.group} for linode_group in self.linode_groups: self.inventory.add_group(linode_group) diff --git a/plugins/module_utils/utm_utils.py b/plugins/module_utils/utm_utils.py index 571d1e1851..2e7432fb38 100644 --- a/plugins/module_utils/utm_utils.py +++ b/plugins/module_utils/utm_utils.py @@ -183,7 +183,7 @@ class UTM: result = None if response is not None: results = json.loads(response.read()) - result = next(iter([d for d in results if d['name'] == module.params.get('name')]), None) + result = next((d for d in results if d['name'] == module.params.get('name')), None) return info, result def _clean_result(self, result): diff --git a/plugins/module_utils/vexata.py b/plugins/module_utils/vexata.py index 8334d0506e..ed0b11480c 100644 --- a/plugins/module_utils/vexata.py +++ b/plugins/module_utils/vexata.py @@ -20,10 +20,9 @@ VXOS_VERSION = None def get_version(iocs_json): if not iocs_json: raise Exception('Invalid IOC json') - active = [x for x in iocs_json if x['mgmtRole']] - if not active: + active = next((x for x in iocs_json if x['mgmtRole']), None) + if active is None: raise Exception('Unable to detect active IOC') - active = active[0] ver = active['swVersion'] if ver[0] != 'v': raise Exception('Illegal version string')