Move this function out from underneath `ensure_returns` and make it
available for general purpose use as an object method instead. This is
purely a scope-level patch with no functional changes.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qapi/parser.py | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
index 97e7dacb0fd..261f8ba9f8b 100644
--- a/scripts/qapi/parser.py
+++ b/scripts/qapi/parser.py
@@ -816,6 +816,22 @@ def new_feature(self, info: QAPISourceInfo, name: str) -> None:
def append_line(self, line: str) -> None:
self.all_sections[-1].append_line(line)
+ def _insert_near_kind(
+ self,
+ kind: 'QAPIDoc.Kind',
+ new_sect: 'QAPIDoc.Section',
+ after: bool = False,
+ ) -> bool:
+ """Insert or append a new doc section at a specific point."""
+ for idx, sect in enumerate(reversed(self.all_sections)):
+ if sect.kind == kind:
+ pos = len(self.all_sections) - idx - 1
+ if after:
+ pos += 1
+ self.all_sections.insert(pos, new_sect)
+ return True
+ return False
+
def connect_member(self, member: 'QAPISchemaMember') -> None:
if member.name not in self._args:
assert member.info
@@ -850,28 +866,13 @@ def connect_feature(self, feature: 'QAPISchemaFeature') -> None:
self._features[feature.name].connect(feature)
def ensure_returns(self, info: QAPISourceInfo) -> None:
-
- def _insert_near_kind(
- kind: QAPIDoc.Kind,
- new_sect: QAPIDoc.Section,
- after: bool = False,
- ) -> bool:
- for idx, sect in enumerate(reversed(self.all_sections)):
- if sect.kind == kind:
- pos = len(self.all_sections) - idx - 1
- if after:
- pos += 1
- self.all_sections.insert(pos, new_sect)
- return True
- return False
-
if any(s.kind == QAPIDoc.Kind.RETURNS for s in self.all_sections):
return
# Stub "Returns" section for undocumented returns value
stub = QAPIDoc.Section(info, QAPIDoc.Kind.RETURNS)
- if any(_insert_near_kind(kind, stub, after) for kind, after in (
+ if any(self._insert_near_kind(kind, stub, after) for kind, after in (
# 1. If arguments, right after those.
(QAPIDoc.Kind.MEMBER, True),
# 2. Elif errors, right *before* those.
--
2.54.0