From 5917355facef3bf0d83324205b0ac0803f2fdbf6 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 22 Jun 2023 11:28:20 +1000 Subject: [PATCH 1/4] pylint: Remove warning about using dict() instead of dict literal pylint 2.17.2 (Fedora 38) seems to complain about this. Signed-off-by: David Gibson --- avocado/utils/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/avocado/utils/build.py b/avocado/utils/build.py index 32e86be347..0373a27bc3 100644 --- a/avocado/utils/build.py +++ b/avocado/utils/build.py @@ -107,7 +107,7 @@ def make( :returns: exit status of the make process """ - kwargs = dict(env=env, ignore_status=ignore_status) + kwargs = {"env": env, "ignore_status": ignore_status} if process_kwargs is not None: kwargs.update(process_kwargs) result = run_make(path, make, extra_args, kwargs) From f91a075165e41beb89d8e74d3d73dc7bec204786 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 22 Jun 2023 11:31:18 +1000 Subject: [PATCH 2/4] pylint: Suppress unreachable code warnings due to exit()s Several tests in selftests/.data/test_statuses.py log a message after calling sys.exit(), which causes 2.17.2 (Fedora 38) to complain about unreachable code. It looks like these messages are here so we can see what's happening if sys.exit() were ever to *not* behave as we expect, so we don't want to remove then. Instead use a pylint suppression. Signed-off-by: David Gibson --- selftests/.data/test_statuses.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/selftests/.data/test_statuses.py b/selftests/.data/test_statuses.py index de3004ebb1..10141ae1da 100644 --- a/selftests/.data/test_statuses.py +++ b/selftests/.data/test_statuses.py @@ -199,7 +199,7 @@ class ExitSetup(Test): def setUp(self): self.log.info("setup pre") sys.exit(-1) - self.log.info("setup post") + self.log.info("setup post") # pylint: disable=W0101 def test(self): self.log.info("test pre") @@ -219,7 +219,7 @@ def setUp(self): def test(self): self.log.info("test pre") sys.exit(-1) - self.log.info("test post") + self.log.info("test post") # pylint: disable=W0101 def tearDown(self): self.log.info("teardown pre") @@ -240,7 +240,7 @@ def tearDown(self): self.log.info("teardown pre") self.log.info("teardown status: %s", self.status) sys.exit(-1) - self.log.info("teardown post") + self.log.info("teardown post") # pylint: disable=W0101 class ExceptionSetup(Test): From 7d7832c2130815478620d1139da75e378d1dfc27 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Wed, 21 Jun 2023 23:17:24 +1000 Subject: [PATCH 3/4] pylint: Fully qualify exception names in overgeneral-exceptions config pylint 2.17.2 (Fedora 38) gives warnings if the exception classes specified in the overgeneral-exceptions option of the config don't give a module. Fully qualify them with 'builtins.' to stop this warning. Signed-off-by: David Gibson --- .pylintrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index ee21757d6e..37d27c9201 100644 --- a/.pylintrc +++ b/.pylintrc @@ -541,5 +541,5 @@ valid-metaclass-classmethod-first-arg=cls # Exceptions that will emit a warning when being caught. Defaults to # "BaseException, Exception". -overgeneral-exceptions=BaseException, - Exception +overgeneral-exceptions=builtins.BaseException, + builtins.Exception From 587a6f30e207794045db3e322f42c8cdb4b30174 Mon Sep 17 00:00:00 2001 From: David Gibson Date: Thu, 22 Jun 2023 11:46:53 +1000 Subject: [PATCH 4/4] pylint: Fix places that raise an overly broad exception pylint 2.17.2 (Fedora 38) complains about places that raise an overly broad exception, such as bare 'Exception' rather than a derived class. Change most places that do that to raise an appropriate derived class. One remaining place appears to be deliberately raising the generic exception, so use a pylint suppression there instead. Signed-off-by: David Gibson --- avocado/utils/external/gdbmi_parser.py | 10 +++++++--- avocado/utils/gdb.py | 4 +++- avocado/utils/kernel.py | 2 +- examples/tests/multiple_tests.py | 2 +- examples/tests/uncaught_exception.py | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/avocado/utils/external/gdbmi_parser.py b/avocado/utils/external/gdbmi_parser.py index 5e33816699..927351378f 100644 --- a/avocado/utils/external/gdbmi_parser.py +++ b/avocado/utils/external/gdbmi_parser.py @@ -30,6 +30,10 @@ from avocado.utils.external import spark +class GdbMiException(Exception): + pass + + class Token: def __init__(self, token_type, value=None): self.type = token_type @@ -126,7 +130,7 @@ def t_c_string(self, s): def t_default(self, s): # pylint: disable=W0221 r"( . | \n )+" - raise Exception(f"Specification error: unmatched input for '{s}'") + raise GdbMiException(f"Specification error: unmatched input for '{s}'") @staticmethod def __unescape(s): @@ -200,7 +204,7 @@ def nonterminal(self, token_type, args): def error(self, token, i=0, tokens=None): # pylint: disable=W0221 if i > 2: print(f"{tokens[i - 3]} {tokens[i - 2]} " f"{tokens[i - 1]} {tokens[i]}") - raise Exception(f"Syntax error at or near {int(i)}:'{token}' token") + raise GdbMiException(f"Syntax error at or near {int(i)}:'{token}' token") class GdbMiInterpreter(spark.GenericASTTraversal): @@ -249,7 +253,7 @@ def n_tuple(node): else: node.value[n] = v else: - raise Exception("Invalid tuple") + raise GdbMiException("Invalid tuple") # print 'tuple: %s' % node.value @staticmethod diff --git a/avocado/utils/gdb.py b/avocado/utils/gdb.py index 3e93cda113..629448360b 100644 --- a/avocado/utils/gdb.py +++ b/avocado/utils/gdb.py @@ -397,7 +397,9 @@ def cmd(self, command): if result_response_received: # raise an exception here, because no two result # responses should come from a single command AFAIK - raise Exception("Many result responses to a single cmd") + raise UnexpectedResponseError( + "Many result responses to a single cmd" + ) result_response_received = True cmd.result = parsed_response else: diff --git a/avocado/utils/kernel.py b/avocado/utils/kernel.py index 1badacce91..878e61e198 100644 --- a/avocado/utils/kernel.py +++ b/avocado/utils/kernel.py @@ -119,7 +119,7 @@ def uncompress(self): LOG.info("Uncompressing tarball") archive.extract(self.asset_path, self.work_dir) else: - raise Exception("Unable to find the tarball") + raise RuntimeError("Unable to find the tarball") def configure(self, targets=("defconfig"), extra_configs=None): """ diff --git a/examples/tests/multiple_tests.py b/examples/tests/multiple_tests.py index aabf441db9..826962d707 100644 --- a/examples/tests/multiple_tests.py +++ b/examples/tests/multiple_tests.py @@ -30,4 +30,4 @@ def action(): """ This method should never execute """ - raise Exception("This action method should never be executed.") + raise RuntimeError("This action method should never be executed.") diff --git a/examples/tests/uncaught_exception.py b/examples/tests/uncaught_exception.py index 3336607008..e1414e9343 100644 --- a/examples/tests/uncaught_exception.py +++ b/examples/tests/uncaught_exception.py @@ -14,4 +14,4 @@ def test(): """ This should end with ERROR. """ - raise Exception("This is a generic exception") + raise Exception("This is a generic exception") # pylint: disable=W0719