Skip to content

Commit

Permalink
[pylint] Fixes more pylint issues
Browse files Browse the repository at this point in the history
The following are fixed in this change:

    W3101 - missing-timeout
    W0231 - super-init-not-called
    C0123 - unidiomatic-typecheck
    C0207 - use-maxsplit-arg
    E0611 - no-name-in-module
    E0702 - raising-bad-type
    E1101 - no-member
    E1135 - unsupported-membership-test
    C0411 - wrong-import-order

Signed-off-by: Ponnuvel Palaniyappan <[email protected]>
  • Loading branch information
pponnuvel authored and TurboTurtle committed Aug 13, 2024
1 parent 1086911 commit 95dbbc2
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 24 deletions.
8 changes: 0 additions & 8 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,12 @@ disable=
W0107, # unnecessary-pass
W0718, # broad-exception-caught
W0102, # dangerous-default-value
W3101, # missing-timeout
C0201, # consider-iterating-dictionary
W1201, # logging-not-lazy
W0707, # raise-missing-from
C0117, # unnecessary-negation
W0212, # protected-access
W0231, # super-init-not-called
C0123, # unidiomatic-typecheck
C0207, # use-maxsplit-arg
C2801, # unnecessary-dunder-call
E0611, # no-name-in-module
E0702, # raising-bad-type
E1101, # no-member
E1135, # unsupported-membership-test
R1721, # unnecessary-comprehension
W0108, # unnecessary-lambda
W0223, # abstract-method
Expand Down
4 changes: 2 additions & 2 deletions sos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def __init__(self, args):
['collector'])
except ModuleNotFoundError as err:
import sos.missing
if 'sos.collector' in err.msg:
if 'sos.collector' in str(err.msg):
# is not locally installed - packaged separately
self._components['collect'] = (sos.missing.MissingCollect, [])
elif 'pexpect' in err.msg:
elif 'pexpect' in str(err.msg):
# cannot be imported due to missing the pexpect dep
self._components['collect'] = (sos.missing.MissingPexpect, [])
else:
Expand Down
3 changes: 2 additions & 1 deletion sos/cleaner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def __init__(self, parser=None, args=None, cmdline=None, in_place=False,

for _parser in self.opts.disable_parsers:
for _loaded in self.parsers:
_loaded_name = _loaded.name.lower().split('parser')[0].strip()
_temp = _loaded.name.lower().split('parser', maxsplit=1)[0]
_loaded_name = _temp.strip()
if _parser.lower().strip() == _loaded_name:
self.log_info(f"Disabling parser: {_loaded_name}")
self.ui_log.warning(
Expand Down
2 changes: 1 addition & 1 deletion sos/cleaner/mappings/ip_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def ip_in_dataset(self, ipaddr):
already created
"""
for _ip in self.dataset.values():
if str(ipaddr).split('/')[0] == _ip.split('/')[0]:
if str(ipaddr).split('/', maxsplit=1)[0] == _ip.split('/')[0]:
return True
return False

Expand Down
11 changes: 8 additions & 3 deletions sos/policies/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import time
from datetime import datetime, timedelta

from sos.utilities import TIMEOUT_DEFAULT

DEVICE_AUTH_CLIENT_ID = "sos-tools"
GRANT_TYPE_DEVICE_CODE = "urn:ietf:params:oauth:grant-type:device_code"

Expand Down Expand Up @@ -67,7 +69,8 @@ def _request_device_code(self):
res = requests.post(
self.client_identifier_url,
data=data,
headers=headers)
headers=headers,
timeout=TIMEOUT_DEFAULT)
res.raise_for_status()
response = res.json()
self._user_code = response.get("user_code")
Expand Down Expand Up @@ -99,7 +102,8 @@ def poll_for_auth_completion(self):
time.sleep(self._interval)
try:
check_auth_completion = requests.post(self.token_endpoint,
data=token_data)
data=token_data,
timeout=TIMEOUT_DEFAULT)

status_code = check_auth_completion.status_code

Expand Down Expand Up @@ -187,7 +191,8 @@ def _use_refresh_token_grant(self, refresh_token=None):
refresh_token else refresh_token}

refresh_token_res = requests.post(self.token_endpoint,
data=refresh_token_data)
data=refresh_token_data,
timeout=TIMEOUT_DEFAULT)

if refresh_token_res.status_code == 200:
self._set_token_data(refresh_token_res.json())
Expand Down
6 changes: 3 additions & 3 deletions sos/policies/distros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from sos.policies.runtimes.lxd import LxdContainerRuntime

from sos.utilities import (shell_out, is_executable, bold,
sos_get_command_output)
sos_get_command_output, TIMEOUT_DEFAULT)


try:
Expand Down Expand Up @@ -787,7 +787,7 @@ def _upload_https_put(self, archive, verify=True):
"""
return requests.put(self.get_upload_url(), data=archive,
auth=self.get_upload_https_auth(),
verify=verify)
verify=verify, timeout=TIMEOUT_DEFAULT)

def _get_upload_headers(self):
"""Define any needed headers to be passed with the POST request here
Expand All @@ -807,7 +807,7 @@ def _upload_https_post(self, archive, verify=True):
}
return requests.post(self.get_upload_url(), files=files,
auth=self.get_upload_https_auth(),
verify=verify)
verify=verify, timeout=TIMEOUT_DEFAULT)

def upload_https(self):
"""Attempts to upload the archive to an HTTPS location.
Expand Down
4 changes: 2 additions & 2 deletions sos/policies/distros/redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from sos.policies.package_managers.rpm import RpmPackageManager
from sos.policies.package_managers.flatpak import FlatpakPackageManager
from sos.policies.package_managers import MultiPackageManager
from sos.utilities import bold, convert_bytes
from sos.utilities import bold, convert_bytes, TIMEOUT_DEFAULT
from sos import _sos as _

try:
Expand Down Expand Up @@ -327,7 +327,7 @@ def _upload_https_post(self, archive, verify=True):
f"{self.get_upload_url_string()}")
return requests.post(self.get_upload_url(), files=files,
headers=self._get_upload_https_auth(),
verify=verify)
verify=verify, timeout=TIMEOUT_DEFAULT)

def _get_upload_headers(self):
if self.get_upload_url().startswith(RH_API_HOST):
Expand Down
2 changes: 1 addition & 1 deletion sos/policies/package_managers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def packages(self):

@property
def manager_name(self):
return self.__class__.__name__.lower().split('package')[0]
return self.__class__.__name__.lower().split('package', maxsplit=1)[0]

def exec_cmd(self, command, timeout=30, need_root=False, env=None,
use_shell=False, chroot=None):
Expand Down
2 changes: 1 addition & 1 deletion sos/report/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def set_value(self, val):
if type('') in self.val_type:
self.value = str(val)
return
if not any(type(val) is _t for _t in self.val_type):
if not any(isinstance(val, _t) for _t in self.val_type):
valid = []
for t in self.val_type:
if t is None:
Expand Down
2 changes: 1 addition & 1 deletion tests/sos_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def manifest(self):
self._manifest = json.loads(content)
except Exception:
self._manifest = ''
self.warning('Could not load manifest for test')
self.log.warn('Could not load manifest for test')
return self._manifest

@property
Expand Down
1 change: 1 addition & 0 deletions tests/unittests/plugin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def create_file(size, dirname=None):

class MockArchive(TarFileArchive):

# pylint: disable=super-init-not-called
def __init__(self):
self.m = {}
self.strings = {}
Expand Down
3 changes: 2 additions & 1 deletion tests/vendor_tests/redhat/rhbz1928628.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# See the LICENSE file in the source distribution for further information.


from report_tests.plugin_tests.networking import NetworkingPluginTest
from tests.report_tests.plugin_tests.networking.networking import \
NetworkingPluginTest


class rhbz1928628(NetworkingPluginTest):
Expand Down

0 comments on commit 95dbbc2

Please sign in to comment.