diff mbox series

[v2,02/62] qapi: shush pylint up

Message ID 20250309083550.5155-3-jsnow@redhat.com (mailing list archive)
State New
Headers show
Series docs: Add new QAPI transmogrifier | expand

Commit Message

John Snow March 9, 2025, 8:34 a.m. UTC
Shhhhh!

This patch is RFC quality, I wasn't in the mood to actually solve
problems so much as I was in the mood to continue working on the Sphinx
rework. Plus, I don't think the code I am patching has hit origin/master
yet ...

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qapi/backend.py | 2 ++
 scripts/qapi/main.py    | 8 +++-----
 2 files changed, 5 insertions(+), 5 deletions(-)

Comments

Markus Armbruster March 9, 2025, 7:41 p.m. UTC | #1
John Snow <jsnow@redhat.com> writes:

> Shhhhh!
>
> This patch is RFC quality, I wasn't in the mood to actually solve
> problems so much as I was in the mood to continue working on the Sphinx
> rework.

Does this patch leave anything in need of cleanup?  If yes, mark the
spots with TODO comments, please.  If no, drop the sentence above?

>         Plus, I don't think the code I am patching has hit origin/master
> yet ...

This is no longer correct.

> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  scripts/qapi/backend.py | 2 ++
>  scripts/qapi/main.py    | 8 +++-----
>  2 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/qapi/backend.py b/scripts/qapi/backend.py
> index 14e60aa67af..49ae6ecdd33 100644
> --- a/scripts/qapi/backend.py
> +++ b/scripts/qapi/backend.py
> @@ -13,6 +13,7 @@
>  
>  
>  class QAPIBackend(ABC):
> +    # pylint: disable=too-few-public-methods
>  
>      @abstractmethod
>      def generate(self,
> @@ -36,6 +37,7 @@ def generate(self,
>  
>  
>  class QAPICBackend(QAPIBackend):
> +    # pylint: disable=too-few-public-methods
>  
>      def generate(self,
>                   schema: QAPISchema,
> diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py
> index 5b4679abcf1..01155373bd0 100644
> --- a/scripts/qapi/main.py
> +++ b/scripts/qapi/main.py
> @@ -38,8 +38,7 @@ def create_backend(path: str) -> QAPIBackend:
>      try:
>          mod = import_module(module_path)
>      except Exception as ex:
> -        print(f"unable to import '{module_path}': {ex}", file=sys.stderr)
> -        sys.exit(1)
> +        raise QAPIError(f"unable to import '{module_path}': {ex}") from ex
>  
>      try:
>          klass = getattr(mod, class_name)
> @@ -51,9 +50,8 @@ def create_backend(path: str) -> QAPIBackend:
>      try:
>          backend = klass()
>      except Exception as ex:
> -        print(f"backend '{path}' cannot be instantiated: {ex}",
> -              file=sys.stderr)
> -        sys.exit(1)
> +        raise QAPIError(
> +            f"backend '{path}' cannot be instantiated: {ex}") from ex
>  
>      if not isinstance(backend, QAPIBackend):
>          print(f"backend '{path}' must be an instance of QAPIBackend",

Missed in my review of the patch that added this code: the caller
catches QAPIError, and returns non-zero exit code on catch.  The
caller's caller passes the exit code to sys.exit().  Leaving the
sys.exit() to the callers is cleaner.

However, you convert only two out of five error paths from sys.exit() to
raise.  All or nothing, please.

Maybe split the patch into a "# pylint:" and a "raise QAPIError" part?
diff mbox series

Patch

diff --git a/scripts/qapi/backend.py b/scripts/qapi/backend.py
index 14e60aa67af..49ae6ecdd33 100644
--- a/scripts/qapi/backend.py
+++ b/scripts/qapi/backend.py
@@ -13,6 +13,7 @@ 
 
 
 class QAPIBackend(ABC):
+    # pylint: disable=too-few-public-methods
 
     @abstractmethod
     def generate(self,
@@ -36,6 +37,7 @@  def generate(self,
 
 
 class QAPICBackend(QAPIBackend):
+    # pylint: disable=too-few-public-methods
 
     def generate(self,
                  schema: QAPISchema,
diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py
index 5b4679abcf1..01155373bd0 100644
--- a/scripts/qapi/main.py
+++ b/scripts/qapi/main.py
@@ -38,8 +38,7 @@  def create_backend(path: str) -> QAPIBackend:
     try:
         mod = import_module(module_path)
     except Exception as ex:
-        print(f"unable to import '{module_path}': {ex}", file=sys.stderr)
-        sys.exit(1)
+        raise QAPIError(f"unable to import '{module_path}': {ex}") from ex
 
     try:
         klass = getattr(mod, class_name)
@@ -51,9 +50,8 @@  def create_backend(path: str) -> QAPIBackend:
     try:
         backend = klass()
     except Exception as ex:
-        print(f"backend '{path}' cannot be instantiated: {ex}",
-              file=sys.stderr)
-        sys.exit(1)
+        raise QAPIError(
+            f"backend '{path}' cannot be instantiated: {ex}") from ex
 
     if not isinstance(backend, QAPIBackend):
         print(f"backend '{path}' must be an instance of QAPIBackend",