[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 2/6] qapi/parser: Allow empty QAPIDoc Sections
From: |
John Snow |
Subject: |
[PATCH v2 2/6] qapi/parser: Allow empty QAPIDoc Sections |
Date: |
Thu, 20 May 2021 18:57:06 -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 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 --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(
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 v2 0/6] qapi: static typing conversion, pt5b, John Snow, 2021/05/20
- [PATCH v2 3/6] qapi/parser: add type hint annotations (QAPIDoc), John Snow, 2021/05/20
- [PATCH v2 6/6] qapi/parser: enable pylint checks, John Snow, 2021/05/20
- [PATCH v2 2/6] qapi/parser: Allow empty QAPIDoc Sections,
John Snow <=
- [PATCH v2 4/6] qapi/parser: enable mypy checks, John Snow, 2021/05/20
- [PATCH v2 1/6] qapi/parser: fix unused check_args_section arguments, John Snow, 2021/05/20
- [PATCH v2 5/6] qapi/parser: Silence too-few-public-methods warning, John Snow, 2021/05/20