From 8d7bd6c6ab68a4ef3fed2620ef8e07a03aa92d34 Mon Sep 17 00:00:00 2001 From: Florence Blanc-Renaud Date: Wed, 29 Nov 2023 11:13:55 +0100 Subject: [PATCH] pylint: fix errors Fix the following errors: I0021(useless-suppression) R1710(inconsistent-return-statements) E1101(no-member) Ignore the following errors: E0601(used-before-assignment) The variable is imported when the code is run in_server. Signed-off-by: Florence Blanc-Renaud Reviewed-By: Alexander Bokovoy Reviewed-By: Rob Crittenden --- ipaclient/remote_plugins/schema.py | 2 +- ipalib/base.py | 2 +- ipaserver/install/certs.py | 2 +- ipaserver/plugins/group.py | 2 ++ ipaserver/plugins/hbactest.py | 2 ++ ipaserver/plugins/idrange.py | 2 ++ ipaserver/plugins/idviews.py | 2 ++ ipaserver/plugins/trust.py | 2 ++ ipaserver/plugins/vault.py | 2 ++ ipatests/pytest_ipa/integration/tasks.py | 1 + ipatests/test_xmlrpc/test_certmap_plugin.py | 4 ++-- 11 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ipaclient/remote_plugins/schema.py b/ipaclient/remote_plugins/schema.py index 324763c46..2306ac7a6 100644 --- a/ipaclient/remote_plugins/schema.py +++ b/ipaclient/remote_plugins/schema.py @@ -584,7 +584,7 @@ def get_package(server_info, client): for plugin_cls in (_SchemaCommandPlugin, _SchemaObjectPlugin): for full_name in schema[plugin_cls.schema_key]: plugin = plugin_cls(schema, str(full_name)) - plugin = module.register()(plugin) + plugin = module.register()(plugin) # pylint: disable=no-member sys.modules[module_name] = module for full_name, topic in six.iteritems(schema['topics']): diff --git a/ipalib/base.py b/ipalib/base.py index d8f9ee728..2970bb188 100644 --- a/ipalib/base.py +++ b/ipalib/base.py @@ -469,7 +469,7 @@ class NameSpace(ReadOnly): if isinstance(key, str): return self.__map[key] if type(key) in (int, slice): - return self.__members[key] # pylint: disable=invalid-sequence-index + return self.__members[key] raise TypeError( TYPE_ERROR % ('key', (str, int, slice, 'object with __name__'), key, type(key)) diff --git a/ipaserver/install/certs.py b/ipaserver/install/certs.py index 8d9fe8c48..e2e995640 100644 --- a/ipaserver/install/certs.py +++ b/ipaserver/install/certs.py @@ -786,7 +786,7 @@ class _CrossProcessLock: def _read(self, fileobj): p = configparser.RawConfigParser() if six.PY2: - p.readfp(fileobj) # pylint: disable=deprecated-method + p.readfp(fileobj) # pylint: disable=no-member else: p.read_file(fileobj) diff --git a/ipaserver/plugins/group.py b/ipaserver/plugins/group.py index 23cf3f5c5..f05a39f69 100644 --- a/ipaserver/plugins/group.py +++ b/ipaserver/plugins/group.py @@ -649,7 +649,9 @@ class group_add_member(LDAPAddMember): raise errors.NotFound(reason=_('Cannot perform external member validation without ' 'Samba 4 support installed. Make sure you have installed ' 'server-trust-ad sub-package of IPA on the server')) + # pylint: disable=used-before-assignment domain_validator = ipaserver.dcerpc.DomainValidator(self.api) + # pylint: enable=used-before-assignment if not domain_validator.is_configured(): raise errors.NotFound(reason=_('Cannot perform join operation without own domain configured. ' 'Make sure you have run ipa-adtrust-install on the IPA server first')) diff --git a/ipaserver/plugins/hbactest.py b/ipaserver/plugins/hbactest.py index 568c13174..fe97293e1 100644 --- a/ipaserver/plugins/hbactest.py +++ b/ipaserver/plugins/hbactest.py @@ -400,7 +400,9 @@ class hbactest(Command): if options['user'] != u'all': # check first if this is not a trusted domain user if _dcerpc_bindings_installed: + # pylint: disable=used-before-assignment is_valid_sid = ipaserver.dcerpc.is_sid_valid(options['user']) + # pylint: enable=used-before-assignment else: is_valid_sid = False components = util.normalize_name(options['user']) diff --git a/ipaserver/plugins/idrange.py b/ipaserver/plugins/idrange.py index 3eca90a5b..30a018e43 100644 --- a/ipaserver/plugins/idrange.py +++ b/ipaserver/plugins/idrange.py @@ -343,7 +343,9 @@ class idrange(LDAPObject): 'without Samba 4 support installed. Make sure you have ' 'installed server-trust-ad sub-package of IPA on the server')) + # pylint: disable=used-before-assignment domain_validator = ipaserver.dcerpc.DomainValidator(self.api) + # pylint: enable=used-before-assignment if not domain_validator.is_configured(): raise errors.NotFound(reason=_('Cross-realm trusts are not ' diff --git a/ipaserver/plugins/idviews.py b/ipaserver/plugins/idviews.py index 6a16884cf..ee05ba162 100644 --- a/ipaserver/plugins/idviews.py +++ b/ipaserver/plugins/idviews.py @@ -617,7 +617,9 @@ def resolve_object_to_anchor(ldap, obj_type, obj, fallback_to_ldap): # If not successful, try looking up the object in the trusted domain try: if _dcerpc_bindings_installed: + # pylint: disable=used-before-assignment domain_validator = ipaserver.dcerpc.DomainValidator(api) + # pylint: enable=used-before-assignment if domain_validator.is_configured(): sid = domain_validator.get_trusted_domain_object_sid(obj, fallback_to_ldap=fallback_to_ldap) diff --git a/ipaserver/plugins/trust.py b/ipaserver/plugins/trust.py index 79264b8d8..9c4bb5f8b 100644 --- a/ipaserver/plugins/trust.py +++ b/ipaserver/plugins/trust.py @@ -339,7 +339,9 @@ def add_range(myapi, trustinstance, range_name, dom_sid, *keys, **options): + basedn # Get the domain validator + # pylint: disable=used-before-assignment domain_validator = ipaserver.dcerpc.DomainValidator(myapi) + # pylint: enable=used-before-assignment if not domain_validator.is_configured(): raise errors.NotFound( reason=_('Cannot search in trusted domains without own ' diff --git a/ipaserver/plugins/vault.py b/ipaserver/plugins/vault.py index 574c83a9a..a47cf7bd3 100644 --- a/ipaserver/plugins/vault.py +++ b/ipaserver/plugins/vault.py @@ -841,7 +841,9 @@ class vault_del(LDAPDelete): assert isinstance(dn, DN) with self.api.Backend.kra.get_client() as kra_client: + # pylint: disable=used-before-assignment kra_account = pki.account.AccountClient(kra_client.connection) + # pylint: enable=used-before-assignment kra_account.login() client_key_id = self.obj.get_key_id(dn) diff --git a/ipatests/pytest_ipa/integration/tasks.py b/ipatests/pytest_ipa/integration/tasks.py index 3dd32cfc5..ee6dec7a1 100755 --- a/ipatests/pytest_ipa/integration/tasks.py +++ b/ipatests/pytest_ipa/integration/tasks.py @@ -1614,6 +1614,7 @@ def resolve_record(nameserver, query, rtype="SOA", retry=True, timeout=100): if not retry: raise time.sleep(1) + raise errors.DNSResolverError(exception=ValueError("Record not found")) def ipa_backup(host, disable_role_check=False, raiseonerr=True): diff --git a/ipatests/test_xmlrpc/test_certmap_plugin.py b/ipatests/test_xmlrpc/test_certmap_plugin.py index 29ed8ded3..071a5a182 100644 --- a/ipatests/test_xmlrpc/test_certmap_plugin.py +++ b/ipatests/test_xmlrpc/test_certmap_plugin.py @@ -302,7 +302,7 @@ class EWE: self.value = None self.change_principal_cm = change_principal(self.user, self.password) - self.change_principal_cm.__enter__() # pylint: disable=no-member + self.change_principal_cm.__enter__() if self.exception: self.assert_raises_cm = pytest.raises(self.exception) @@ -311,7 +311,7 @@ class EWE: return self def __exit__(self, exc_type, exc_value, tb): - self.change_principal_cm.__exit__( # pylint: disable=no-member + self.change_principal_cm.__exit__( exc_type, exc_value, tb) if self.exception: return self.assert_raises_cm.__exit__(exc_type, exc_value, tb)