From: Markus Armbruster <armbru@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: qemu-devel@nongnu.org, "Peter Xu" <peterx@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Stefan Berger" <stefanb@linux.vnet.ibm.com>,
"Fabiano Rosas" <farosas@suse.de>,
"Hanna Reitz" <hreitz@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Zhao Liu" <zhao1.liu@intel.com>, "Kevin Wolf" <kwolf@redhat.com>,
"Ani Sinha" <anisinha@redhat.com>,
"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
"Jiri Pirko" <jiri@resnulli.us>,
"Alex Williamson" <alex@shazbot.org>,
"Kashyap Chamarthy" <kchamart@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Kostiantyn Kostiuk" <kkostiuk@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Michael Roth" <michael.roth@amd.com>,
"Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
"Vladimir Sementsov-Ogievskiy" <vsementsov@yandex-team.ru>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
qemu-block@nongnu.org, "Cédric Le Goater" <clg@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Igor Mammedov" <imammedo@redhat.com>,
"Jason Wang" <jasowangio@gmail.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Eric Blake" <eblake@redhat.com>
Subject: Re: [PATCH 14/14] qapi/parser: convert single-section properties to getter properties
Date: Fri, 02 Oct 2026 11:44:21 +0200 [thread overview]
Message-ID: <87cxts4etm.fsf@pond.sub.org> (raw)
In-Reply-To: <20260928223657.2303684-15-jsnow@redhat.com> (John Snow's message of "Mon, 28 Sep 2026 18:36:57 -0400")
John Snow <jsnow@redhat.com> writes:
> Remove dedicated pointers to single sections, instead preferring a
> functional getter property that returns the same thing dynamically.
>
> This is being done mainly for the benefit of being able to condense
> the _append() function, but I'm not convinced it's worth it. I'm not
> convinced it's not not worth it either, though.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> scripts/qapi/parser.py | 47 +++++++++++++++++++++++-------------------
> 1 file changed, 26 insertions(+), 21 deletions(-)
Hmm.
> diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py
> index 1d8f1d39ab1..d4b5b3e5ab6 100644
> --- a/scripts/qapi/parser.py
> +++ b/scripts/qapi/parser.py
> @@ -773,12 +773,6 @@ def __init__(self, info: QAPISourceInfo, symbol: Optional[str] = None):
> self._args: Dict[str, QAPIDoc.ArgSection] = {}
> self._features: Dict[str, QAPIDoc.ArgSection] = {}
>
> - # a command's "Returns" and "Errors" section
> - self._returns: Optional[QAPIDoc.Section] = None
> - self._errors: Optional[QAPIDoc.Section] = None
> - # "Since" section
> - self.since: Optional[QAPIDoc.Section] = None
> -
> @property
> def has_features(self) -> bool:
> return bool(self._features)
> @@ -790,21 +784,10 @@ def _append(self, section: 'QAPIDoc.Section') -> None:
> All other methods/helpers/etc ultimately use this and only
> this interface for appending a new section.
> """
> - if section.kind == QAPIDoc.Kind.RETURNS:
> - if self._returns:
> - raise QAPISemError(
> - section.info, "duplicated '%s' section" % section.kind)
> - self._returns = section
> - elif section.kind == QAPIDoc.Kind.ERRORS:
> - if self._errors:
> - raise QAPISemError(
> - section.info, "duplicated '%s' section" % section.kind)
> - self._errors = section
> - elif section.kind == QAPIDoc.Kind.SINCE:
> - if self.since:
> - raise QAPISemError(
> - section.info, "duplicated '%s' section" % section.kind)
> - self.since = section
> + if str(section.kind) in ('Intro', 'Returns', 'Errors', 'Since'):
> + if self._sections[section.kind]:
> + raise QAPISemError(section.info,
> + "duplicated '%s' section" % section.kind)
> self._sections[section.kind].append(section)
> self._active_section = section
>
Likable so far.
> @@ -815,6 +798,28 @@ def __iter__(self) -> Iterator['QAPIDoc.Section']:
> def __len__(self) -> int:
> return sum(len(x) for x in self._sections.values())
>
> + def _single_section_property(
> + self,
> + kind: 'QAPIDoc.Kind'
> + ) -> Optional['QAPIDoc.Section']:
> + try:
> + return self._sections[kind][0]
> + except IndexError:
> + pass
> + return None
Returns the first section of a kind. Let's name it after what it does:
_first_section().
The try works, but
return self._sections[kind][0] if self._sections[kind] else None
seems to work as well, and with less ceremony :)
> +
> + @property
> + def _returns(self) -> Optional['QAPIDoc.Section']:
> + return self._single_section_property(QAPIDoc.Kind.RETURNS)
> +
> + @property
> + def _errors(self) -> Optional['QAPIDoc.Section']:
> + return self._single_section_property(QAPIDoc.Kind.ERRORS)
> +
> + @property
> + def since(self) -> Optional['QAPIDoc.Section']:
> + return self._single_section_property(QAPIDoc.Kind.SINCE)
> +
> def end(self) -> None:
> for section in self:
> section.text = section.text.strip('\n')
prev parent reply other threads:[~2026-10-02 9:44 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 22:36 [PATCH 00/14] qapi: enforce section ordering John Snow
2026-09-28 22:36 ` [PATCH 01/14] qapi: rename "plain" sections to "details" John Snow
2026-09-29 11:49 ` Markus Armbruster
2026-09-29 14:36 ` John Snow
2026-09-28 22:36 ` [PATCH 02/14] docs/qapi-code-gen: expand each section's syntax into a mini-section John Snow
2026-09-28 22:36 ` [PATCH 03/14] qapi: re-order QAPI doc block sections John Snow
2026-09-29 12:10 ` Markus Armbruster
2026-09-29 14:32 ` John Snow
2026-09-28 22:36 ` [PATCH 04/14] qapi/parser: enforce doc block section ordering John Snow
2026-09-29 12:36 ` Markus Armbruster
2026-09-29 14:31 ` John Snow
2026-09-29 15:00 ` Markus Armbruster
2026-09-28 22:36 ` [PATCH 05/14] qapi: move 'details' sections to the bottom of doc blocks John Snow
2026-10-01 11:14 ` Markus Armbruster
2026-09-28 22:36 ` [PATCH 06/14] qapi/parser: enforce 'details' sections' relative position John Snow
2026-09-28 22:36 ` [PATCH 07/14] qapi: re-order 'since' sections to always be last John Snow
2026-09-28 22:36 ` [PATCH 08/14] qapi/parser: enforce strict positioning for "Since:" section John Snow
2026-09-29 12:53 ` Markus Armbruster
2026-09-29 14:25 ` John Snow
2026-09-29 15:04 ` Markus Armbruster
2026-09-28 22:36 ` [PATCH 09/14] qapi/parser: remove _insert_after_intro() helper John Snow
2026-09-29 13:09 ` Markus Armbruster
2026-09-29 14:19 ` John Snow
2026-09-29 15:08 ` Markus Armbruster
2026-09-28 22:36 ` [PATCH 10/14] qapi/parser: add _append() method John Snow
2026-09-29 13:28 ` Markus Armbruster
2026-09-29 14:14 ` John Snow
2026-09-29 15:09 ` Markus Armbruster
2026-09-28 22:36 ` [PATCH 11/14] qapi/parser: privatize "all_sections" field as "_sections" John Snow
2026-10-02 8:51 ` Markus Armbruster
2026-09-28 22:36 ` [PATCH 12/14] qapi/parser: add _active_section private member John Snow
2026-09-28 22:36 ` [PATCH 13/14] qapi/parser: add new _sections mapping John Snow
2026-10-02 7:24 ` Markus Armbruster
2026-09-28 22:36 ` [PATCH 14/14] qapi/parser: convert single-section properties to getter properties John Snow
2026-10-02 9:44 ` Markus Armbruster [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87cxts4etm.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=alex@shazbot.org \
--cc=anisinha@redhat.com \
--cc=berrange@redhat.com \
--cc=clg@redhat.com \
--cc=eblake@redhat.com \
--cc=farosas@suse.de \
--cc=hreitz@redhat.com \
--cc=imammedo@redhat.com \
--cc=jasowangio@gmail.com \
--cc=jiri@resnulli.us \
--cc=jsnow@redhat.com \
--cc=kchamart@redhat.com \
--cc=kkostiuk@redhat.com \
--cc=kwolf@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mchehab+huawei@kernel.org \
--cc=michael.roth@amd.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@oss.qualcomm.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=sgarzare@redhat.com \
--cc=stefanb@linux.vnet.ibm.com \
--cc=stefanha@redhat.com \
--cc=vsementsov@yandex-team.ru \
--cc=zhao1.liu@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.