[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/6] qapi/parser: Allow empty QAPIDoc Sections
From: |
John Snow |
Subject: |
[PATCH 2/6] qapi/parser: Allow empty QAPIDoc Sections |
Date: |
Wed, 19 May 2021 15:17:14 -0400 |
It simplifies the typing to say that _section is always a
QAPIDoc.Section().
To accommodate this change, we must allow for this object to evaluate to
False for functions like _end_section which behave differently based on
whether or not a Section has been started.
Signed-off-by: John Snow <jsnow@redhat.com>
---
Probably a better fix is to restructure the code to prevent
_end_section() from being called twice in a row, but that seemed like
more effort, but if you have suggestions for a tactical fix, I'm open to
it.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/parser.py | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index b3a468504fc..71e982bff57 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -456,6 +456,9 @@ def __init__(self, parser, name=None, indent=0):
# the expected indent level of the text of this section
self._indent = indent
+ def __bool__(self) -> bool:
+ return bool(self.name or self.text)
+
def append(self, line):
# Strip leading spaces corresponding to the expected indent level
# Blank lines are always OK.
@@ -722,7 +725,7 @@ def _end_section(self):
raise QAPIParseError(
self._parser,
"empty doc section '%s'" % self._section.name)
- self._section = None
+ self._section = QAPIDoc.Section(self._parser)
def _append_freeform(self, line):
match = re.match(r'(@\S+:)', line)
--
2.30.2
[PATCH 4/6] qapi/parser.py: enable mypy checks, John Snow, 2021/05/19
[PATCH 1/6] qapi/parser.py: remove unused check_args_section arguments, John Snow, 2021/05/19
[PATCH 5/6] qapi/parser.py: Silence too-few-public-methods warning, John Snow, 2021/05/19
[PATCH 6/6] qapi/parser.py: enable pylint checks, John Snow, 2021/05/19
[PATCH 3/6] qapi/parser.py: add type hint annotations (QAPIDoc), John Snow, 2021/05/19