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 <js...@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 <js...@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