qapi/parser: move _insert_near_kind() method
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> Message-ID: <20260611042332.482979-9-jsnow@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
John Snow committed
Jun 11, 2026 at 00:23 UTC
6a1c092b01e5c9ee84964ccb2fc1cfd858d50fa4
1 file changed
+17
-16
scripts/qapi/parser.py
+17
-16
@@ -816,6 +816,22 @@ class QAPIDoc:
816
def append_line(self, line: str) -> None:
817
self.all_sections[-1].append_line(line)
818
819
+ def _insert_near_kind(
820
+ self,
821
+ kind: 'QAPIDoc.Kind',
822
+ new_sect: 'QAPIDoc.Section',
823
+ after: bool = False,
824
+ ) -> bool:
825
+ """Insert or append a new doc section at a specific point."""
826
+ for idx, sect in enumerate(reversed(self.all_sections)):
827
+ if sect.kind == kind:
828
+ pos = len(self.all_sections) - idx - 1
829
+ if after:
830
+ pos += 1
831
+ self.all_sections.insert(pos, new_sect)
832
+ return True
833
+ return False
834
+
835
def connect_member(self, member: 'QAPISchemaMember') -> None:
836
if member.name not in self._args:
837
assert member.info
@@ -850,28 +866,13 @@ class QAPIDoc:
866
self._features[feature.name].connect(feature)
867
868
def ensure_returns(self, info: QAPISourceInfo) -> None:
853
-
854
- def _insert_near_kind(
855
- kind: QAPIDoc.Kind,
856
- new_sect: QAPIDoc.Section,
857
- after: bool = False,
858
- ) -> bool:
859
- for idx, sect in enumerate(reversed(self.all_sections)):
860
- if sect.kind == kind:
861
- pos = len(self.all_sections) - idx - 1
862
- if after:
863
- pos += 1
864
- self.all_sections.insert(pos, new_sect)
865
- return True
866
- return False
867
-
869
if any(s.kind == QAPIDoc.Kind.RETURNS for s in self.all_sections):
870
return
871
872
# Stub "Returns" section for undocumented returns value
873
stub = QAPIDoc.Section(info, QAPIDoc.Kind.RETURNS)
874
874
- if any(_insert_near_kind(kind, stub, after) for kind, after in (
875
+ if any(self._insert_near_kind(kind, stub, after) for kind, after in (
876
# 1. If arguments, right after those.
877
(QAPIDoc.Kind.MEMBER, True),
878
# 2. Elif errors, right *before* those.