diff mbox series

[v2,2/6] qapi/parser: Allow empty QAPIDoc Sections

Message ID 20210520225710.168356-3-jsnow@redhat.com (mailing list archive)
State New, archived
Headers show
Series qapi: static typing conversion, pt5b | expand

Commit Message

John Snow May 20, 2021, 10:57 p.m. UTC
It simplifies the typing to say that _section is always a

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 empty
sections from being "ended", but that seems like a bigger whale than
what I'm after at the immediate moment.

Signed-off-by: John Snow <jsnow@redhat.com>
 scripts/qapi/parser.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series


diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index b6a5e661215..3ddde318376 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(
                     "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)