[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
- [PATCH 03/26] qapi/parser.py: use 'with' statement for opening files, (continued)
- [PATCH 03/26] qapi/parser.py: use 'with' statement for opening files, John Snow, 2020/09/22
- [PATCH 02/26] qapi/parser.py: group variable declarations in __init__, John Snow, 2020/09/22
- [PATCH 04/26] qapi/source.py: Add default arguments to QAPISourceInfo, John Snow, 2020/09/22
- [PATCH 01/26] qapi/parser.py: refactor parsing routine into method, John Snow, 2020/09/22
- [PATCH 05/26] qapi/parser.py: start source info at line 0, John Snow, 2020/09/22
- [PATCH 07/26] qapi/parser.py: fully remove 'null' constant, John Snow, 2020/09/22
- [PATCH 08/26] qapi/parser.py: Assert lexer value is a string, John Snow, 2020/09/22
- [PATCH 06/26] qapi/parser.py: raise QAPIParseError during file opening, John Snow, 2020/09/22
- [PATCH 09/26] qapi/parser.py: assert get_expr returns object in outer loop, John Snow, 2020/09/22
- [PATCH 10/26] qapi/parser.py: assert object keys are strings, John Snow, 2020/09/22
- [PATCH 11/26] qapi/parser.py: Convert several methods to @classmethod,
John Snow <=
- [PATCH 12/26] qapi/parser.py: add casts to pragma checks, John Snow, 2020/09/22
- [PATCH 13/26] qapi/parser.py: add type hint annotations, John Snow, 2020/09/22
- [PATCH 14/26] qapi/parser.py: add docstrings, John Snow, 2020/09/22
- [PATCH 15/26] qapi/parser.py: add ParsedExpression type, John Snow, 2020/09/22
- [PATCH 16/26] qapi/pragma.py: Move QAPISchemaPragma into its own module, John Snow, 2020/09/22
- [PATCH 18/26] qapi/parser.py: Modify _include() to use parser state, John Snow, 2020/09/22
- [PATCH 17/26] qapi/pragma.py: Move pragma parsing out of parser.py, John Snow, 2020/09/22
- [PATCH 20/26] qapi/parser.py: remove unused check_args_section arguments, John Snow, 2020/09/22
- [PATCH 21/26] qapi/parser.py: QAPIDoc: convert @staticmethod to @classmethod, John Snow, 2020/09/22
- [PATCH 19/26] qapi/parser.py: add parent argument, John Snow, 2020/09/22