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 <flo@redhat.com>
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Florence Blanc-Renaud 2023-11-29 11:13:55 +01:00
parent 7f485ba7dc
commit 8d7bd6c6ab
11 changed files with 18 additions and 5 deletions

View File

@ -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']):

View File

@ -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))

View File

@ -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)

View File

@ -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'))

View File

@ -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'])

View File

@ -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 '

View File

@ -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)

View File

@ -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 '

View File

@ -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)

View File

@ -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):

View File

@ -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)