From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C334CC61D85 for ; Tue, 21 Nov 2023 16:23:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5TWP-0003Ev-Sz; Tue, 21 Nov 2023 11:22:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5TWO-0003D2-LC for qemu-devel@nongnu.org; Tue, 21 Nov 2023 11:22:44 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r5TWG-00007W-9y for qemu-devel@nongnu.org; Tue, 21 Nov 2023 11:22:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700583755; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iKrWq8hYNxNitToJJ2FwQguLHu1JtQpMCh0VMxvX1XA=; b=LvctjzDnKvTZXzmIk+K8rYw4pY0jmeWQxrqpxZ2aOvQ3l8aAMz1mzTU5GBayTlSkCLM2o4 sFC83RVDXcEkOdldpgKKJ3lvUB/szUtefO6RjUYJ9LDMMVvvfAWP43rD9g1mfldeFovM8N O6gXKbETTEchZCSK/zrKvZNDNsDws1M= Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-166-GrV2hoVfM7aEZ6gKc0Tzig-1; Tue, 21 Nov 2023 11:22:29 -0500 X-MC-Unique: GrV2hoVfM7aEZ6gKc0Tzig-1 Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-2839e23f151so5775551a91.0 for ; Tue, 21 Nov 2023 08:22:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700583748; x=1701188548; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iKrWq8hYNxNitToJJ2FwQguLHu1JtQpMCh0VMxvX1XA=; b=i6Ixr2FNgFTaeyglyGNS1G0wWMsH5iULySsEXgoL/DuRghrFfBMgNHRorzSgLDPtBn FmP4nbQVcVnjKU9rcOzbT9rvOojnF20O+kkskU3aRtmu4OEiUxcFzPJlOocepAs2BJsF e44w5LpU1v142pBlFNyPlPEB6EnrWUvqGOLy6GqqkaMqQGJTnoruiyT9LFycF3e1cVDP o0E1TJMV5i7yCH8Fun4NYTAVllfaG8y2kSUQFVG3OqmM0zIu3TjLignmVPhWEU9WJi6K UNR80O46MmsQB6br35yftmNbYlV5/dNom3mokevfVDHaWOJpRlzdxmJg+p+pp7ATGMNK Sfmg== X-Gm-Message-State: AOJu0Yyaj+PA1N+dQIs5pLN5QfPj1UOS0r0uiU3uUAReayFw2EORUfuD WIzZyjJG4gcM/c0rheZYpsR69u5W0wuiYG5o7UZgoZyBNdNEU2AhkHRL6gt6QIKbyI365nc8Hg5 INHr0KvUciyZGqFHZWFGX9XbuTufsvzM= X-Received: by 2002:a17:90a:d18f:b0:280:cd5f:bf90 with SMTP id fu15-20020a17090ad18f00b00280cd5fbf90mr9487643pjb.23.1700583748328; Tue, 21 Nov 2023 08:22:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IFe/JoL52dDfOazaWUh2ClemhhQBtSYoYdSpzIMWzgr+hUt2Uk9GLgjr/Ji28pA/IA4/YcC1aQ+n6tuvNGmGxI= X-Received: by 2002:a17:90a:d18f:b0:280:cd5f:bf90 with SMTP id fu15-20020a17090ad18f00b00280cd5fbf90mr9487619pjb.23.1700583747877; Tue, 21 Nov 2023 08:22:27 -0800 (PST) MIME-Version: 1.0 References: <20231116014350.653792-1-jsnow@redhat.com> <20231116014350.653792-4-jsnow@redhat.com> <87o7fn44em.fsf@pond.sub.org> In-Reply-To: <87o7fn44em.fsf@pond.sub.org> From: John Snow Date: Tue, 21 Nov 2023 11:22:16 -0500 Message-ID: Subject: Re: [PATCH 03/19] qapi/schema: name QAPISchemaInclude entities To: Markus Armbruster Cc: qemu-devel , Peter Maydell , Michael Roth Content-Type: multipart/alternative; boundary="000000000000341590060aac0238" Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org --000000000000341590060aac0238 Content-Type: text/plain; charset="UTF-8" On Tue, Nov 21, 2023, 8:33 AM Markus Armbruster wrote: > John Snow writes: > > > It simplifies typing to mandate that entities will always have a name; > > to achieve this we can occasionally assign an internal name. This > > alleviates errors such as: > > > > qapi/schema.py:287: error: Argument 1 to "__init__" of > > "QAPISchemaEntity" has incompatible type "None"; expected "str" > > [arg-type] > > > > Trying to fix it the other way by allowing entities to only have > > optional names opens up a nightmare portal of whackamole to try and > > audit that every other pathway doesn't actually pass a None name when we > > expect it to; this is the simpler direction of consitifying the typing. > > Arguably, that nightmare is compile-time proof of "we are not mistaking > QAPISchemaInclude for a named entity". > > When I added the include directive, I shoehorned it into the existing > representation of the QAPI schema as "list of QAPISchemaEntity" by > making it a subtype of QAPISchemaEntity. That was a somewhat lazy hack. > > Note that qapi-code-gen.rst distinguishes between definitions and > directives. > > The places where mypy gripes that .name isn't 'str' generally want > something with a name (what qapi-code-gen.rst calls a definition). If > we somehow pass them an include directive, they'll use None for a name, > which is no good. mypy is pointing out this problem. > > What to do about it? > > 1. Paper it over: give include directives some made-up name (this > patch). Now the places use the made-up name instead of None, and mypy > can't see the problem anymore. > > 2. Assert .name is not None until mypy is happy. I guess that's what > you called opening "a nightmare portal of whackamole". > Yep. > 3. Clean up the typing: have a type for top-level expression (has no > name), and a subtype for definition (has a name). Rough sketch > appended. Thoughts? > Oh, that'll work. I tried to keep to "minimal SLOC" but where you want to see deeper fixes, I'm happy to deviate. I'll give it a shot. > > Signed-off-by: John Snow > > --- > > scripts/qapi/schema.py | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py > > index 153e703e0ef..0fb44452dd5 100644 > > --- a/scripts/qapi/schema.py > > +++ b/scripts/qapi/schema.py > > @@ -220,7 +220,9 @@ def visit(self, visitor): > > > > class QAPISchemaInclude(QAPISchemaEntity): > > def __init__(self, sub_module, info): > > - super().__init__(None, info, None) > > + # Includes are internal entity objects; and may occur multiple > times > > + name = f"q_include_{info.fname}:{info.line}" > > + super().__init__(name, info, None) > > self._sub_module = sub_module > > > > def visit(self, visitor): > > There are two instances of .name is None: > > def __repr__(self) -> str: > if self.name is None: > return "<%s at 0x%x>" % (type(self).__name__, id(self)) > return "<%s:%s at 0x%x>" % (type(self).__name__, self.name, > id(self)) > > and > > def _def_entity(self, ent: QAPISchemaEntity) -> None: > # Only the predefined types are allowed to not have info > assert ent.info or self._predefining > self._entity_list.append(ent) > if ent.name is None: > return > [...] > > Don't they need to be updated? > Oh, yes. I remove some assertions later in the series but I very likely missed these if cases. > > > diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py > index 24ad166d52..eaff1df534 100644 > --- a/scripts/qapi/schema.py > +++ b/scripts/qapi/schema.py > @@ -70,6 +70,45 @@ def is_present(self) -> bool: > > > class QAPISchemaEntity: > + def __init__(self, info: Optional[QAPISourceInfo]): > + # For explicitly defined entities, info points to the (explicit) > + # definition. For builtins (and their arrays), info is None. > + # For implicitly defined entities, info points to a place that > + # triggered the implicit definition (there may be more than one > + # such place). > + self.info = info > + self._module: Optional[QAPISchemaModule] = None > + self._checked = False > + > + def __repr__(self) -> str: > + return "<%s at 0x%x>" % (type(self).__name__, id(self)) > + > + def check(self, schema: QAPISchema) -> None: > + self._checked = True > + > + def connect_doc(self, doc: Optional[QAPIDoc] = None) -> None: > + pass > + > + def check_doc(self) -> None: > + pass > + > + def _set_module( > + self, schema: QAPISchema, info: Optional[QAPISourceInfo] > + ) -> None: > + assert self._checked > + fname = info.fname if info else > QAPISchemaModule.BUILTIN_MODULE_NAME > + self._module = schema.module_by_fname(fname) > + self._module.add_entity(self) > + > + def set_module(self, schema: QAPISchema) -> None: > + self._set_module(schema, self.info) > + > + def visit(self, visitor: QAPISchemaVisitor) -> None: > + # pylint: disable=unused-argument > + assert self._checked > + > + > +class QAPISchemaDefinition(QAPISchemaEntity): > meta: str > > def __init__( > @@ -80,24 +119,16 @@ def __init__( > ifcond: Optional[QAPISchemaIfCond] = None, > features: Optional[List[QAPISchemaFeature]] = None, > ): > + super().__init__(info) > for f in features or []: > f.set_defined_in(name) > self.name = name > - self._module: Optional[QAPISchemaModule] = None > - # For explicitly defined entities, info points to the (explicit) > - # definition. For builtins (and their arrays), info is None. > - # For implicitly defined entities, info points to a place that > - # triggered the implicit definition (there may be more than one > - # such place). > - self.info = info > self.doc = doc > self._ifcond = ifcond or QAPISchemaIfCond() > self.features = features or [] > self._checked = False > - > + > def __repr__(self) -> str: > - if self.name is None: > - return "<%s at 0x%x>" % (type(self).__name__, id(self)) > return "<%s:%s at 0x%x>" % (type(self).__name__, self.name, > id(self)) > > @@ -122,17 +153,6 @@ def check_doc(self) -> None: > if self.doc: > self.doc.check() > > - def _set_module( > - self, schema: QAPISchema, info: Optional[QAPISourceInfo] > - ) -> None: > - assert self._checked > - fname = info.fname if info else > QAPISchemaModule.BUILTIN_MODULE_NAME > - self._module = schema.module_by_fname(fname) > - self._module.add_entity(self) > - > - def set_module(self, schema: QAPISchema) -> None: > - self._set_module(schema, self.info) > - > @property > def ifcond(self) -> QAPISchemaIfCond: > assert self._checked > @@ -141,10 +161,6 @@ def ifcond(self) -> QAPISchemaIfCond: > def is_implicit(self) -> bool: > return not self.info > > - def visit(self, visitor: QAPISchemaVisitor) -> None: > - # pylint: disable=unused-argument > - assert self._checked > - > def describe(self) -> str: > return "%s '%s'" % (self.meta, self.name) > > @@ -301,9 +317,7 @@ def visit(self, visitor: QAPISchemaVisitor) -> None: > > class QAPISchemaInclude(QAPISchemaEntity): > def __init__(self, sub_module: QAPISchemaModule, info: > QAPISourceInfo): > - # Includes are internal entity objects; and may occur multiple > times > - name = f"q_include_{info.fname}:{info.line}" > - super().__init__(name, info, None) > + super().__init__(info) > self._sub_module = sub_module > > def visit(self, visitor: QAPISchemaVisitor) -> None: > @@ -311,7 +325,7 @@ def visit(self, visitor: QAPISchemaVisitor) -> None: > visitor.visit_include(self._sub_module.name, self.info) > > > -class QAPISchemaType(QAPISchemaEntity): > +class QAPISchemaType(QAPISchemaDefinition): > # Return the C type for common use. > # For the types we commonly box, this is a pointer type. > def c_type(self) -> str: > @@ -977,7 +991,7 @@ def __init__( > super().__init__(name, info, typ, False, ifcond) > > > -class QAPISchemaCommand(QAPISchemaEntity): > +class QAPISchemaCommand(QAPISchemaDefinition): > meta = 'command' > > def __init__( > @@ -1059,7 +1073,7 @@ def visit(self, visitor: QAPISchemaVisitor) -> None: > self.coroutine) > > > -class QAPISchemaEvent(QAPISchemaEntity): > +class QAPISchemaEvent(QAPISchemaDefinition): > meta = 'event' > > def __init__( > @@ -1133,7 +1147,7 @@ def __init__(self, fname: str): > exprs = check_exprs(parser.exprs) > self.docs = parser.docs > self._entity_list: List[QAPISchemaEntity] = [] > - self._entity_dict: Dict[str, QAPISchemaEntity] = {} > + self._entity_dict: Dict[str, QAPISchemaDefinition] = {} > self._module_dict: Dict[str, QAPISchemaModule] = OrderedDict() > self._schema_dir = os.path.dirname(fname) > self._make_module(QAPISchemaModule.BUILTIN_MODULE_NAME) > @@ -1145,9 +1159,12 @@ def __init__(self, fname: str): > self.check() > > def _def_entity(self, ent: QAPISchemaEntity) -> None: > + self._entity_list.append(ent) > + > + def _def_definition(self, ent: QAPISchemaDefinition) -> None: > # Only the predefined types are allowed to not have info > assert ent.info or self._predefining > - self._entity_list.append(ent) > + self._def_entity(ent) > if ent.name is None: > return > # TODO reject names that differ only in '_' vs. '.' vs. '-', > @@ -1163,7 +1180,7 @@ def _def_entity(self, ent: QAPISchemaEntity) -> None: > ent.info, "%s is already defined" % other_ent.describe()) > self._entity_dict[ent.name] = ent > > - def get_entity(self, name: str) -> Optional[QAPISchemaEntity]: > + def get_definition(self, name: str) -> Optional[QAPISchemaDefinition]: > return self._entity_dict.get(name) > > def get_typed_entity( > @@ -1171,7 +1188,7 @@ def get_typed_entity( > name: str, > typ: Type[_EntityType] > ) -> Optional[_EntityType]: > - ent = self.get_entity(name) > + ent = self.get_definition(name) > if ent is not None and not isinstance(ent, typ): > etype = type(ent).__name__ > ttype = typ.__name__ > @@ -1225,7 +1242,7 @@ def _def_include(self, expr: QAPIExpression) -> None: > def _def_builtin_type( > self, name: str, json_type: str, c_type: str > ) -> None: > - self._def_entity(QAPISchemaBuiltinType(name, json_type, c_type)) > + self._def_definition(QAPISchemaBuiltinType(name, json_type, > c_type)) > # Instantiating only the arrays that are actually used would > # be nice, but we can't as long as their generated code > # (qapi-builtin-types.[ch]) may be shared by some other > @@ -1251,14 +1268,14 @@ def _def_predefineds(self) -> None: > self._def_builtin_type(*t) > self.the_empty_object_type = QAPISchemaObjectType( > 'q_empty', None, None, None, None, None, [], None) > - self._def_entity(self.the_empty_object_type) > + self._def_definition(self.the_empty_object_type) > > qtypes = ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', > 'qbool'] > qtype_values = self._make_enum_members( > [{'name': n} for n in qtypes], None) > > - self._def_entity(QAPISchemaEnumType('QType', None, None, None, > None, > + self._def_definition(QAPISchemaEnumType('QType', None, None, > None, None, > qtype_values, 'QTYPE')) > > def _make_features( > @@ -1294,8 +1311,8 @@ def _make_array_type( > self, element_type: str, info: Optional[QAPISourceInfo] > ) -> str: > name = element_type + 'List' # reserved by > check_defn_name_str() > - if not self.get_entity(name): > - self._def_entity(QAPISchemaArrayType(name, info, > element_type)) > + if not self.get_definition(name): > + self._def_definition(QAPISchemaArrayType(name, info, > element_type)) > return name > > def _make_implicit_object_type( > @@ -1317,7 +1334,7 @@ def _make_implicit_object_type( > # later. > pass > else: > - self._def_entity(QAPISchemaObjectType( > + self._def_definition(QAPISchemaObjectType( > name, info, None, ifcond, None, None, members, None)) > return name > > @@ -1328,7 +1345,7 @@ def _def_enum_type(self, expr: QAPIExpression) -> > None: > ifcond = QAPISchemaIfCond(expr.get('if')) > info = expr.info > features = self._make_features(expr.get('features'), info) > - self._def_entity(QAPISchemaEnumType( > + self._def_definition(QAPISchemaEnumType( > name, info, expr.doc, ifcond, features, > self._make_enum_members(data, info), prefix)) > > @@ -1367,7 +1384,7 @@ def _def_struct_type(self, expr: QAPIExpression) -> > None: > info = expr.info > ifcond = QAPISchemaIfCond(expr.get('if')) > features = self._make_features(expr.get('features'), info) > - self._def_entity(QAPISchemaObjectType( > + self._def_definition(QAPISchemaObjectType( > name, info, expr.doc, ifcond, features, base, > self._make_members(data, info), > None)) > @@ -1403,7 +1420,7 @@ def _def_union_type(self, expr: QAPIExpression) -> > None: > info) > for (key, value) in data.items()] > members: List[QAPISchemaObjectTypeMember] = [] > - self._def_entity( > + self._def_definition( > QAPISchemaObjectType(name, info, expr.doc, ifcond, features, > base, members, > QAPISchemaVariants( > @@ -1422,7 +1439,7 @@ def _def_alternate_type(self, expr: QAPIExpression) > -> None: > info) > for (key, value) in data.items()] > tag_member = QAPISchemaObjectTypeMember('type', info, 'QType', > False) > - self._def_entity( > + self._def_definition( > QAPISchemaAlternateType( > name, info, expr.doc, ifcond, features, > QAPISchemaVariants(None, info, tag_member, variants))) > @@ -1447,7 +1464,7 @@ def _def_command(self, expr: QAPIExpression) -> None: > if isinstance(rets, list): > assert len(rets) == 1 > rets = self._make_array_type(rets[0], info) > - self._def_entity(QAPISchemaCommand(name, info, expr.doc, ifcond, > + self._def_definition(QAPISchemaCommand(name, info, expr.doc, > ifcond, > features, data, rets, > gen, success_response, > boxed, allow_oob, > allow_preconfig, > @@ -1464,7 +1481,7 @@ def _def_event(self, expr: QAPIExpression) -> None: > data = self._make_implicit_object_type( > name, info, ifcond, > 'arg', self._make_members(data, info)) > - self._def_entity(QAPISchemaEvent(name, info, expr.doc, ifcond, > + self._def_definition(QAPISchemaEvent(name, info, expr.doc, ifcond, > features, data, boxed)) > > def _def_exprs(self, exprs: List[QAPIExpression]) -> None: > I'll try the refactor out in a patch at the end of my series and see how feasible it is. (I haven't reviewed it deeply yet, so if there's an obvious problem I'll find it when I go to implement this. conceptually it seems fine.) > --000000000000341590060aac0238 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, Nov 21, 2023, 8:33 AM Markus Armbruster <armbru@redhat.com> wrote:
John Snow <jsnow@redhat.com> write= s:

> It simplifies typing to mandate that entities will always have a name;=
> to achieve this we can occasionally assign an internal name. This
> alleviates errors such as:
>
> qapi/schema.py:287: error: Argument 1 to "__init__" of
> "QAPISchemaEntity" has incompatible type "None"; e= xpected "str"
> [arg-type]
>
> Trying to fix it the other way by allowing entities to only have
> optional names opens up a nightmare portal of whackamole to try and > audit that every other pathway doesn't actually pass a None name w= hen we
> expect it to; this is the simpler direction of consitifying the typing= .

Arguably, that nightmare is compile-time proof of "we are not mistakin= g
QAPISchemaInclude for a named entity".

When I added the include directive, I shoehorned it into the existing
representation of the QAPI schema as "list of QAPISchemaEntity" b= y
making it a subtype of QAPISchemaEntity.=C2=A0 That was a somewhat lazy hac= k.

Note that qapi-code-gen.rst distinguishes between definitions and
directives.

The places where mypy gripes that .name isn't 'str' generally w= ant
something with a name (what qapi-code-gen.rst calls a definition).=C2=A0 If=
we somehow pass them an include directive, they'll use None for a name,=
which is no good.=C2=A0 mypy is pointing out this problem.

What to do about it?

1. Paper it over: give include directives some made-up name (this
patch).=C2=A0 Now the places use the made-up name instead of None, and mypy=
can't see the problem anymore.

2. Assert .name is not None until mypy is happy.=C2=A0 I guess that's w= hat
you called opening "a nightmare portal of whackamole".

Yep.
<= div dir=3D"auto">

3. Clean up the typing: have a type for top-level expression (has no
name), and a subtype for definition (has a name).=C2=A0 Rough sketch
appended.=C2=A0 Thoughts?
Oh, that'll work. I tried to keep to "min= imal SLOC" but where you want to see deeper fixes, I'm happy to de= viate. I'll give it a shot.


> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>=C2=A0 scripts/qapi/schema.py | 4 +++-
>=C2=A0 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
> index 153e703e0ef..0fb44452dd5 100644
> --- a/scripts/qapi/schema.py
> +++ b/scripts/qapi/schema.py
> @@ -220,7 +220,9 @@ def visit(self, visitor):
>=C2=A0
>=C2=A0 class QAPISchemaInclude(QAPISchemaEntity):
>=C2=A0 =C2=A0 =C2=A0 def __init__(self, sub_module, info):
> -=C2=A0 =C2=A0 =C2=A0 =C2=A0 super().__init__(None, info, None)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Includes are internal entity objects; a= nd may occur multiple times
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 name =3D f"q_include_{info.fname}:{i= nfo.line}"
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 super().__init__(name, info, None)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._sub_module =3D sub_module
>=C2=A0
>=C2=A0 =C2=A0 =C2=A0 def visit(self, visitor):

There are two instances of .name is None:

=C2=A0 =C2=A0 def __repr__(self) -> str:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if self.name is None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return "<%s at 0x%x>&q= uot; % (type(self).__name__, id(self))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return "<%s:%s at 0x%x>" % (typ= e(self).__name__, self.name,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 id(self))

and

=C2=A0 =C2=A0 def _def_entity(self, ent: QAPISchemaEntity) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Only the predefined types are allowed to not = have info
=C2=A0 =C2=A0 =C2=A0 =C2=A0 assert ent.info or self._predefining
=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._entity_list.append(ent)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if ent.name is None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return
=C2=A0 =C2=A0 =C2=A0 =C2=A0 [...]

Don't they need to be updated?

Oh, yes. I remove some assertions later i= n the series but I very likely missed these if cases.




diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 24ad166d52..eaff1df534 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -70,6 +70,45 @@ def is_present(self) -> bool:


=C2=A0class QAPISchemaEntity:
+=C2=A0 =C2=A0 def __init__(self, info: Optional[QAPISourceInfo]):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # For explicitly defined entities, info points= to the (explicit)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # definition.=C2=A0 For builtins (and their ar= rays), info is None.
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # For implicitly defined entities, info points= to a place that
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # triggered the implicit definition (there may= be more than one
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # such place).
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.info =3D info
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._module: Optional[QAPISchemaModule] =3D N= one
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._checked =3D False
+
+=C2=A0 =C2=A0 def __repr__(self) -> str:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 return "<%s at 0x%x>" % (type(= self).__name__, id(self))
+
+=C2=A0 =C2=A0 def check(self, schema: QAPISchema) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._checked =3D True
+
+=C2=A0 =C2=A0 def connect_doc(self, doc: Optional[QAPIDoc] =3D None) ->= None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 pass
+
+=C2=A0 =C2=A0 def check_doc(self) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 pass
+
+=C2=A0 =C2=A0 def _set_module(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self, schema: QAPISchema, info: Optional[QAPIS= ourceInfo]
+=C2=A0 =C2=A0 ) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 assert self._checked
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 fname =3D info.fname if info else QAPISchemaMo= dule.BUILTIN_MODULE_NAME
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._module =3D schema.module_by_fname(fname)=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._module.add_entity(self)
+
+=C2=A0 =C2=A0 def set_module(self, schema: QAPISchema) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._set_module(schema, self.info)
+
+=C2=A0 =C2=A0 def visit(self, visitor: QAPISchemaVisitor) -> None:
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 # pylint: disable=3Dunused-argument
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 assert self._checked
+
+
+class QAPISchemaDefinition(QAPISchemaEntity):
=C2=A0 =C2=A0 =C2=A0meta: str

=C2=A0 =C2=A0 =C2=A0def __init__(
@@ -80,24 +119,16 @@ def __init__(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ifcond: Optional[QAPISchemaIfCond] =3D No= ne,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0features: Optional[List[QAPISchemaFeature= ]] =3D None,
=C2=A0 =C2=A0 =C2=A0):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 super().__init__(info)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for f in features or []:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0f.set_defined_in(name)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.name =3D name
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._module: Optional[QAPISchemaModule] =3D N= one
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # For explicitly defined entities, info points= to the (explicit)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # definition.=C2=A0 For builtins (and their ar= rays), info is None.
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # For implicitly defined entities, info points= to a place that
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # triggered the implicit definition (there may= be more than one
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # such place).
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.info =3D info
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.doc =3D doc
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._ifcond =3D ifcond or QAPISchemaIfCo= nd()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.features =3D features or []
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._checked =3D False
-
+=C2=A0 =C2=A0 =C2=A0 =C2=A0
=C2=A0 =C2=A0 =C2=A0def __repr__(self) -> str:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 if self.name is None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return "<%s at 0x%x>&= quot; % (type(self).__name__, id(self))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return "<%s:%s at 0x%x>" = % (type(self).__name__, self.name,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0id(self))

@@ -122,17 +153,6 @@ def check_doc(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if self.doc:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.doc.check()

-=C2=A0 =C2=A0 def _set_module(
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self, schema: QAPISchema, info: Optional[QAPIS= ourceInfo]
-=C2=A0 =C2=A0 ) -> None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 assert self._checked
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 fname =3D info.fname if info else QAPISchemaMo= dule.BUILTIN_MODULE_NAME
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._module =3D schema.module_by_fname(fname)=
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._module.add_entity(self)
-
-=C2=A0 =C2=A0 def set_module(self, schema: QAPISchema) -> None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._set_module(schema, self.info)
-
=C2=A0 =C2=A0 =C2=A0@property
=C2=A0 =C2=A0 =C2=A0def ifcond(self) -> QAPISchemaIfCond:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assert self._checked
@@ -141,10 +161,6 @@ def ifcond(self) -> QAPISchemaIfCond:
=C2=A0 =C2=A0 =C2=A0def is_implicit(self) -> bool:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return not self.info

-=C2=A0 =C2=A0 def visit(self, visitor: QAPISchemaVisitor) -> None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # pylint: disable=3Dunused-argument
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 assert self._checked
-
=C2=A0 =C2=A0 =C2=A0def describe(self) -> str:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return "%s '%s'" % (sel= f.meta, self.name)

@@ -301,9 +317,7 @@ def visit(self, visitor: QAPISchemaVisitor) -> None:=

=C2=A0class QAPISchemaInclude(QAPISchemaEntity):
=C2=A0 =C2=A0 =C2=A0def __init__(self, sub_module: QAPISchemaModule, info: = QAPISourceInfo):
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 # Includes are internal entity objects; and ma= y occur multiple times
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 name =3D f"q_include_{info.fname}:{info.l= ine}"
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 super().__init__(name, info, None)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 super().__init__(info)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._sub_module =3D sub_module

=C2=A0 =C2=A0 =C2=A0def visit(self, visitor: QAPISchemaVisitor) -> None:=
@@ -311,7 +325,7 @@ def visit(self, visitor: QAPISchemaVisitor) -> None:=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0visitor.visit_include(self._sub_m= odule.name, self.info)


-class QAPISchemaType(QAPISchemaEntity):
+class QAPISchemaType(QAPISchemaDefinition):
=C2=A0 =C2=A0 =C2=A0# Return the C type for common use.
=C2=A0 =C2=A0 =C2=A0# For the types we commonly box, this is a pointer type= .
=C2=A0 =C2=A0 =C2=A0def c_type(self) -> str:
@@ -977,7 +991,7 @@ def __init__(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0super().__init__(name, info, typ, False, = ifcond)


-class QAPISchemaCommand(QAPISchemaEntity):
+class QAPISchemaCommand(QAPISchemaDefinition):
=C2=A0 =C2=A0 =C2=A0meta =3D 'command'

=C2=A0 =C2=A0 =C2=A0def __init__(
@@ -1059,7 +1073,7 @@ def visit(self, visitor: QAPISchemaVisitor) -> Non= e:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.coroutine)


-class QAPISchemaEvent(QAPISchemaEntity):
+class QAPISchemaEvent(QAPISchemaDefinition):
=C2=A0 =C2=A0 =C2=A0meta =3D 'event'

=C2=A0 =C2=A0 =C2=A0def __init__(
@@ -1133,7 +1147,7 @@ def __init__(self, fname: str):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0exprs =3D check_exprs(parser.exprs)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.docs =3D parser.docs
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._entity_list: List[QAPISchemaEntity]= =3D []
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._entity_dict: Dict[str, QAPISchemaEntity]= =3D {}
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._entity_dict: Dict[str, QAPISchemaDefinit= ion] =3D {}
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._module_dict: Dict[str, QAPISchemaMo= dule] =3D OrderedDict()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._schema_dir =3D os.path.dirname(fnam= e)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._make_module(QAPISchemaModule.BUILTI= N_MODULE_NAME)
@@ -1145,9 +1159,12 @@ def __init__(self, fname: str):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.check()

=C2=A0 =C2=A0 =C2=A0def _def_entity(self, ent: QAPISchemaEntity) -> None= :
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._entity_list.append(ent)
+
+=C2=A0 =C2=A0 def _def_definition(self, ent: QAPISchemaDefinition) -> N= one:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# Only the predefined types are allowed t= o not have info
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assert ent.info or self._predefining=
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._entity_list.append(ent)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(ent)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if ent.name is None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# TODO reject names that differ only in &= #39;_' vs. '.'=C2=A0 vs. '-',
@@ -1163,7 +1180,7 @@ def _def_entity(self, ent: QAPISchemaEntity) -> No= ne:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ent.info= , "%s is already defined" % other_ent.describe())
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._entity_dict[ent.name] =3D ent<= br>
-=C2=A0 =C2=A0 def get_entity(self, name: str) -> Optional[QAPISchemaEnt= ity]:
+=C2=A0 =C2=A0 def get_definition(self, name: str) -> Optional[QAPISchem= aDefinition]:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return self._entity_dict.get(name)

=C2=A0 =C2=A0 =C2=A0def get_typed_entity(
@@ -1171,7 +1188,7 @@ def get_typed_entity(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name: str,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0typ: Type[_EntityType]
=C2=A0 =C2=A0 =C2=A0) -> Optional[_EntityType]:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 ent =3D self.get_entity(name)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 ent =3D self.get_definition(name)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if ent is not None and not isinstance(ent= , typ):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0etype =3D type(ent).__name_= _
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ttype =3D typ.__name__
@@ -1225,7 +1242,7 @@ def _def_include(self, expr: QAPIExpression) -> No= ne:
=C2=A0 =C2=A0 =C2=A0def _def_builtin_type(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self, name: str, json_type: str, c_type: = str
=C2=A0 =C2=A0 =C2=A0) -> None:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(QAPISchemaBuiltinType(name, j= son_type, c_type))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(QAPISchemaBuiltinType(nam= e, json_type, c_type))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# Instantiating only the arrays that are = actually used would
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# be nice, but we can't as long as th= eir generated code
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# (qapi-builtin-types.[ch]) may be shared= by some other
@@ -1251,14 +1268,14 @@ def _def_predefineds(self) -> None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._def_builtin_type(*t)<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self.the_empty_object_type =3D QAPISchema= ObjectType(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'q_empty', None, No= ne, None, None, None, [], None)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(self.the_empty_object_type) +=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(self.the_empty_object_typ= e)

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0qtypes =3D ['none', 'qnull= 9;, 'qnum', 'qstring', 'qdict', 'qlist', =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'q= bool']
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0qtype_values =3D self._make_enum_members(=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0[{'name': n} for n = in qtypes], None)

-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(QAPISchemaEnumType('QType= ', None, None, None, None,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(QAPISchemaEnumType('Q= Type', None, None, None, None,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0qtype_values, 'QTYPE'))

=C2=A0 =C2=A0 =C2=A0def _make_features(
@@ -1294,8 +1311,8 @@ def _make_array_type(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self, element_type: str, info: Optional[Q= APISourceInfo]
=C2=A0 =C2=A0 =C2=A0) -> str:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name =3D element_type + 'List'=C2= =A0 =C2=A0 # reserved by check_defn_name_str()
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 if not self.get_entity(name):
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(QAPISchemaArray= Type(name, info, element_type))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 if not self.get_definition(name):
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(QAPISchemaA= rrayType(name, info, element_type))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return name

=C2=A0 =C2=A0 =C2=A0def _make_implicit_object_type(
@@ -1317,7 +1334,7 @@ def _make_implicit_object_type(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0# later.
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pass
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0else:
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(QAPISchemaObjec= tType(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(QAPISchemaO= bjectType(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name, info, N= one, ifcond, None, None, members, None))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return name

@@ -1328,7 +1345,7 @@ def _def_enum_type(self, expr: QAPIExpression) -> = None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ifcond =3D QAPISchemaIfCond(expr.get('= ;if'))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0info =3D expr.info
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0features =3D self._make_features(expr.get= ('features'), info)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(QAPISchemaEnumType(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(QAPISchemaEnumType(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name, info, expr.doc, ifcon= d, features,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._make_enum_members(dat= a, info), prefix))

@@ -1367,7 +1384,7 @@ def _def_struct_type(self, expr: QAPIExpression) ->= ; None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0info =3D expr.info
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0ifcond =3D QAPISchemaIfCond(expr.get('= ;if'))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0features =3D self._make_features(expr.get= ('features'), info)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(QAPISchemaObjectType(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(QAPISchemaObjectType(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name, info, expr.doc, ifcon= d, features, base,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0self._make_members(data, in= fo),
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0None))
@@ -1403,7 +1420,7 @@ def _def_union_type(self, expr: QAPIExpression) ->= None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 info)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for (key, value) in data.it= ems()]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0members: List[QAPISchemaObjectTypeMember]= =3D []
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0QAPISchemaObjectType(name, = info, expr.doc, ifcond, features,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 base, members,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 QAPISchemaVariants(
@@ -1422,7 +1439,7 @@ def _def_alternate_type(self, expr: QAPIExpression) -= > None:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 info)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for (key, value) in data.it= ems()]
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0tag_member =3D QAPISchemaObjectTypeMember= ('type', info, 'QType', False)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0QAPISchemaAlternateType( =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name, info, e= xpr.doc, ifcond, features,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0QAPISchemaVar= iants(None, info, tag_member, variants)))
@@ -1447,7 +1464,7 @@ def _def_command(self, expr: QAPIExpression) -> No= ne:
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if isinstance(rets, list):
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0assert len(rets) =3D=3D 1 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0rets =3D self._make_array_t= ype(rets[0], info)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(QAPISchemaCommand(name, info,= expr.doc, ifcond,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(QAPISchemaCommand(name, i= nfo, expr.doc, ifcond,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 features, data, rets,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 gen, success_response,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 boxed, allow_oob, allow_preconfig,
@@ -1464,7 +1481,7 @@ def _def_event(self, expr: QAPIExpression) -> None= :
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0data =3D self._make_implici= t_object_type(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0name, info, i= fcond,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0'arg'= , self._make_members(data, info))
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_entity(QAPISchemaEvent(name, info, e= xpr.doc, ifcond,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 self._def_definition(QAPISchemaEvent(name, inf= o, expr.doc, ifcond,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 f= eatures, data, boxed))

=C2=A0 =C2=A0 =C2=A0def _def_exprs(self, exprs: List[QAPIExpression]) ->= None:

I'll try the refactor out in a patch at the end of my series and = see how feasible it is.

= (I haven't reviewed it deeply yet, so if there's an obvious problem= I'll find it when I go to implement this. conceptually it seems fine.)=
--000000000000341590060aac0238--