diff --git a/.pylintrc b/.pylintrc
index 52bb1e43641..f5fdcd82414 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -10,16 +10,11 @@ disable=
unspecified-encoding,
global-statement,
protected-access,
- redundant-u-string-prefix,
broad-exception-raised,
subprocess-popen-preexec-fn,
- format-string-without-interpolation,
- cell-var-from-loop,
logging-not-lazy,
unknown-option-value,
- implicit-str-concat,
unused-wildcard-import,
- pointless-statement,
wildcard-import,
unused-argument,
deprecated-module,
@@ -38,11 +33,9 @@ disable=
too-many-lines,
trailing-newlines,
missing-final-newline,
- unnecessary-negation,
use-implicit-booleaness-not-len,
wrong-import-order,
use-implicit-booleaness-not-comparison,
- multiple-imports,
consider-using-enumerate,
unnecessary-lambda-assignment,
consider-using-dict-items,
@@ -52,23 +45,17 @@ disable=
consider-using-with,
too-many-statements,
too-many-branches,
- simplifiable-if-statement,
too-many-locals,
too-many-arguments,
too-few-public-methods,
- consider-using-min-builtin,
- comparison-with-itself,
too-many-return-statements,
- inconsistent-return-statements,
consider-using-in,
too-many-nested-blocks,
too-many-public-methods,
consider-using-sys-exit,
chained-comparison,
too-many-instance-attributes,
- consider-using-join,
too-many-boolean-expressions,
- useless-object-inheritance,
use-a-generator,
too-many-positional-arguments
[REPORTS]
diff --git a/addons/cppcheck.py b/addons/cppcheck.py
index 1649815e070..735269d32c5 100644
--- a/addons/cppcheck.py
+++ b/addons/cppcheck.py
@@ -1,5 +1,7 @@
-import cppcheckdata, sys, os
+import cppcheckdata
+import sys
+import os
__checkers__ = []
diff --git a/addons/cppcheckdata.py b/addons/cppcheckdata.py
index aedad755b7d..6f434d5e283 100755
--- a/addons/cppcheckdata.py
+++ b/addons/cppcheckdata.py
@@ -532,6 +532,7 @@ def tokAt(self, n):
for i, t in enumerate(tl):
if i == n:
return t
+ return None
def linkAt(self, n):
token = self.tokAt(n)
diff --git a/addons/misra.py b/addons/misra.py
index 8ab57985f98..4d3fa22391d 100755
--- a/addons/misra.py
+++ b/addons/misra.py
@@ -1292,7 +1292,7 @@ def remove_file_prefix(file_path, prefix):
return result
-class Rule(object):
+class Rule():
"""Class to keep rule text and metadata"""
MISRA_SEVERITY_LEVELS = ['Required', 'Mandatory', 'Advisory']
@@ -1326,7 +1326,7 @@ def __repr__(self):
return "%d.%d (%s)" % (self.num1, self.num2, self.misra_severity)
-class MisraSettings(object):
+class MisraSettings():
"""Hold settings for misra.py script."""
__slots__ = ["verify", "quiet", "show_summary"]
diff --git a/addons/runaddon.py b/addons/runaddon.py
index 536abe864f7..26ad7e9fa73 100644
--- a/addons/runaddon.py
+++ b/addons/runaddon.py
@@ -1,4 +1,8 @@
-import cppcheckdata, cppcheck, runpy, sys, os
+import cppcheckdata
+import cppcheck
+import runpy
+import sys
+import os
if __name__ == '__main__':
addon = sys.argv[1]
diff --git a/htmlreport/cppcheck-htmlreport b/htmlreport/cppcheck-htmlreport
index 95c9bf3ff2b..6e2f69f6e98 100755
--- a/htmlreport/cppcheck-htmlreport
+++ b/htmlreport/cppcheck-htmlreport
@@ -382,8 +382,8 @@ HTML_FOOTER = """
HTML_ERROR = "<--- %s\n"
HTML_INCONCLUSIVE = "<--- %s\n"
-HTML_EXPANDABLE_ERROR = "
\n"""
-HTML_EXPANDABLE_INCONCLUSIVE = "\n"""
+HTML_EXPANDABLE_ERROR = "\n"
+HTML_EXPANDABLE_INCONCLUSIVE = "\n"
# escape() and unescape() takes care of &, < and >.
html_escape_table = {
diff --git a/test/cli/samples_test.py b/test/cli/samples_test.py
index 44bbbbb526e..d8459509d3a 100644
--- a/test/cli/samples_test.py
+++ b/test/cli/samples_test.py
@@ -18,7 +18,7 @@ def test_samples():
with open(os.path.join(sample_dir, 'out.txt')) as out_in:
out_txt = out_in.read()
- if not sys.platform == 'win32':
+ if sys.platform != 'win32':
out_txt = out_txt.replace('\\', '/')
if not os.path.exists(os.path.join(sample_dir, 'good.c')):
@@ -30,12 +30,12 @@ def test_samples():
# check that good input does not produce any warnings
ret, _, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', good_src], cwd=__root_dir)
- if not ret == 0:
+ if ret != 0:
failures[good_src] = stderr
# check that the bad inout produces a warning
ret, _, stderr = cppcheck(['-q', '--enable=all', '--disable=missingInclude', '--inconclusive', '--check-level=exhaustive', '--error-exitcode=1', bad_src], cwd=__root_dir)
- if not ret == 1:
+ if ret != 1:
failures[bad_src] = stderr
# check that the bad input procudes the expected output
diff --git a/tools/MT-Unsafe.py b/tools/MT-Unsafe.py
index 9783993090d..965a6261db8 100755
--- a/tools/MT-Unsafe.py
+++ b/tools/MT-Unsafe.py
@@ -59,7 +59,7 @@ def man_search(manpage):
MANPAGE = open(manpage, 'r')
except OSError as filename:
print('cannot open %s' % filename, file=sys.stderr)
- return None, None
+ return # None, None
vprint(1, '%s opened' % (manpage))
@@ -95,7 +95,7 @@ def man_search(manpage):
if res:
apis.add(res.group(1))
dprint(1, 'found api %s in %s' % (res.group(1), lineread))
- next
+ continue
if 'MT-Unsafe' in lineread:
resUnsafe = re.search("MT-Unsafe\\s+(.*)(\\n\'|$)", lineread)
@@ -114,7 +114,7 @@ def man_search(manpage):
dprint(1, 'new apis %s' % list(apis))
for api in apis:
unsafe_apis.add(api)
- next
+ continue
# if lineread.startswith('.TE'):
if re.search('.TE', lineread):
@@ -147,7 +147,8 @@ def do_man_dir(directory):
"""Recursively process a directory of man-pages."""
dprint(1, 'do_man_dir(%s)' % (directory))
if os.path.isfile(directory):
- return do_man_page(directory)
+ do_man_page(directory)
+ return
for path, _, files in os.walk(directory):
for file in files:
@@ -162,7 +163,7 @@ def do_man_dir(directory):
if re.match('^-+debug', arg):
debug = debug+1
dprint(1, 'debug %d' % debug)
- next
+ continue
else:
if os.access(arg, os.R_OK):
manpages.add(arg)
diff --git a/tools/creduce.py b/tools/creduce.py
index 0ab9f5b9986..f6f9c7d8e47 100644
--- a/tools/creduce.py
+++ b/tools/creduce.py
@@ -1,4 +1,10 @@
-import argparse, contextlib, multiprocessing, os, tempfile, shutil, subprocess
+import argparse
+import contextlib
+import multiprocessing
+import os
+import tempfile
+import shutil
+import subprocess
@contextlib.contextmanager
def mkdtemp():
diff --git a/tools/donate-cpu-server.py b/tools/donate-cpu-server.py
index 75fc4954a93..c607b3776bc 100755
--- a/tools/donate-cpu-server.py
+++ b/tools/donate-cpu-server.py
@@ -26,7 +26,7 @@
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
# changes)
-SERVER_VERSION = "1.3.59"
+SERVER_VERSION = "1.3.60"
OLD_VERSION = '2.15.0'
@@ -1585,7 +1585,7 @@ def server(server_address_port: int, packages: list, packageIndex: int, resultPa
print_ts('packages_nodata: {}'.format(len(packages_nodata)))
- print_ts('removing packages with no files to process'.format(len(packages_nodata)))
+ print_ts('removing packages with no files to process')
packages_nodata_clean = []
for pkg_n in packages_nodata:
if pkg_n in packages:
diff --git a/tools/donate-cpu.py b/tools/donate-cpu.py
index 142622b1212..40d3f88adc3 100755
--- a/tools/donate-cpu.py
+++ b/tools/donate-cpu.py
@@ -247,8 +247,8 @@
cppcheck_head_info = lib.get_cppcheck_info(tree_path)
capture_callstack = True
- def get_client_version_head():
- cmd = 'python3' + ' ' + os.path.join(tree_path, 'tools', 'donate-cpu.py') + ' ' + '--version'
+ def get_client_version_head(path):
+ cmd = 'python3' + ' ' + os.path.join(path, 'tools', 'donate-cpu.py') + ' ' + '--version'
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, universal_newlines=True)
try:
comm = p.communicate()
@@ -256,7 +256,7 @@ def get_client_version_head():
except:
return None
- client_version_head = get_client_version_head()
+ client_version_head = get_client_version_head(tree_path)
c, errout, info, t, cppcheck_options, timing_info = lib.scan_package(tree_path, source_path, libraries, capture_callstack)
if c < 0:
if c == -101 and 'error: could not find or open any of the paths given.' in errout:
diff --git a/tools/donate_cpu_lib.py b/tools/donate_cpu_lib.py
index e7394d5593e..d1184447a92 100644
--- a/tools/donate_cpu_lib.py
+++ b/tools/donate_cpu_lib.py
@@ -16,7 +16,7 @@
# Version scheme (MAJOR.MINOR.PATCH) should orientate on "Semantic Versioning" https://semver.org/
# Every change in this script should result in increasing the version number accordingly (exceptions may be cosmetic
# changes)
-CLIENT_VERSION = "1.3.62"
+CLIENT_VERSION = "1.3.63"
# Timeout for analysis with Cppcheck in seconds
CPPCHECK_TIMEOUT = 30 * 60
@@ -80,6 +80,7 @@ def check_requirements():
# Try and retry with exponential backoff if an exception is raised
+# pylint: disable-next=inconsistent-return-statements
def try_retry(fun, fargs=(), max_tries=5, sleep_duration=5.0, sleep_factor=2.0):
for i in range(max_tries):
try:
@@ -93,6 +94,7 @@ def try_retry(fun, fargs=(), max_tries=5, sleep_duration=5.0, sleep_factor=2.0):
print("Trying {} again in {} seconds".format(fun.__name__, sleep_duration))
time.sleep(sleep_duration)
sleep_duration *= sleep_factor
+ # do not return - re-try
else:
print("Maximum number of tries reached for {}".format(fun.__name__))
raise e
diff --git a/tools/matchcompiler.py b/tools/matchcompiler.py
index 40cccdcd273..333958053cf 100755
--- a/tools/matchcompiler.py
+++ b/tools/matchcompiler.py
@@ -683,7 +683,7 @@ def convertFile(self, srcname, destname, line_directive):
srclines = fin.readlines()
fin.close()
- code = u''
+ code = ''
modified = False
@@ -710,20 +710,18 @@ def convertFile(self, srcname, destname, line_directive):
code += line
# Compute matchFunctions
- strFunctions = u''
- for function in self._rawMatchFunctions:
- strFunctions += function
+ strFunctions = ''.join(self._rawMatchFunctions)
- lineno = u''
+ lineno = ''
if line_directive:
- lineno = u'#line 1 "' + srcname + '"\n'
+ lineno = '#line 1 "' + srcname + '"\n'
- header = u'#include "matchcompiler.h"\n'
- header += u'#include \n'
- header += u'#include \n'
+ header = '#include "matchcompiler.h"\n'
+ header += '#include \n'
+ header += '#include \n'
if len(self._rawMatchFunctions):
- header += u'#include "errorlogger.h"\n'
- header += u'#include "token.h"\n'
+ header += '#include "errorlogger.h"\n'
+ header += '#include "token.h"\n'
fout = io.open(destname, 'wt', encoding="utf-8")
if modified or len(self._rawMatchFunctions):
diff --git a/tools/reduce.py b/tools/reduce.py
index 0c3349fbcc3..cac7458a3c1 100755
--- a/tools/reduce.py
+++ b/tools/reduce.py
@@ -173,8 +173,7 @@ def combinelines(self, filedata):
i1 = i
i2 = i + chunksize
i = i2
- if i2 > len(lines):
- i2 = len(lines)
+ i2 = min(i2, len(lines))
filedata2 = list(filedata)
for line in lines[i1:i2]:
@@ -259,10 +258,7 @@ def removeline(self, filedata):
elif stmt and '{' in strippedline and strippedline.find('}') == len(strippedline) - 1:
self.replaceandrun('remove line', filedata, i, '')
- if strippedline[-1] in ';{}':
- stmt = True
- else:
- stmt = False
+ stmt = strippedline[-1] in ';{}'
def set_elapsed_time(self, elapsed_time):
self.__elapsed_time = elapsed_time
diff --git a/tools/reduce_test.py b/tools/reduce_test.py
index f3e9486634e..aaeec7a87e3 100644
--- a/tools/reduce_test.py
+++ b/tools/reduce_test.py
@@ -125,9 +125,10 @@ def test_combinelines_chunk_2():
's,\n',
't;\n'
]
+ filedata_exp = filedata
filedata2 = reduce.combinelines(filedata)
- assert filedata == filedata
+ assert filedata == filedata_exp
assert filedata2 == ['int i,j,\n',
'',
'l,\n',
diff --git a/tools/triage_py/triage_version.py b/tools/triage_py/triage_version.py
index c3d6c29ee32..dcad4ab004f 100644
--- a/tools/triage_py/triage_version.py
+++ b/tools/triage_py/triage_version.py
@@ -205,7 +205,7 @@ def sort_commit_hashes(commits):
if args.perf:
if out == "timeout":
data_str = "0.0" # TODO: how to handle these properly?
- elif not ec == 0:
+ elif ec != 0:
continue # skip errors
else:
data_str = '{}'.format((end - start) / 1000.0 / 1000.0 / 1000.0)