From f53ca3ad39ad7b6716d059ae5624df79474a3387 Mon Sep 17 00:00:00 2001 From: Rafael Guterres Jeffman Date: Wed, 22 May 2024 10:04:22 -0300 Subject: [PATCH] pylint: Ignore usage of 'unicode' before assignment New versions of pylint ignore Python 2 functions and types, evaluating 'unicode' as "undefined". ansible-freeipa will always define 'unicode' when running under Python 3, and it is always defined under Python 2. This patch fixes these false positives. --- plugins/module_utils/ansible_freeipa_module.py | 5 ++++- plugins/modules/ipagroup.py | 4 +++- plugins/modules/ipahost.py | 2 +- plugins/modules/iparole.py | 2 +- plugins/modules/ipaservice.py | 2 +- plugins/modules/ipauser.py | 2 +- roles/ipareplica/library/ipareplica_add_to_ipaservers.py | 2 +- roles/ipareplica/library/ipareplica_prepare.py | 2 +- 8 files changed, 13 insertions(+), 8 deletions(-) diff --git a/plugins/module_utils/ansible_freeipa_module.py b/plugins/module_utils/ansible_freeipa_module.py index 16b4fa810e..8675beee9a 100644 --- a/plugins/module_utils/ansible_freeipa_module.py +++ b/plugins/module_utils/ansible_freeipa_module.py @@ -487,7 +487,10 @@ def module_params_get(module, name, allow_empty_list_item=False): # Ansible issue https://github.com/ansible/ansible/issues/77108 if isinstance(value, list): for val in value: - if isinstance(val, (str, unicode)) and not val: + if ( + isinstance(val, (str, unicode)) # pylint: disable=E0606 + and not val + ): if not allow_empty_list_item: module.fail_json( msg="Parameter '%s' contains an empty string" % diff --git a/plugins/modules/ipagroup.py b/plugins/modules/ipagroup.py index dcb1f3a361..1ffdef9deb 100644 --- a/plugins/modules/ipagroup.py +++ b/plugins/modules/ipagroup.py @@ -663,7 +663,9 @@ def main(): check_parameters(ansible_module, state, action) - elif isinstance(group_name, (str, unicode)): + elif ( + isinstance(group_name, (str, unicode)) # pylint: disable=E0606 + ): name = group_name else: ansible_module.fail_json(msg="Group '%s' is not valid" % diff --git a/plugins/modules/ipahost.py b/plugins/modules/ipahost.py index a1d2142365..86336c4613 100644 --- a/plugins/modules/ipahost.py +++ b/plugins/modules/ipahost.py @@ -988,7 +988,7 @@ def main(): sshpubkey = [str(normalize_sshpubkey(key)) for key in sshpubkey] - elif isinstance(host, (str, unicode)): + elif isinstance(host, (str, unicode)): # pylint: disable=E0606 name = host else: ansible_module.fail_json(msg="Host '%s' is not valid" % diff --git a/plugins/modules/iparole.py b/plugins/modules/iparole.py index 2e87626802..25017e7669 100644 --- a/plugins/modules/iparole.py +++ b/plugins/modules/iparole.py @@ -293,7 +293,7 @@ def result_get_value_lowercase(res_find, key, default=None): if existing is not None: if isinstance(existing, (list, tuple)): existing = [to_text(item).lower() for item in existing] - if isinstance(existing, (str, unicode)): + if isinstance(existing, (str, unicode)): # pylint: disable=E0606 existing = existing.lower() else: existing = default diff --git a/plugins/modules/ipaservice.py b/plugins/modules/ipaservice.py index 1a4fd7146c..8326d4228a 100644 --- a/plugins/modules/ipaservice.py +++ b/plugins/modules/ipaservice.py @@ -693,7 +693,7 @@ def main(): delete_continue = service.get("delete_continue") - elif isinstance(service, (str, unicode)): + elif isinstance(service, (str, unicode)): # pylint: disable=E0606 name = service else: ansible_module.fail_json(msg="Service '%s' is not valid" % diff --git a/plugins/modules/ipauser.py b/plugins/modules/ipauser.py index 8c8bb436c3..d7c18082d7 100644 --- a/plugins/modules/ipauser.py +++ b/plugins/modules/ipauser.py @@ -1382,7 +1382,7 @@ def main(): email = extend_emails(email, default_email_domain) - elif isinstance(user, (str, unicode)): + elif isinstance(user, (str, unicode)): # pylint: disable=E0606 name = user else: ansible_module.fail_json(msg="User '%s' is not valid" % diff --git a/roles/ipareplica/library/ipareplica_add_to_ipaservers.py b/roles/ipareplica/library/ipareplica_add_to_ipaservers.py index 66c1615b17..6fb8b1f921 100644 --- a/roles/ipareplica/library/ipareplica_add_to_ipaservers.py +++ b/roles/ipareplica/library/ipareplica_add_to_ipaservers.py @@ -139,7 +139,7 @@ def main(): conn.connect(ccache=installer._ccache) remote_api.Command['hostgroup_add_member']( u'ipaservers', - host=[unicode(api.env.host)], + host=[unicode(api.env.host)], # pylint: disable=E0606 ) finally: if conn.isconnected(): diff --git a/roles/ipareplica/library/ipareplica_prepare.py b/roles/ipareplica/library/ipareplica_prepare.py index 9624324072..5d9fd2d546 100644 --- a/roles/ipareplica/library/ipareplica_prepare.py +++ b/roles/ipareplica/library/ipareplica_prepare.py @@ -658,7 +658,7 @@ def main(): # Check authorization result = remote_api.Command['hostgroup_find']( cn=u'ipaservers', - host=[unicode(api.env.host)] + host=[unicode(api.env.host)] # pylint: disable=E0606 )['result'] add_to_ipaservers = not result