Skip to content

Commit

Permalink
pylint: Fix useless-suppression
Browse files Browse the repository at this point in the history
Cleanup up no longer used Pylint's disables where possible.

Fixes: https://pagure.io/freeipa/issue/9117
Signed-off-by: Stanislav Levin <[email protected]>
Reviewed-By: Rob Crittenden <[email protected]>
  • Loading branch information
stanislavlevin authored and rcritten committed Mar 11, 2022
1 parent ac6fe01 commit 5a00882
Show file tree
Hide file tree
Showing 80 changed files with 131 additions and 204 deletions.
2 changes: 1 addition & 1 deletion daemons/ipa-otpd/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def main():
rsp.DecodePacket(buf)
pkt.VerifyReply(rsp)

proc.terminate() # pylint: disable=E1101
proc.terminate()
proc.wait()

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion install/certmonger/dogtag-ipa-ca-renew-agent-submit.in
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def request_cert(reuse_existing, **kwargs):
sys.stderr.write(result.raw_error_output)
else:
# Write bytes directly
sys.stderr.buffer.write(result.raw_error_output) #pylint: disable=no-member
sys.stderr.buffer.write(result.raw_error_output)
sys.stderr.flush()

syslog.syslog(syslog.LOG_NOTICE,
Expand Down
4 changes: 2 additions & 2 deletions install/certmonger/ipa-server-guard.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def run_operation(cmd):

result = ipautil.run(cmd, raiseonerr=False, env=os.environ)
# Write bytes directly
sys.stdout.buffer.write(result.raw_output) #pylint: disable=no-member
sys.stderr.buffer.write(result.raw_error_output) #pylint: disable=no-member
sys.stdout.buffer.write(result.raw_output)
sys.stderr.buffer.write(result.raw_error_output)
sys.stdout.flush()
sys.stderr.flush()

Expand Down
1 change: 0 additions & 1 deletion install/tools/ipa-pki-retrieve-key.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def main():
"File '{}' missing or not readable.\n".format(filename)
)

# pylint: disable=no-member
client = CustodiaClient(
client_service="{}@{}".format(service, env.host),
server=args.servername,
Expand Down
4 changes: 2 additions & 2 deletions install/tools/ipa-replica-conncheck.in
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class PortResponder(threading.Thread):
logger.debug('%d %s: Stopped listening', port, proto)

def _is_closing(self):
with self._close_lock: # pylint: disable=not-context-manager
with self._close_lock:
return self._close

def _bind_to_port(self, port, socket_type):
Expand Down Expand Up @@ -370,7 +370,7 @@ class PortResponder(threading.Thread):
def stop(self):
logger.debug('Stopping listening thread.')

with self._close_lock: # pylint: disable=not-context-manager
with self._close_lock:
self._close = True


Expand Down
3 changes: 1 addition & 2 deletions ipaclient/install/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3667,7 +3667,7 @@ def init(installer):
root_logger = logging.getLogger()
for handler in root_logger.handlers:
if (isinstance(handler, logging.StreamHandler) and
handler.stream is sys.stderr): # pylint: disable=no-member
handler.stream is sys.stderr):
installer.debug = handler.level == logging.DEBUG
break
else:
Expand Down Expand Up @@ -3749,7 +3749,6 @@ class ClientInstallInterface(hostname_.HostNameInstallInterface,
force_join = enroll_only(force_join)

ntp_servers = knob(
# pylint: disable=invalid-sequence-index
typing.List[str], None,
description="ntp server to use. This option can be used multiple "
"times",
Expand Down
4 changes: 2 additions & 2 deletions ipaclient/install/ipa_certupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ def run_with_args(api):

update_server(certs)

# pylint: disable=import-error,ipa-forbidden-import
# pylint: disable=ipa-forbidden-import
from ipaserver.install import cainstance, custodiainstance
# pylint: enable=import-error,ipa-forbidden-import
# pylint: enable=ipa-forbidden-import

# Add LWCA tracking requests. Only execute if *this server*
# has CA installed (ca_enabled indicates CA-ful topology).
Expand Down
2 changes: 0 additions & 2 deletions ipaclient/install/ipa_client_automount.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
from xml.etree import ElementTree as etree
import SSSDConfig

# pylint: disable=import-error
from six.moves.urllib.parse import urlsplit

# pylint: enable=import-error
from optparse import OptionParser # pylint: disable=deprecated-module
from ipapython import ipachangeconf
from ipaclient.install import ipadiscovery
Expand Down
4 changes: 0 additions & 4 deletions ipaclient/plugins/otptoken.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def __inner(self, host, **kwargs):
return create_https_connection(host, **tmp)

def https_open(self, req):
# pylint: disable=no-member
return self.do_open(self.__inner, req)

@register()
Expand All @@ -156,8 +155,6 @@ def forward(self, *args, **kwargs):
segments = list(urllib.parse.urlparse(self.api.env.xmlrpc_uri))
assert segments[0] == 'https' # Ensure encryption.
segments[2] = segments[2].replace('/xml', '/session/sync_token')
# urlunparse *can* take one argument
# pylint: disable=too-many-function-args
sync_uri = urllib.parse.urlunparse(segments)

# Prepare the query.
Expand All @@ -170,7 +167,6 @@ def forward(self, *args, **kwargs):
query = query.encode('utf-8')

# Sync the token.
# pylint: disable=E1101
handler = HTTPSHandler(
cafile=api.env.tls_ca_cert,
tls_version_min=api.env.tls_version_min,
Expand Down
3 changes: 3 additions & 0 deletions ipaclient/remote_plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ def is_valid(self):

def get_package(api):
if api.env.in_tree:
# server packages are not published on pypi.org
# pylint: disable=useless-suppression
# pylint: disable=import-error,ipa-forbidden-import
from ipaserver import plugins
# pylint: enable=import-error,ipa-forbidden-import
# pylint: enable=useless-suppression
else:
try:
plugins = api._remote_plugins
Expand Down
4 changes: 2 additions & 2 deletions ipaclient/remote_plugins/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def iter_namespace(self, namespace):
def get_help(self, namespace, member):
if isinstance(self._help, bytes):
self._help = json.loads(
self._help.decode('utf-8') # pylint: disable=no-member
self._help.decode('utf-8')
)

return self._help[namespace][member]
Expand Down Expand Up @@ -585,7 +585,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) # pylint: disable=no-member
plugin = module.register()(plugin)
sys.modules[module_name] = module

for full_name, topic in six.iteritems(schema['topics']):
Expand Down
8 changes: 7 additions & 1 deletion ipalib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ def _enable_warnings(error=False):
import warnings

# get reference to Py_BytesWarningFlag from Python CAPI
byteswarnings = ctypes.c_int.in_dll( # pylint: disable=no-member
byteswarnings = ctypes.c_int.in_dll(
ctypes.pythonapi, 'Py_BytesWarningFlag')

if byteswarnings.value >= 2:
Expand Down Expand Up @@ -936,9 +936,12 @@ class API(plugable.API):
@property
def packages(self):
if self.env.in_server:
# server packages are not published on pypi.org
# pylint: disable=useless-suppression
# pylint: disable=import-error,ipa-forbidden-import
import ipaserver.plugins
# pylint: enable=import-error,ipa-forbidden-import
# pylint: enable=useless-suppression
result = (
ipaserver.plugins,
)
Expand All @@ -951,9 +954,12 @@ def packages(self):
)

if self.env.context in ('installer', 'updates'):
# server packages are not published on pypi.org
# pylint: disable=useless-suppression
# pylint: disable=import-error,ipa-forbidden-import
import ipaserver.install.plugins
# pylint: enable=import-error,ipa-forbidden-import
# pylint: enable=useless-suppression
result += (ipaserver.install.plugins,)

return result
Expand Down
2 changes: 1 addition & 1 deletion ipalib/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def execute(self, _name, *args, **options):
if _name not in self.Command:
raise CommandError(name=_name)
return self.Command[_name](*args, **options)
except PublicError: # pylint: disable=try-except-raise
except PublicError:
raise
except Exception as e:
logger.exception(
Expand Down
10 changes: 4 additions & 6 deletions ipalib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from ipalib.constants import CLI_TAB, LDAP_GENERALIZED_TIME_FORMAT
from ipalib.parameters import File, BinaryFile, Str, Enum, Any, Flag
from ipalib.text import _
from ipalib import api # pylint: disable=unused-import
from ipalib import api
from ipapython.dnsutil import DNSName
from ipapython.admintool import ScriptError

Expand Down Expand Up @@ -609,7 +609,7 @@ def prompt_yesno(self, label, default=None):
prompt = u'%s Yes/No: ' % label

while True:
data = self.prompt_helper(prompt, label).lower() #pylint: disable=E1103
data = self.prompt_helper(prompt, label).lower()

if data in (u'yes', u'y'):
return True
Expand Down Expand Up @@ -680,9 +680,9 @@ def select_entry(self, entries, format, attrs, display_count=True):
except EOFError:
return -2

if resp.lower() == "q": #pylint: disable=E1103
if resp.lower() == "q":
return -2
if resp.lower() == "a": #pylint: disable=E1103
if resp.lower() == "a":
return -1
try:
selection = int(resp) - 1
Expand Down Expand Up @@ -1411,9 +1411,7 @@ def load_files(self, cmd, kw):
elif p.stdin_if_missing:
try:
if six.PY3 and p.type is bytes:
# pylint: disable=no-member
raw = sys.stdin.buffer.read()
# pylint: enable=no-member
else:
raw = sys.stdin.read()
except IOError as e:
Expand Down
6 changes: 2 additions & 4 deletions ipalib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ def __setitem__(self, key, value):
if type(value) not in (unicode, int, float, bool, type(None), DN):
raise TypeError(key, value)
object.__setattr__(self, key, value)
# pylint: disable=unsupported-assignment-operation, no-member
# pylint: disable=no-member
self.__d[key] = value
# pylint: enable=unsupported-assignment-operation, no-member
# pylint: enable=no-member

def __getitem__(self, key):
"""
Expand Down Expand Up @@ -600,12 +600,10 @@ def _finalize_core(self, **defaults):
# and server from jsonrpc_uri so that when only server or xmlrpc_uri
# is specified, all 3 keys have a value.)
if 'xmlrpc_uri' not in self and 'server' in self:
# pylint: disable=no-member, access-member-before-definition
self.xmlrpc_uri = 'https://{}/ipa/xml'.format(self.server)

# Derive ldap_uri from server
if 'ldap_uri' not in self and 'server' in self:
# pylint: disable=no-member, access-member-before-definition
self.ldap_uri = 'ldap://{}'.format(self.server)

# Derive jsonrpc_uri from xmlrpc_uri
Expand Down
1 change: 0 additions & 1 deletion ipalib/install/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class HostNameInstallInterface(service.ServiceInstallInterface):
"""

ip_addresses = knob(
# pylint: disable=invalid-sequence-index
typing.List[CheckedIPAddress], None,
description="Specify IP address that should be added to DNS. This "
"option can be used multiple times",
Expand Down
2 changes: 0 additions & 2 deletions ipalib/install/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def domain_name(self, value):
validate_domain_name(value)

servers = knob(
# pylint: disable=invalid-sequence-index
typing.List[str], None,
description="FQDN of IPA server",
cli_names='--server',
Expand Down Expand Up @@ -143,7 +142,6 @@ def realm_name(self, value):
)

ca_cert_files = knob(
# pylint: disable=invalid-sequence-index
typing.List[str], None,
description="load the CA certificate from this file",
cli_names='--ca-cert-file',
Expand Down
8 changes: 4 additions & 4 deletions ipalib/plugable.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def bootstrap(self, parser=None, **overrides):
if root_logger.handlers or self.env.validate_api:
return

if self.env.debug: # pylint: disable=using-constant-test
if self.env.debug:
level = logging.DEBUG
else:
level = logging.INFO
Expand All @@ -478,7 +478,7 @@ def bootstrap(self, parser=None, **overrides):

# Add stderr handler:
level = logging.INFO
if self.env.debug: # pylint: disable=using-constant-test
if self.env.debug:
level = logging.DEBUG
else:
if self.env.context == 'cli':
Expand Down Expand Up @@ -510,7 +510,7 @@ def bootstrap(self, parser=None, **overrides):
return

level = logging.INFO
if self.env.debug: # pylint: disable=using-constant-test
if self.env.debug:
level = logging.DEBUG
if self.env.log is not None:
try:
Expand Down Expand Up @@ -663,7 +663,7 @@ def add_package(self, package):
continue
except Exception:
tb = self.env.startup_traceback
if tb: # pylint: disable=using-constant-test
if tb:
logger.exception("could not load plugin module %s", name)
raise

Expand Down
7 changes: 1 addition & 6 deletions ipalib/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
from xmlrpclib import (Binary, Fault, DateTime, dumps, loads, ServerProxy,
Transport, ProtocolError, MININT, MAXINT)
except ImportError:
# pylint: disable=import-error
from xmlrpc.client import (Binary, Fault, DateTime, dumps, loads, ServerProxy,
Transport, ProtocolError, MININT, MAXINT)

Expand Down Expand Up @@ -763,7 +762,7 @@ def __send_request(self, connection, host, handler, request_body, debug):
else:
connection.putrequest("POST", handler)
headers.append(("User-Agent", self.user_agent))
self.send_headers(connection, headers) # pylint: disable=E1101
self.send_headers(connection, headers)
self.send_content(connection, request_body)
return connection

Expand Down Expand Up @@ -996,8 +995,6 @@ def apply_session_cookie(self, url):
# Form the session URL by substituting the session path into the original URL
scheme, netloc, path, params, query, fragment = urllib.parse.urlparse(original_url)
path = self.session_path
# urlencode *can* take one argument
# pylint: disable=too-many-function-args
session_url = urllib.parse.urlunparse((scheme, netloc, path, params, query, fragment))

return session_url
Expand Down Expand Up @@ -1078,11 +1075,9 @@ def create_connection(self, ccache=None, verbose=None, fallback=None,
)
# We don't care about the response, just that we got one
return serverproxy
# pylint: disable=try-except-raise
except errors.KerberosError:
# kerberos error on one server is likely on all
raise
# pylint: enable=try-except-raise
except ProtocolError as e:
if hasattr(context, 'session_cookie') and e.errcode == 401:
# Unauthorized. Remove the session and try again.
Expand Down
8 changes: 3 additions & 5 deletions ipalib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,18 @@ def as_unicode(self):
else:
t = create_translation(self.key)
if six.PY2:
return t.ugettext(self.msg) # pylint: disable=no-member
return t.ugettext(self.msg)
else:
return t.gettext(self.msg)

def __str__(self):
return unicode(self.as_unicode())

def __json__(self):
return unicode(self) #pylint: disable=no-member
return unicode(self)

def __mod__(self, kw):
return unicode(self) % kw #pylint: disable=no-member
return unicode(self) % kw

def format(self, *args, **kwargs):
return unicode(self).format(*args, **kwargs)
Expand Down Expand Up @@ -481,9 +481,7 @@ def __call__(self, count):
else:
t = create_translation(self.key)
if six.PY2:
# pylint: disable=no-member
return t.ungettext(self.singular, self.plural, count)
# pylint: enable=no-member
else:
return t.ngettext(self.singular, self.plural, count)

Expand Down
Loading

0 comments on commit 5a00882

Please sign in to comment.