Skip to content

Commit

Permalink
[pylint] Fix pylint issues
Browse files Browse the repository at this point in the history
The following are addressed here:
 - redundant-u-string-prefix
 - simplifiable-if-expression
 - consider-using-generator
 - access-member-before-definition
 - simplifiable-if-statement
 - signature-differs

Signed-off-by: Ponnuvel Palaniyappan <[email protected]>
  • Loading branch information
pponnuvel authored and TurboTurtle committed Aug 8, 2024
1 parent 938aff3 commit 36ad771
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 39 deletions.
6 changes: 0 additions & 6 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,27 @@ disable=
###################### VV things we should fix VV
W0719, # broad-exception-raised
W1203, # logging-fstring-interpolation
W1406, # redundant-u-string-prefix
W1514, # unspecified-encoding
W0107, # unnecessary-pass
W0718, # broad-exception-caught
W0102, # dangerous-default-value
W0221, # arguments-differ
W3101, # missing-timeout
C0201, # consider-iterating-dictionary
R1719, # simplifiable-if-expression
W1201, # logging-not-lazy
W0707, # raise-missing-from
W0237, # arguments-renamed
C0117, # unnecessary-negation
W0212, # protected-access
R1728, # consider-using-generator
W0231, # super-init-not-called
C0123, # unidiomatic-typecheck
C0207, # use-maxsplit-arg
C2801, # unnecessary-dunder-call
E0203, # access-member-before-definition
E0611, # no-name-in-module
E0702, # raising-bad-type
E1101, # no-member
E1135, # unsupported-membership-test
R1703, # simplifiable-if-statement
R1721, # unnecessary-comprehension
W0108, # unnecessary-lambda
W0222, # signature-differs
W0223, # abstract-method
W1509, # subprocess-popen-preexec-fn
2 changes: 1 addition & 1 deletion sos/collector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def _parse_options(self):
"""
self.commons = {
'cmdlineopts': self.opts,
'need_sudo': True if self.opts.ssh_user != 'root' else False,
'need_sudo': self.opts.ssh_user != 'root',
'tmpdir': self.tmpdir,
'hostlen': max(len(self.opts.primary), len(self.hostname)),
'policy': self.policy
Expand Down
14 changes: 7 additions & 7 deletions sos/collector/transports/control_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def _connect(self, password=''): # pylint: disable=too-many-branches
res = pexpect.spawn(cmd, encoding='utf-8')

connect_expects = [
u'Connected',
u'password:',
u'.*Permission denied.*',
u'.* port .*: No route to host',
u'.*Could not resolve hostname.*',
'Connected',
'password:',
'.*Permission denied.*',
'.* port .*: No route to host',
'.*Could not resolve hostname.*',
pexpect.TIMEOUT
]

Expand All @@ -127,8 +127,8 @@ def _connect(self, password=''): # pylint: disable=too-many-branches
elif index == 1:
if password:
pass_expects = [
u'Connected',
u'Permission denied, please try again.',
'Connected',
'Permission denied, please try again.',
pexpect.TIMEOUT
]
res.sendline(password)
Expand Down
3 changes: 1 addition & 2 deletions sos/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ def setup_archive(self, name=''):
if self.opts.encrypt:
self._get_encryption_method()
enc_opts = {
'encrypt': True if (self.opts.encrypt_pass or
self.opts.encrypt_key) else False,
'encrypt': self.opts.encrypt_pass or self.opts.encrypt_key,
'key': self.opts.encrypt_key,
'password': self.opts.encrypt_pass
}
Expand Down
2 changes: 1 addition & 1 deletion sos/policies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def _fmt_vendor_urls(self):
:returns: Formatted string of URLS
:rtype: ``str``
"""
width = max([len(v[0]) for v in self.vendor_urls])
width = max(len(v[0]) for v in self.vendor_urls)
return "\n".join(
f"\t{url[0]:<{width}} : {url[1]}" for url in self.vendor_urls
)
Expand Down
14 changes: 7 additions & 7 deletions sos/policies/distros/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,9 @@ def upload_sftp(self, user=None, password=None):
ret = pexpect.spawn(sftp_cmd, encoding='utf-8')

sftp_expects = [
u'sftp>',
u'password:',
u'Connection refused',
'sftp>',
'password:',
'Connection refused',
pexpect.TIMEOUT,
pexpect.EOF
]
Expand All @@ -716,8 +716,8 @@ def upload_sftp(self, user=None, password=None):
elif idx == 1:
ret.sendline(password)
pass_expects = [
u'sftp>',
u'Permission denied',
'sftp>',
'Permission denied',
pexpect.TIMEOUT,
pexpect.EOF
]
Expand Down Expand Up @@ -746,10 +746,10 @@ def upload_sftp(self, user=None, password=None):
ret.sendline(put_cmd)

put_expects = [
u'100%',
'100%',
pexpect.TIMEOUT,
pexpect.EOF,
u'No such file or directory'
'No such file or directory'
]

put_success = ret.expect(put_expects, timeout=180)
Expand Down
2 changes: 1 addition & 1 deletion sos/policies/distros/suse.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, sysroot=None, init=None, probe_runtime=True,
remote_exec=remote_exec)

@classmethod
def check(cls, remote):
def check(cls, remote=''):
"""This method checks to see if we are running on SuSE.
"""

Expand Down
2 changes: 1 addition & 1 deletion sos/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ def final_work(self):
# that still will be moved to the sos report final directory path
tmpdir_path = Path(self.tmpdir)
self.estimated_plugsizes['sos_logs_reports'] = sum(
[f.lstat().st_size for f in tmpdir_path.glob('**/*')])
f.lstat().st_size for f in tmpdir_path.glob('**/*'))

_sum = get_human_readable(sum(self.estimated_plugsizes.values()))
self.ui_log.info("Estimated disk space requirement for whole "
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 @@ -3370,7 +3370,7 @@ def setup(self):
self.add_copy_spec(list(self.files))

def setup_verify(self):
if not hasattr(self, "verify_packages") or not self.verify_packages:
if not hasattr(self, "verify_packages"):
if hasattr(self, "packages") and self.packages:
# Limit automatic verification to only the named packages
self.verify_packages = [p + "$" for p in self.packages]
Expand Down
6 changes: 3 additions & 3 deletions sos/report/reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ def unicode(self):
if len(self.FOOTER) > 0:
line_buf.append(self.FOOTER)

output = u'\n'.join(map(lambda i: (i if isinstance(i, str)
else i.decode('utf8', 'ignore')),
line_buf))
output = '\n'.join(map(lambda i: (i if isinstance(i, str)
else i.decode('utf8', 'ignore')),
line_buf))
return output

def process_subsection(self, section, key, header, format_, footer):
Expand Down
4 changes: 2 additions & 2 deletions tests/unittests/plugin_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ class MockOptions:
class PluginToolTests(unittest.TestCase):

def test_regex_findall(self):
test_s = u"\n".join(
test_s = "\n".join(
['this is only a test', 'there are only two lines'])
test_fo = StringIO(test_s)
matches = regex_findall(r".*lines$", test_fo)
self.assertEqual(matches, ['there are only two lines'])

def test_regex_findall_miss(self):
test_s = u"\n".join(
test_s = "\n".join(
['this is only a test', 'there are only two lines'])
test_fo = StringIO(test_s)
matches = regex_findall(r".*not_there$", test_fo)
Expand Down
12 changes: 6 additions & 6 deletions tests/unittests/report_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def setUp(self):
self.section = Section(name="plugin")
self.div = '\n' + PlainTextReport.PLUGDIVIDER
self.pluglist = "Loaded Plugins:\n{pluglist}"
self.defaultheader = u''.join([
self.defaultheader = ''.join([
self.pluglist.format(pluglist=" plugin"),
self.div,
"\nplugin\n"
Expand All @@ -92,7 +92,7 @@ def test_two_sections(self):
section2 = Section(name="second")
self.report.add(section1, section2)

self.assertEqual(u''.join([
self.assertEqual(''.join([
self.pluglist.format(pluglist=" first second"),
self.div,
"\nfirst",
Expand All @@ -108,7 +108,7 @@ def test_command(self):
self.section.add(cmd)
self.report.add(self.section)

self.assertEqual(u''.join([
self.assertEqual(''.join([
self.defaultheader,
"- commands executed:\n * ls -al /foo/bar/baz"
]),
Expand All @@ -119,7 +119,7 @@ def test_copied_file(self):
self.section.add(cf)
self.report.add(self.section)

self.assertEqual(u''.join([
self.assertEqual(''.join([
self.defaultheader,
"- files copied:\n * /etc/hosts"
]),
Expand All @@ -131,7 +131,7 @@ def test_created_file(self):
self.section.add(crf)
self.report.add(self.section)

self.assertEqual(u''.join([
self.assertEqual(''.join([
self.defaultheader,
"- files created:\n * sample.txt"
]),
Expand All @@ -142,7 +142,7 @@ def test_alert(self):
self.section.add(alrt)
self.report.add(self.section)

self.assertEqual(u''.join([
self.assertEqual(''.join([
self.defaultheader,
"- alerts:\n ! this is an alert"
]),
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/utilities_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class GrepTest(unittest.TestCase):

def test_file_obj(self):
test_s = u"\n".join(
test_s = "\n".join(
['this is only a test', 'there are only two lines'])
test_fo = StringIO(test_s)
matches = grep(".*test$", test_fo)
Expand Down

0 comments on commit 36ad771

Please sign in to comment.