mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-07-29 15:55:47 -05:00
Fix Pylint 2.0 violations
Fix the following violations aiming to support Pylint 2.0 - `unneeded-not` (C0113): Consider changing "not item in items" to "item not in items" used when a boolean expression contains an unneeded negation. - `useless-import-alias` (C0414): Import alias does not rename original package Used when an import alias is same as original package.e.g using import numpy as numpy instead of import numpy as np - `raising-format-tuple` (W0715): Exception arguments suggest string formatting might be intended Used when passing multiple arguments to an exception constructor, the first of them a string literal containing what appears to be placeholders intended for formatting - `bad-continuation` (C0330): This was already included on the disable list, although with current version of pylint (2.0.0.dev2) violations at the end of the files are not being ignored. See: https://github.com/PyCQA/pylint/issues/2278 - `try-except-raise` (E0705): The except handler raises immediately Used when an except handler uses raise as its first or only operator. This is useless because it raises back the exception immediately. Remove the raise operator or the entire try-except-raise block! - `consider-using-set-comprehension` (R1718): Consider using a set comprehension Although there is nothing syntactically wrong with this code, it is hard to read and can be simplified to a set comprehension.Also it is faster since you don't need to create another transient list - `dict-keys-not-iterating` (W1655): dict.keys referenced when not iterating Used when dict.keys is referenced in a non-iterating context (returns an iterator in Python 3) - `comprehension-escape` (W1662): Using a variable that was bound inside a comprehension Emitted when using a variable, that was bound in a comprehension handler, outside of the comprehension itself. On Python 3 these variables will be deleted outside of the comprehension. Issue: https://pagure.io/freeipa/issue/7614 Signed-off-by: Armando Neto <abiagion@redhat.com> Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
committed by
Christian Heimes
parent
aacf185ff8
commit
d13571942e
@@ -28,8 +28,9 @@ register = Registry()
|
|||||||
@register(override=True, no_fail=True)
|
@register(override=True, no_fail=True)
|
||||||
class automember_add_condition(MethodOverride):
|
class automember_add_condition(MethodOverride):
|
||||||
has_output_params = (
|
has_output_params = (
|
||||||
Str('failed',
|
Str(
|
||||||
label=_('Failed to add'),
|
'failed',
|
||||||
flags=['suppress_empty'],
|
label=_('Failed to add'),
|
||||||
|
flags=['suppress_empty'],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -669,9 +669,8 @@ class ModVaultData(Local):
|
|||||||
|
|
||||||
name = self.name + '_internal'
|
name = self.name + '_internal'
|
||||||
try:
|
try:
|
||||||
|
# ipalib.errors.NotFound exception can be propagated
|
||||||
return self.api.Command[name](*args, **options)
|
return self.api.Command[name](*args, **options)
|
||||||
except errors.NotFound:
|
|
||||||
raise
|
|
||||||
except (errors.InternalError,
|
except (errors.InternalError,
|
||||||
errors.ExecutionError,
|
errors.ExecutionError,
|
||||||
errors.GenericError):
|
errors.GenericError):
|
||||||
|
|||||||
+1
-1
@@ -139,7 +139,7 @@ class Executioner(Backend):
|
|||||||
if _name not in self.Command:
|
if _name not in self.Command:
|
||||||
raise CommandError(name=_name)
|
raise CommandError(name=_name)
|
||||||
return self.Command[_name](*args, **options)
|
return self.Command[_name](*args, **options)
|
||||||
except PublicError:
|
except PublicError: # pylint: disable=try-except-raise
|
||||||
raise
|
raise
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
|
|||||||
@@ -1071,9 +1071,11 @@ class RPCClient(Connectible):
|
|||||||
)
|
)
|
||||||
# We don't care about the response, just that we got one
|
# We don't care about the response, just that we got one
|
||||||
return serverproxy
|
return serverproxy
|
||||||
|
# pylint: disable=try-except-raise
|
||||||
except errors.KerberosError:
|
except errors.KerberosError:
|
||||||
# kerberos error on one server is likely on all
|
# kerberos error on one server is likely on all
|
||||||
raise
|
raise
|
||||||
|
# pylint: enable=try-except-raise
|
||||||
except ProtocolError as e:
|
except ProtocolError as e:
|
||||||
if hasattr(context, 'session_cookie') and e.errcode == 401:
|
if hasattr(context, 'session_cookie') and e.errcode == 401:
|
||||||
# Unauthorized. Remove the session and try again.
|
# Unauthorized. Remove the session and try again.
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ class SystemdService(PlatformService):
|
|||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
svar = self.parse_variables(result.output)
|
svar = self.parse_variables(result.output)
|
||||||
if not self.service_instance("") in svar:
|
if self.service_instance("") not in svar:
|
||||||
# systemd doesn't show the service
|
# systemd doesn't show the service
|
||||||
return False
|
return False
|
||||||
except ipautil.CalledProcessError:
|
except ipautil.CalledProcessError:
|
||||||
|
|||||||
@@ -310,8 +310,6 @@ class Configurable(six.with_metaclass(abc.ABCMeta, object)):
|
|||||||
prop = prop_cls(self)
|
prop = prop_cls(self)
|
||||||
try:
|
try:
|
||||||
prop.validate(value)
|
prop.validate(value)
|
||||||
except KnobValueError:
|
|
||||||
raise
|
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise KnobValueError(name, str(e))
|
raise KnobValueError(name, str(e))
|
||||||
|
|
||||||
|
|||||||
@@ -208,11 +208,10 @@ class SchemaCache(object):
|
|||||||
info = e.args[0].get('info', '').strip()
|
info = e.args[0].get('info', '').strip()
|
||||||
raise errors.DatabaseError(desc = u'uri=%s' % url,
|
raise errors.DatabaseError(desc = u'uri=%s' % url,
|
||||||
info = u'Unable to retrieve LDAP schema: %s: %s' % (desc, info))
|
info = u'Unable to retrieve LDAP schema: %s: %s' % (desc, info))
|
||||||
except IndexError:
|
|
||||||
# no 'cn=schema' entry in LDAP? some servers use 'cn=subschema'
|
# no 'cn=schema' entry in LDAP? some servers use 'cn=subschema'
|
||||||
# TODO: DS uses 'cn=schema', support for other server?
|
# TODO: DS uses 'cn=schema', support for other server?
|
||||||
# raise a more appropriate exception
|
# raise a more appropriate exception
|
||||||
raise
|
|
||||||
|
|
||||||
return ldap.schema.SubSchema(schema_entry[1])
|
return ldap.schema.SubSchema(schema_entry[1])
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -68,7 +68,7 @@ from time import sleep
|
|||||||
try:
|
try:
|
||||||
from ldap.controls import RequestControl as LDAPControl
|
from ldap.controls import RequestControl as LDAPControl
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from ldap.controls import LDAPControl as LDAPControl
|
from ldap.controls import LDAPControl
|
||||||
|
|
||||||
if six.PY3:
|
if six.PY3:
|
||||||
unicode = str
|
unicode = str
|
||||||
@@ -1726,8 +1726,8 @@ class TrustDomainJoins(object):
|
|||||||
self.local_domain.establish_trust(self.remote_domain,
|
self.local_domain.establish_trust(self.remote_domain,
|
||||||
trustdom_passwd,
|
trustdom_passwd,
|
||||||
trust_type, trust_external)
|
trust_type, trust_external)
|
||||||
return dict(
|
return {
|
||||||
local=self.local_domain,
|
'local': self.local_domain,
|
||||||
remote=self.remote_domain,
|
'remote': self.remote_domain,
|
||||||
verified=False
|
'verified': False,
|
||||||
)
|
}
|
||||||
|
|||||||
+5
-10
@@ -467,16 +467,11 @@ p11_kit_uri_free = _libp11_kit.p11_kit_uri_free
|
|||||||
def loadLibrary(module):
|
def loadLibrary(module):
|
||||||
"""Load the PKCS#11 library"""
|
"""Load the PKCS#11 library"""
|
||||||
# Load PKCS #11 library
|
# Load PKCS #11 library
|
||||||
try:
|
if module:
|
||||||
if module:
|
# pylint: disable=no-member
|
||||||
# pylint: disable=no-member
|
pDynLib = _ffi.dlopen(module, _ffi.RTLD_NOW | _ffi.RTLD_LOCAL)
|
||||||
pDynLib = _ffi.dlopen(module, _ffi.RTLD_NOW | _ffi.RTLD_LOCAL)
|
else:
|
||||||
else:
|
raise Exception()
|
||||||
raise Exception()
|
|
||||||
|
|
||||||
except Exception:
|
|
||||||
# Failed to load the PKCS #11 library
|
|
||||||
raise
|
|
||||||
|
|
||||||
# Retrieve the entry point for C_GetFunctionList
|
# Retrieve the entry point for C_GetFunctionList
|
||||||
pGetFunctionList = pDynLib.C_GetFunctionList
|
pGetFunctionList = pDynLib.C_GetFunctionList
|
||||||
|
|||||||
@@ -1073,7 +1073,9 @@ last, after all sets and adds."""),
|
|||||||
entry_attrs[attr] = value
|
entry_attrs[attr] = value
|
||||||
else:
|
else:
|
||||||
# unknown attribute: remove duplicite and invalid values
|
# unknown attribute: remove duplicite and invalid values
|
||||||
entry_attrs[attr] = list(set([val for val in entry_attrs[attr] if val]))
|
entry_attrs[attr] = list(
|
||||||
|
{val for val in entry_attrs[attr] if val}
|
||||||
|
)
|
||||||
if not entry_attrs[attr]:
|
if not entry_attrs[attr]:
|
||||||
entry_attrs[attr] = None
|
entry_attrs[attr] = None
|
||||||
elif isinstance(entry_attrs[attr], (tuple, list)) and len(entry_attrs[attr]) == 1:
|
elif isinstance(entry_attrs[attr], (tuple, list)) and len(entry_attrs[attr]) == 1:
|
||||||
@@ -2343,7 +2345,9 @@ class BaseLDAPModAttribute(LDAPQuery):
|
|||||||
return arg.clone(required=True, attribute=attribute, alwaysask=True)
|
return arg.clone(required=True, attribute=attribute, alwaysask=True)
|
||||||
|
|
||||||
def _update_attrs(self, update, entry_attrs):
|
def _update_attrs(self, update, entry_attrs):
|
||||||
raise NotImplementedError("%s.update_attrs()", self.__class__.__name__)
|
raise NotImplementedError(
|
||||||
|
"%s.update_attrs()" % self.__class__.__name__
|
||||||
|
)
|
||||||
|
|
||||||
def execute(self, *keys, **options):
|
def execute(self, *keys, **options):
|
||||||
ldap = self.obj.backend
|
ldap = self.obj.backend
|
||||||
|
|||||||
@@ -226,7 +226,7 @@ class krbtpolicy_reset(baseldap.LDAPQuery):
|
|||||||
else:
|
else:
|
||||||
def_values = _default_values
|
def_values = _default_values
|
||||||
|
|
||||||
entry = ldap.get_entry(dn, def_values.keys())
|
entry = ldap.get_entry(dn, list(def_values))
|
||||||
entry.update(def_values)
|
entry.update(def_values)
|
||||||
try:
|
try:
|
||||||
ldap.update_entry(entry)
|
ldap.update_entry(entry)
|
||||||
|
|||||||
@@ -242,7 +242,8 @@ class privilege_remove_permission(LDAPRemoveReverseMember):
|
|||||||
type=dict,
|
type=dict,
|
||||||
doc=_('Members that could not be added'),
|
doc=_('Members that could not be added'),
|
||||||
),
|
),
|
||||||
output.Output('completed',
|
output.Output(
|
||||||
|
'completed',
|
||||||
type=int,
|
type=int,
|
||||||
doc=_('Number of permissions removed'),
|
doc=_('Number of permissions removed'),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -240,11 +240,13 @@ class role_remove_privilege(LDAPRemoveReverseMember):
|
|||||||
|
|
||||||
has_output = (
|
has_output = (
|
||||||
output.Entry('result'),
|
output.Entry('result'),
|
||||||
output.Output('failed',
|
output.Output(
|
||||||
|
'failed',
|
||||||
type=dict,
|
type=dict,
|
||||||
doc=_('Members that could not be added'),
|
doc=_('Members that could not be added'),
|
||||||
),
|
),
|
||||||
output.Output('completed',
|
output.Output(
|
||||||
|
'completed',
|
||||||
type=int,
|
type=int,
|
||||||
doc=_('Number of privileges removed'),
|
doc=_('Number of privileges removed'),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -832,8 +832,9 @@ class user_find(baseuser_find):
|
|||||||
DN(self.obj.active_container_dn, self.api.env.basedn),
|
DN(self.obj.active_container_dn, self.api.env.basedn),
|
||||||
DN(self.obj.delete_container_dn, self.api.env.basedn),
|
DN(self.obj.delete_container_dn, self.api.env.basedn),
|
||||||
)
|
)
|
||||||
entries[:] = [e for e in entries
|
entries[:] = list(
|
||||||
if any(e.dn.endswith(bd) for bd in base_dns)]
|
e for e in entries if any(e.dn.endswith(bd) for bd in base_dns)
|
||||||
|
)
|
||||||
|
|
||||||
self.post_common_callback(ldap, entries, lockout=False, **options)
|
self.post_common_callback(ldap, entries, lockout=False, **options)
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ disable=
|
|||||||
useless-super-delegation, # new in pylint 1.7
|
useless-super-delegation, # new in pylint 1.7
|
||||||
redefined-argument-from-local, # new in pylint 1.7
|
redefined-argument-from-local, # new in pylint 1.7
|
||||||
consider-merging-isinstance, # new in pylint 1.7
|
consider-merging-isinstance, # new in pylint 1.7
|
||||||
|
bad-option-value, # required to support upgrade to pylint 2.0
|
||||||
|
|
||||||
|
|
||||||
[REPORTS]
|
[REPORTS]
|
||||||
|
|||||||
Reference in New Issue
Block a user