qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 11/26] qapi/parser.py: Convert several methods to @classmethod


From: John Snow
Subject: [PATCH 11/26] qapi/parser.py: Convert several methods to @classmethod
Date: Tue, 22 Sep 2020 18:35:10 -0400

It's usually nicer to keep static methods as class methods -- this
allows them to call other class methods, to be subclassed and extended,
etc.

Meanwhile, any method that doesn't utilize `self` can be a class method.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 scripts/qapi/parser.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index 756c904257..75a693a9d7 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -139,15 +139,16 @@ def _parse(self):
     def _parse_error(self, msg: str) -> QAPIParseError:
         return QAPIParseError.make(self, msg)
 
-    @staticmethod
-    def reject_expr_doc(doc):
+    @classmethod
+    def reject_expr_doc(cls, doc):
         if doc and doc.symbol:
             raise QAPISemError(
                 doc.info,
                 "documentation for '%s' is not followed by the definition"
                 % doc.symbol)
 
-    def _include(self, include, info, incl_fname, previously_included):
+    @classmethod
+    def _include(cls, include, info, incl_fname, previously_included):
         incl_abs_fname = os.path.abspath(incl_fname)
         # catch inclusion cycle
         inf = info
@@ -162,7 +163,8 @@ def _include(self, include, info, incl_fname, 
previously_included):
 
         return QAPISchemaParser(incl_fname, previously_included, info)
 
-    def _pragma(self, name, value, info):
+    @classmethod
+    def _pragma(cls, name, value, info):
         if name == 'doc-required':
             if not isinstance(value, bool):
                 raise QAPISemError(info,
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]