From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613442756802790.601793077688; Mon, 15 Feb 2021 18:32:36 -0800 (PST) Received: from localhost ([::1]:55564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqAF-0003y4-MQ for importer@patchew.org; Mon, 15 Feb 2021 21:32:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwX-0001Tr-28 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56231) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwO-00031w-55 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:24 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-576-L4KPa5cPOZmFYfewvBt-Sg-1; Mon, 15 Feb 2021 21:18:13 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2D59B18A08BD; Tue, 16 Feb 2021 02:18:12 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4899810023AF; Tue, 16 Feb 2021 02:18:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441895; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DQB24nfAxz/Y6GQBu3FfiR/mrF6wbsVJL1x/oHAyuTs=; b=bMaLiJKNjYBvQfkE+4fo2qWCmb+gFWD4AHOG5p5ukBxR9AF4bTF+oKXt6zeGSKOdR37hJp 9cWYOHOnZT/7JIVgbGzPIhhIfNUqZ7EqRXGK6TOyWjxg+JEKTgVoIa31dPXygUa5Pm4ftz QCv0xOWPbtkpGSx23qESugMvVKokLXE= X-MC-Unique: L4KPa5cPOZmFYfewvBt-Sg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 01/19] qapi: Replace List[str] with Sequence[str] for ifcond Date: Mon, 15 Feb 2021 21:17:51 -0500 Message-Id: <20210216021809.134886-2-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It does happen to be a list (as of now), but we can describe it in more general terms with no loss in accuracy to allow tuples and other constructs. In the future, we can write "ifcond: Sequence[str] =3D ()" as a default parameter, which we could not do with a Mutable type like a List. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 3 ++- scripts/qapi/events.py | 4 ++-- scripts/qapi/gen.py | 12 ++++++------ scripts/qapi/types.py | 12 ++++++------ scripts/qapi/visit.py | 10 +++++----- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 54af519f44d..0a75a9371ba 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -17,6 +17,7 @@ Dict, List, Optional, + Sequence, Set, ) =20 @@ -297,7 +298,7 @@ def visit_end(self) -> None: def visit_command(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: Sequence[str], features: List[QAPISchemaFeature], arg_type: Optional[QAPISchemaObjectType], ret_type: Optional[QAPISchemaType], diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 8c57deb2b89..90d2f6156d8 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,7 +12,7 @@ See the COPYING file in the top-level directory. """ =20 -from typing import List, Optional +from typing import List, Optional, Sequence =20 from .common import c_enum_const, c_name, mcgen from .gen import QAPISchemaModularCVisitor, build_params, ifcontext @@ -214,7 +214,7 @@ def visit_end(self) -> None: def visit_event(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: Sequence[str], features: List[QAPISchemaFeature], arg_type: Optional[QAPISchemaObjectType], boxed: bool) -> None: diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 63549cc8d47..1fa503bdbdf 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -17,8 +17,8 @@ from typing import ( Dict, Iterator, - List, Optional, + Sequence, Tuple, ) =20 @@ -85,7 +85,7 @@ def write(self, output_dir: str) -> None: fp.write(text) =20 =20 -def _wrap_ifcond(ifcond: List[str], before: str, after: str) -> str: +def _wrap_ifcond(ifcond: Sequence[str], before: str, after: str) -> str: if before =3D=3D after: return after # suppress empty #if ... #endif =20 @@ -127,9 +127,9 @@ def build_params(arg_type: Optional[QAPISchemaObjectTyp= e], class QAPIGenCCode(QAPIGen): def __init__(self, fname: str): super().__init__(fname) - self._start_if: Optional[Tuple[List[str], str, str]] =3D None + self._start_if: Optional[Tuple[Sequence[str], str, str]] =3D None =20 - def start_if(self, ifcond: List[str]) -> None: + def start_if(self, ifcond: Sequence[str]) -> None: assert self._start_if is None self._start_if =3D (ifcond, self._body, self._preamble) =20 @@ -187,11 +187,11 @@ def _bottom(self) -> str: =20 =20 @contextmanager -def ifcontext(ifcond: List[str], *args: QAPIGenCCode) -> Iterator[None]: +def ifcontext(ifcond: Sequence[str], *args: QAPIGenCCode) -> Iterator[None= ]: """ A with-statement context manager that wraps with `start_if()` / `end_i= f()`. =20 - :param ifcond: A list of conditionals, passed to `start_if()`. + :param ifcond: A sequence of conditionals, passed to `start_if()`. :param args: any number of `QAPIGenCCode`. =20 Example:: diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 2bdd6268476..20d572a23aa 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -13,7 +13,7 @@ # See the COPYING file in the top-level directory. """ =20 -from typing import List, Optional +from typing import List, Optional, Sequence =20 from .common import ( c_enum_const, @@ -139,7 +139,7 @@ def gen_struct_members(members: List[QAPISchemaObjectTy= peMember]) -> str: return ret =20 =20 -def gen_object(name: str, ifcond: List[str], +def gen_object(name: str, ifcond: Sequence[str], base: Optional[QAPISchemaObjectType], members: List[QAPISchemaObjectTypeMember], variants: Optional[QAPISchemaVariants]) -> str: @@ -307,7 +307,7 @@ def _gen_type_cleanup(self, name: str) -> None: def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: Sequence[str], features: List[QAPISchemaFeature], members: List[QAPISchemaEnumMember], prefix: Optional[str]) -> None: @@ -318,7 +318,7 @@ def visit_enum_type(self, def visit_array_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: Sequence[str], element_type: QAPISchemaType) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.preamble_add(gen_fwd_object_or_array(name)) @@ -328,7 +328,7 @@ def visit_array_type(self, def visit_object_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: Sequence[str], features: List[QAPISchemaFeature], base: Optional[QAPISchemaObjectType], members: List[QAPISchemaObjectTypeMember], @@ -351,7 +351,7 @@ def visit_object_type(self, def visit_alternate_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: Sequence[str], features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: with ifcontext(ifcond, self._genh): diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 22e62df9017..9aa0b1e11e9 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -13,7 +13,7 @@ See the COPYING file in the top-level directory. """ =20 -from typing import List, Optional +from typing import List, Optional, Sequence =20 from .common import ( c_enum_const, @@ -337,7 +337,7 @@ def _begin_user_module(self, name: str) -> None: def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: Sequence[str], features: List[QAPISchemaFeature], members: List[QAPISchemaEnumMember], prefix: Optional[str]) -> None: @@ -348,7 +348,7 @@ def visit_enum_type(self, def visit_array_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: Sequence[str], element_type: QAPISchemaType) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name)) @@ -357,7 +357,7 @@ def visit_array_type(self, def visit_object_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: Sequence[str], features: List[QAPISchemaFeature], base: Optional[QAPISchemaObjectType], members: List[QAPISchemaObjectTypeMember], @@ -379,7 +379,7 @@ def visit_object_type(self, def visit_alternate_type(self, name: str, info: Optional[QAPISourceInfo], - ifcond: List[str], + ifcond: Sequence[str], features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: with ifcontext(ifcond, self._genh, self._genc): --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613443149; cv=none; d=zohomail.com; s=zohoarc; b=lC8QOTU7o3LEhikbAbkCKACNkPiztrKRV9Znz5ZR0KMeiZ/rjcVNZF7eSwooN3/h6qy0jU3OM55togyPfkmGHF2LKu2sZbc7SLOgohyGNn9IlQzLoAZQ6q2yLjBu8ZlvmTYi/Dt8yWtGFopqlrH04Vd5B5P7ZVUxIEaNyuGZqdg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613443149; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XWr0AcRlsQez5Aq3NxYWxDa4M/wcTgndy6zggib5YUk=; b=clh+MeHU//NiQZV2AkaCoIdi/JlzbJfxjMnDvgF9U14To4W159EarCCKRNPcxzZ338PzSKlYcWVf9Irz+OpqLdXd8/x/YNMnObZkBRfHfsvuW1NsuvrsXoesDfwdEmdd+FHFvLFNS5Ksia/OYmdysrHXRRQhzgD0+43zcHGunhU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443148725785.1890613985778; Mon, 15 Feb 2021 18:39:08 -0800 (PST) Received: from localhost ([::1]:51324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqGZ-0005aH-OP for importer@patchew.org; Mon, 15 Feb 2021 21:39:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwQ-0001St-I7 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48471) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwO-00032J-Lh for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:18 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-498-ga9ECN2PM4OZMpBSL8ePUg-1; Mon, 15 Feb 2021 21:18:14 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2BF34107ACC7; Tue, 16 Feb 2021 02:18:13 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5941710023B0; Tue, 16 Feb 2021 02:18:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441895; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XWr0AcRlsQez5Aq3NxYWxDa4M/wcTgndy6zggib5YUk=; b=adki08TZ9WfkNAiLZkuVOdOq8bgviYskj63FxR+KjcxdnlNiCk7Mk42hESj5264iJXJNLq zF7lh5Fsd+nL/OhoqeN1Jsnl9rurjrSnXtn/opfMzss2VxjoFJxDf2hg/No+dNGrhtnr7D bR0PZg8dZaHCDEM6Fbf0Fuu498tbxLQ= X-MC-Unique: ga9ECN2PM4OZMpBSL8ePUg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 02/19] qapi/introspect.py: assert schema is not None Date: Mon, 15 Feb 2021 21:17:52 -0500 Message-Id: <20210216021809.134886-3-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The introspect visitor is stateful, but expects that it will have a schema to refer to. Add assertions that state this. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index fafec94e022..43ab4be1f77 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -147,6 +147,8 @@ def _name(self, name): return self._name_map[name] =20 def _use_type(self, typ): + assert self._schema is not None + # Map the various integer types to plain int if typ.json_type() =3D=3D 'int': typ =3D self._schema.lookup_type('int') @@ -225,6 +227,8 @@ def visit_alternate_type(self, name, info, ifcond, feat= ures, variants): def visit_command(self, name, info, ifcond, features, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, coroutine): + assert self._schema is not None + arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type obj =3D {'arg-type': self._use_type(arg_type), @@ -234,6 +238,7 @@ def visit_command(self, name, info, ifcond, features, self._gen_tree(name, 'command', obj, ifcond, features) =20 def visit_event(self, name, info, ifcond, features, arg_type, boxed): + assert self._schema is not None arg_type =3D arg_type or self._schema.the_empty_object_type self._gen_tree(name, 'event', {'arg-type': self._use_type(arg_type= )}, ifcond, features) --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613443294; cv=none; d=zohomail.com; s=zohoarc; b=LdQ7dh/o9bND/MQoM2PC8QdOd00BrRBHh8b0F3P5BXgXjSw+VUh7tm3z9xQpvODHPEaiyy6bHGpNhIAqdEIVbyYgJlG2XdRejmm5aYP8BNICMNNL/u066qXrOv/WGty4n+rVzK+0Xdms06QPSj9gaTXrihhdpG0A/stCLlnxiak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613443294; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N9yGGI4O27oKx7dXUhjSvY4iw/NC5t2MvhJDwQcUe9I=; b=b364L0WKpxtq/JAjxu8e2E+68Y7v04IiHZvEx8U5+WephSMxc4/Qgmr4R1fZpr8c13zlOFONIMwxVDwGD1wJpojRlKPwipQeR9wcQwDSDxVU+wVAB9Pu1YQqDn+QekVAfyTz/trJwQZ9l+EWPrrnxMVa1VPyl7WqYEaXUlxfMUE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443293650413.98941369944487; Mon, 15 Feb 2021 18:41:33 -0800 (PST) Received: from localhost ([::1]:59384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqIu-0000W0-Lk for importer@patchew.org; Mon, 15 Feb 2021 21:41:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwT-0001T3-Vc for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:24 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwP-00032i-OU for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:21 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-301-4rLalJGKMQqPBApVRh90uw-1; Mon, 15 Feb 2021 21:18:15 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4B2341E561; Tue, 16 Feb 2021 02:18:14 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 560C710023AF; Tue, 16 Feb 2021 02:18:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441897; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=N9yGGI4O27oKx7dXUhjSvY4iw/NC5t2MvhJDwQcUe9I=; b=SLYeE0F11Fpf0eJWWTOarhffUaF72XyoE89IZFdh5GtOdaDVIMrkzhzRqxUe+eowVsxchU CO+dIp8C716Tyyu1AJfVnCcTtdJMgh7uGZ5ikK8Y6FznL7dt0vUVK9jrMDX6KgRAhK8vxQ VZo3QFQlmfh8eS48ulac7v/iKUTJ9os= X-MC-Unique: 4rLalJGKMQqPBApVRh90uw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 03/19] qapi/introspect.py: use _make_tree for features nodes Date: Mon, 15 Feb 2021 21:17:53 -0500 Message-Id: <20210216021809.134886-4-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" At present, we open-code this in _make_tree itself; but if the structure of the tree changes, this is brittle. Use an explicit recursive call to _make_tree when appropriate to help keep the interior node typing consistent. A consequence of doing this is that the 'ifcond' key of the features dict will be omitted when ifcond is false-ish, just like it is omitted in top-level calls to _make_tree. This also increases consistency in our handling of this property. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 43ab4be1f77..3295a15c98e 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -30,7 +30,9 @@ def _make_tree(obj, ifcond, features, extra=3DNone): if ifcond: extra['if'] =3D ifcond if features: - obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in features] + obj['features'] =3D [ + _make_tree(f.name, f.ifcond, None) for f in features + ] if extra: return (obj, extra) return obj --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613442690; cv=none; d=zohomail.com; s=zohoarc; b=JUOnxvs5rV4JObxuaIgTcnZrguxKlwISK9Z6kn/K8WtCEjnkfQlxYhX84cgm96kDjdu1ZB7t64NIZmZKfXjntTR5K5a3QqHoH8KRUa2hph8HkBvstnlRT76izVukvefkOV4lAev3cYjvYKujk2b/KdePsx16i4RxuH/7i9DAzYA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613442690; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=acrxd18H7FqKyFi0v69UbUmTdPkZgFPrjuidbeAGGhQ=; b=lYz7eZzg0NMNq+w+DEjnG//0TQ4mItLJgSQVtvHVfi478h8uO8LsDTODpHYlqKFiF+e7bbsHa8ZssjokdyC7yas2mUMSfp4PWx4OP25jTc4WroCx4mX25S5Kbp99h/T9gi7DdubnRGCVXSF0uDlsF0ET++YbTANdoJxzCy3KtQc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161344269002019.761414584141676; Mon, 15 Feb 2021 18:31:30 -0800 (PST) Received: from localhost ([::1]:51392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBq9A-0002D0-Mv for importer@patchew.org; Mon, 15 Feb 2021 21:31:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwe-0001n2-Fw for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:38 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21602) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwc-000386-PS for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:32 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-54-7EOM3uEIOW-A1v3KAQVKlQ-1; Mon, 15 Feb 2021 21:18:16 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6DEB3107ACE8; Tue, 16 Feb 2021 02:18:15 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7827B10023AF; Tue, 16 Feb 2021 02:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441910; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=acrxd18H7FqKyFi0v69UbUmTdPkZgFPrjuidbeAGGhQ=; b=AURV11ctlcvP3vG2CPglMoV4u55FEQvhGoP4GLdz88jKBck4s/ZtD+qHbtjKVH2Za2NSAs Sei9ZaSP7YbuV5RsruhTrfDmhymjjvVzdjyCSea652d2pKCRJviFKrFN2n+feBDeUQCPpR uAF/ejRRcc0bW4Jad/S12m1o/I1mdv4= X-MC-Unique: 7EOM3uEIOW-A1v3KAQVKlQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 04/19] qapi/introspect.py: add _gen_features helper Date: Mon, 15 Feb 2021 21:17:54 -0500 Message-Id: <20210216021809.134886-5-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" _make_tree might receive a dict (a SchemaInfo object) or some other type (usually, a string) for its obj parameter. Adding features information should arguably be performed by the caller at such a time when we know the type of the object and don't have to re-interrogate it. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 3295a15c98e..4749f65ea3c 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -24,15 +24,11 @@ ) =20 =20 -def _make_tree(obj, ifcond, features, extra=3DNone): +def _make_tree(obj, ifcond, extra=3DNone): if extra is None: extra =3D {} if ifcond: extra['if'] =3D ifcond - if features: - obj['features'] =3D [ - _make_tree(f.name, f.ifcond, None) for f in features - ] if extra: return (obj, extra) return obj @@ -169,6 +165,10 @@ def _use_type(self, typ): return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) =20 + @staticmethod + def _gen_features(features): + return [_make_tree(f.name, f.ifcond) for f in features] + def _gen_tree(self, name, mtype, obj, ifcond, features): extra =3D None if mtype not in ('command', 'event', 'builtin', 'array'): @@ -179,13 +179,17 @@ def _gen_tree(self, name, mtype, obj, ifcond, feature= s): name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype - self._trees.append(_make_tree(obj, ifcond, features, extra)) + if features: + obj['features'] =3D self._gen_features(features) + self._trees.append(_make_tree(obj, ifcond, extra)) =20 def _gen_member(self, member): obj =3D {'name': member.name, 'type': self._use_type(member.type)} if member.optional: obj['default'] =3D None - return _make_tree(obj, member.ifcond, member.features) + if member.features: + obj['features'] =3D self._gen_features(member.features) + return _make_tree(obj, member.ifcond) =20 def _gen_variants(self, tag_name, variants): return {'tag': tag_name, @@ -193,7 +197,7 @@ def _gen_variants(self, tag_name, variants): =20 def _gen_variant(self, variant): obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} - return _make_tree(obj, variant.ifcond, None) + return _make_tree(obj, variant.ifcond) =20 def visit_builtin_type(self, name, info, json_type): self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613442881228948.7368365905675; Mon, 15 Feb 2021 18:34:41 -0800 (PST) Received: from localhost ([::1]:35784 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqCG-0007UP-2E for importer@patchew.org; Mon, 15 Feb 2021 21:34:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwX-0001UG-8B for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60805) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwT-00033o-O2 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:24 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-QWpG8O8XNHawLQI-PeId9Q-1; Mon, 15 Feb 2021 21:18:17 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1BAD1005501; Tue, 16 Feb 2021 02:18:16 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99B3F10023B0; Tue, 16 Feb 2021 02:18:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441899; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QLWmo10aY/7+eJcykLq1vYXxnbs+2dOAa1qD1gwOsW4=; b=ddDyLUoCfG/o3ODQ6PAc5LZkFbqej6+zqn/QkjIqUzvc/CW64ecogGKF8dY7sI5VxF2WBO Pz6bE3MdfCPoB3fIohQn7XvSxe2dklFhLNEs1eMe7qv2h3jItta809bNqwL/mZQhEiqYav 13fB2m8NFDKJQNZszoyrdQut3s2kI+0= X-MC-Unique: QWpG8O8XNHawLQI-PeId9Q-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 05/19] qapi/introspect.py: guard against ifcond/comment misuse Date: Mon, 15 Feb 2021 21:17:55 -0500 Message-Id: <20210216021809.134886-6-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" _tree_to_qlit is called recursively on dict values (isolated from their keys); at such a point in generating output it is too late to apply an ifcond. Similarly, comments do not necessarily have a "tidy" place they can be printed in such a circumstance. Forbid this usage by renaming "suppress_first_indent" to "dict_value" to emphasize that indents are suppressed only for the benefit of dict values; then add an assertion assuring we do not pass ifcond/comments in this case. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 4749f65ea3c..a7ccda5ab92 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -34,7 +34,7 @@ def _make_tree(obj, ifcond, extra=3DNone): return obj =20 =20 -def _tree_to_qlit(obj, level=3D0, suppress_first_indent=3DFalse): +def _tree_to_qlit(obj, level=3D0, dict_value=3DFalse): =20 def indent(level): return level * 4 * ' ' @@ -43,6 +43,12 @@ def indent(level): ifobj, extra =3D obj ifcond =3D extra.get('if') comment =3D extra.get('comment') + + # NB: _tree_to_qlit is called recursively on the values of a key:v= alue + # pair; those values can't be decorated with comments or condition= als. + msg =3D "dict values cannot have attached comments or if-condition= als." + assert not dict_value, msg + ret =3D '' if comment: ret +=3D indent(level) + '/* %s */\n' % comment @@ -54,7 +60,7 @@ def indent(level): return ret =20 ret =3D '' - if not suppress_first_indent: + if not dict_value: ret +=3D indent(level) if obj is None: ret +=3D 'QLIT_QNULL' --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613442756347513.0556575446185; Mon, 15 Feb 2021 18:32:36 -0800 (PST) Received: from localhost ([::1]:55516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqAF-0003wr-90 for importer@patchew.org; Mon, 15 Feb 2021 21:32:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwX-0001U6-4c for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:25 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34331) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwT-00034B-O2 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:24 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-104-WALuE9dVP_q4fZvocSL4_w-1; Mon, 15 Feb 2021 21:18:18 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D7A688030C1; Tue, 16 Feb 2021 02:18:17 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id E726F10023AF; Tue, 16 Feb 2021 02:18:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441900; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hhSDtbsGfbobVTHftHTtFiV/76YmL0xiVKbNqWrc3lU=; b=VFrkHeY0D5O5dpg+pszIPClU4S5ZnJ0wbOGb4za5dE/9l6hNcKpMH8y5Hyr4DWujFoAOkv jYx3EVTXr8AEjEpVI6TZAd/9HaSueX4H9CsMFvAJYR/9NuizmuwjnfCZpS9KxQ5kX5pTIT uB4rfi+rLRO2kKa3WFyp5pm+FgvROaQ= X-MC-Unique: WALuE9dVP_q4fZvocSL4_w-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 06/19] qapi/introspect.py: Unify return type of _make_tree() Date: Mon, 15 Feb 2021 21:17:56 -0500 Message-Id: <20210216021809.134886-7-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Returning two different types conditionally can be complicated to type. Return one type for consistency. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index a7ccda5ab92..7730d8ed6b2 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -29,9 +29,7 @@ def _make_tree(obj, ifcond, extra=3DNone): extra =3D {} if ifcond: extra['if'] =3D ifcond - if extra: - return (obj, extra) - return obj + return (obj, extra) =20 =20 def _tree_to_qlit(obj, level=3D0, dict_value=3DFalse): --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613443070; cv=none; d=zohomail.com; s=zohoarc; b=CDoovkkktplwT6narR57019Ld2ABxbKBARbsG/0i2+y3A+P5ArAqZv78Fxyl6pzqsrVufv/B1DX44dV5tGM8/Ij4xYDljsHbuufK5xodNs4Qdq+mGWxjcDTht0/U6Lw3upBXMxlTGXiWujzhdiF8K6qWLi7JX2CTxG6+yqPIL54= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613443070; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vGs6OE2ncObnm5kTca0WqPCj9ZU90/mKzbEwVnH6IJw=; b=RxSWIcQjUz0JLBltWQ3oSY0Kq8fFFKqgBaB3ds9DD0JRDxZ7q0gINOo0KhVMdQXJK7tYYimsF13cAAtWOMG04chxs3p54G/3nt8DLPWrH8KTxQ8RiK8uqoNidiU5hkJ1GOU03BZdqFS6vDvhshnh1x5JzH0KHSGkYV6J6O09Kjk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161344307016540.07412428150849; Mon, 15 Feb 2021 18:37:50 -0800 (PST) Received: from localhost ([::1]:44666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqFJ-0002tr-4S for importer@patchew.org; Mon, 15 Feb 2021 21:37:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpww-0001sN-A9 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35204) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwk-00039d-JS for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:49 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-539-S1sPsFJUNSmdoZGAWOdmxQ-1; Mon, 15 Feb 2021 21:18:19 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D435C18A08BF; Tue, 16 Feb 2021 02:18:18 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E80310023AF; Tue, 16 Feb 2021 02:18:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441913; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vGs6OE2ncObnm5kTca0WqPCj9ZU90/mKzbEwVnH6IJw=; b=XfV25SYxgHKHTqvaVLcS65ozqrDhfNNnsl5Gan0Yf6rKVoCAAhxIJj05XugAoIsCK1IcpF OS34hU2HqRAfXchRx1S+D5/zVDTa/iyMc9oTjvl2s7bqwrUfdaQeBGpSjxcTUsl1IwROW3 he4tmSqFCnd0yHIzJ0nE1Hzr1gdToh0= X-MC-Unique: S1sPsFJUNSmdoZGAWOdmxQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 07/19] qapi/introspect.py: replace 'extra' dict with 'comment' argument Date: Mon, 15 Feb 2021 21:17:57 -0500 Message-Id: <20210216021809.134886-8-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is only used to pass in a dictionary with a comment already set, so skip the runaround and just accept the (optional) comment. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 7730d8ed6b2..1655a21f85b 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,6 +10,8 @@ See the COPYING file in the top-level directory. """ =20 +from typing import Optional + from .common import ( c_name, gen_endif, @@ -24,11 +26,12 @@ ) =20 =20 -def _make_tree(obj, ifcond, extra=3DNone): - if extra is None: - extra =3D {} +def _make_tree(obj, ifcond, comment=3DNone): + extra =3D {} if ifcond: extra['if'] =3D ifcond + if comment: + extra['comment'] =3D comment return (obj, extra) =20 =20 @@ -174,18 +177,18 @@ def _gen_features(features): return [_make_tree(f.name, f.ifcond) for f in features] =20 def _gen_tree(self, name, mtype, obj, ifcond, features): - extra =3D None + comment: Optional[str] =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: # Output a comment to make it easy to map masked names # back to the source when reading the generated output. - extra =3D {'comment': '"%s" =3D %s' % (self._name(name), n= ame)} + comment =3D f'"{self._name(name)}" =3D {name}' name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype if features: obj['features'] =3D self._gen_features(features) - self._trees.append(_make_tree(obj, ifcond, extra)) + self._trees.append(_make_tree(obj, ifcond, comment)) =20 def _gen_member(self, member): obj =3D {'name': member.name, 'type': self._use_type(member.type)} --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613443069; cv=none; d=zohomail.com; s=zohoarc; b=WifwxBJTFAAYuw/X+DvMnckSR2ijl64X4LChKd9021VZSa9gX+CT7Yhn9OnMFwE3B0+BdDl2zBlM6b8F7X1fwe5I2cEyIqlWKyeumz0zheBrEIANl/wRY4KBtgNCf+Xmxh1bdhnTUOXVhTaE/AKIOaRfAgseWG02zwXGYrUzWbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613443069; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JxItRlDjeE03aSUCdeoWAjl1xlJSCd+Z/KaGv7sl7LY=; b=exisT1SxiQ7WH8HZXYxc5/Bpfgroq3hZnEsZ6jw6a8jI3k1S4v9ceJ/vaRQ6FaThE8/27G1mMCRSGO3KlMkI2QMjZxSSbQqgb1CApSxo3XvxHGOkJl2FANd38hGFkZktL+iBivozrA5x4+0N8MtLJmgX76+TLY0VbXQ3qo0RLfY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443069771411.6047982289508; Mon, 15 Feb 2021 18:37:49 -0800 (PST) Received: from localhost ([::1]:44604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqFI-0002sJ-Mr for importer@patchew.org; Mon, 15 Feb 2021 21:37:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwY-0001XV-F1 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:26 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33645) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwW-00034N-Iw for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:26 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-282-Px3hZKqKP2SUv0WKVOMwlQ-1; Mon, 15 Feb 2021 21:18:20 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D040A18A08C0; Tue, 16 Feb 2021 02:18:19 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0B5BD10023AF; Tue, 16 Feb 2021 02:18:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441902; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JxItRlDjeE03aSUCdeoWAjl1xlJSCd+Z/KaGv7sl7LY=; b=F8l22+SvxeKeiyaG6vZHVWs5EgOmIaThACPtRB1b4QpxKkDG+RZARO35pyQ1kgVKdVuFvV yFk9QiGmsI1RwPTxS2GC7FfilHc5OfZ9gvqkbc0nf0vmhRwNv+yS+l2Xt+E1zumMQaD0og EoJJwCdNPVz+B+vZZVYxX+nFuMru4UQ= X-MC-Unique: Px3hZKqKP2SUv0WKVOMwlQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 08/19] qapi/introspect.py: Always define all 'extra' dict keys Date: Mon, 15 Feb 2021 21:17:58 -0500 Message-Id: <20210216021809.134886-9-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This mimics how a typed object works, where 'if' and 'comment' are always set, regardless of if they have a value set or not. It is safe to do this because of the way that _tree_to_qlit processes these values (using dict.get with a default of None), resulting in no change of output from _tree_to_qlit. There are no other users of this data. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 1655a21f85b..45231d2abc3 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -27,11 +27,10 @@ =20 =20 def _make_tree(obj, ifcond, comment=3DNone): - extra =3D {} - if ifcond: - extra['if'] =3D ifcond - if comment: - extra['comment'] =3D comment + extra =3D { + 'if': ifcond, + 'comment': comment + } return (obj, extra) =20 =20 --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443194154776.6002710897668; Mon, 15 Feb 2021 18:39:54 -0800 (PST) Received: from localhost ([::1]:53338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqHJ-0006Pq-4Q for importer@patchew.org; Mon, 15 Feb 2021 21:39:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwa-0001d7-Iv for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:28 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwY-00036l-W2 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:28 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-125-43S76pUHPf2x1eAGlrUdgQ-1; Mon, 15 Feb 2021 21:18:24 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C33180196C; Tue, 16 Feb 2021 02:18:23 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0712110023AF; Tue, 16 Feb 2021 02:18:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441906; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=U8ItUfgk19UqYErZWTP4mxz5owKMRR5BUpTeXsR1rwk=; b=cxwV6qFNRfMYd94hwwCPn/L1WpTOT20hdz/VZafnSdG6jdJszs8unVj+jVD0k+4wl+LycR 9urbR0Be3nLET6iTWCSjnXVBYDF5ZJh6rSrFdXq1DOgCbrjIvl0nx3/xIjlbtXSBn/A/N4 qms1Atc1ebqYRYqjAHXWpgbIeJP40sU= X-MC-Unique: 43S76pUHPf2x1eAGlrUdgQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 09/19] qapi/introspect.py: Introduce preliminary tree typing Date: Mon, 15 Feb 2021 21:17:59 -0500 Message-Id: <20210216021809.134886-10-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The types will be used in forthcoming patches to add typing. These types describe the layout and structure of the objects passed to _tree_to_qlit, but lack the power to describe annotations until the next commit. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 45231d2abc3..3c37c138013 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,7 +10,13 @@ See the COPYING file in the top-level directory. """ =20 -from typing import Optional +from typing import ( + Any, + Dict, + List, + Optional, + Union, +) =20 from .common import ( c_name, @@ -26,6 +32,29 @@ ) =20 =20 +# This module constructs a tree data structure that is used to +# generate the introspection information for QEMU. It is shaped +# like a JSON value. +# +# A complexity over JSON is that our values may or may not be annotated. +# +# Un-annotated values may be: +# Scalar: str, bool, None. +# Non-scalar: List, Dict +# _value =3D Union[str, bool, None, Dict[str, JSONValue], List[JSONValue]] +# +# With optional annotations, the type of all values is: +# JSONValue =3D Union[_Value, Annotated[_Value]] +# +# Sadly, mypy does not support recursive types; so the _Stub alias is used= to +# mark the imprecision in the type model where we'd otherwise use JSONValu= e. +_Stub =3D Any +_Scalar =3D Union[str, bool, None] +_NonScalar =3D Union[Dict[str, _Stub], List[_Stub]] +_Value =3D Union[_Scalar, _NonScalar] +# JSONValue =3D TODO, in a forthcoming commit. + + def _make_tree(obj, ifcond, comment=3DNone): extra =3D { 'if': ifcond, --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443511841789.7598751443369; Mon, 15 Feb 2021 18:45:11 -0800 (PST) Received: from localhost ([::1]:42002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqMN-0004wQ-O5 for importer@patchew.org; Mon, 15 Feb 2021 21:45:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwz-0001wi-UT for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52308) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwk-0003A8-KE for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-159-U_Bs24DYNb2CkdC5n9vEig-1; Mon, 15 Feb 2021 21:18:25 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 93D6118A08BD; Tue, 16 Feb 2021 02:18:24 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id A90E910023AF; Tue, 16 Feb 2021 02:18:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441917; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jEfdHr2hSQ3ttgCVRtTxTbMXcAw0ZbXM4l5D1Tamb6Y=; b=ejgFk2L7IiGAKNKAwGySK5lxdz6ExsNrKVgOMhcn/yt+gKK8aRBVsIaXs9jZaSFu7/+bg8 GExh+ly6CMZgaClOL7t8P327Y62vRY40nupKlM2fe8zixRk9FrYjoUrDsLIoP19b6nrBod CE3bTQUBfOIqk30cdxtZb5790+86wmY= X-MC-Unique: U_Bs24DYNb2CkdC5n9vEig-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 10/19] qapi/introspect.py: create a typed 'Annotated' data strutcure Date: Mon, 15 Feb 2021 21:18:00 -0500 Message-Id: <20210216021809.134886-11-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Presently, we use a tuple to attach a dict containing annotations (comments and compile-time conditionals) to a tree node. This is undesirable because dicts are difficult to strongly type; promoting it to a real class allows us to name the values and types of the annotations we are expecting. In terms of typing, the Annotated type serves as a generic container where the annotated node's type is preserved, allowing for greater specificity than we'd be able to provide without a generic. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 78 ++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 33 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 3c37c138013..5224be1a333 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -13,8 +13,12 @@ from typing import ( Any, Dict, + Generic, + Iterable, List, Optional, + Tuple, + TypeVar, Union, ) =20 @@ -52,15 +56,25 @@ _Scalar =3D Union[str, bool, None] _NonScalar =3D Union[Dict[str, _Stub], List[_Stub]] _Value =3D Union[_Scalar, _NonScalar] -# JSONValue =3D TODO, in a forthcoming commit. +JSONValue =3D Union[_Value, 'Annotated[_Value]'] =20 =20 -def _make_tree(obj, ifcond, comment=3DNone): - extra =3D { - 'if': ifcond, - 'comment': comment - } - return (obj, extra) +_ValueT =3D TypeVar('_ValueT', bound=3D_Value) + + +class Annotated(Generic[_ValueT]): + """ + Annotated generally contains a SchemaInfo-like type (as a dict), + But it also used to wrap comments/ifconds around scalar leaf values, + for the benefit of features and enums. + """ + # TODO: Remove after Python 3.7 adds @dataclass: + # pylint: disable=3Dtoo-few-public-methods + def __init__(self, value: _ValueT, ifcond: Iterable[str], + comment: Optional[str] =3D None): + self.value =3D value + self.comment: Optional[str] =3D comment + self.ifcond: Tuple[str, ...] =3D tuple(ifcond) =20 =20 def _tree_to_qlit(obj, level=3D0, dict_value=3DFalse): @@ -68,24 +82,20 @@ def _tree_to_qlit(obj, level=3D0, dict_value=3DFalse): def indent(level): return level * 4 * ' ' =20 - if isinstance(obj, tuple): - ifobj, extra =3D obj - ifcond =3D extra.get('if') - comment =3D extra.get('comment') - + if isinstance(obj, Annotated): # NB: _tree_to_qlit is called recursively on the values of a key:v= alue # pair; those values can't be decorated with comments or condition= als. msg =3D "dict values cannot have attached comments or if-condition= als." assert not dict_value, msg =20 ret =3D '' - if comment: - ret +=3D indent(level) + '/* %s */\n' % comment - if ifcond: - ret +=3D gen_if(ifcond) - ret +=3D _tree_to_qlit(ifobj, level) - if ifcond: - ret +=3D '\n' + gen_endif(ifcond) + if obj.comment: + ret +=3D indent(level) + '/* %s */\n' % obj.comment + if obj.ifcond: + ret +=3D gen_if(obj.ifcond) + ret +=3D _tree_to_qlit(obj.value, level) + if obj.ifcond: + ret +=3D '\n' + gen_endif(obj.ifcond) return ret =20 ret =3D '' @@ -202,7 +212,7 @@ def _use_type(self, typ): =20 @staticmethod def _gen_features(features): - return [_make_tree(f.name, f.ifcond) for f in features] + return [Annotated(f.name, f.ifcond) for f in features] =20 def _gen_tree(self, name, mtype, obj, ifcond, features): comment: Optional[str] =3D None @@ -216,7 +226,7 @@ def _gen_tree(self, name, mtype, obj, ifcond, features): obj['meta-type'] =3D mtype if features: obj['features'] =3D self._gen_features(features) - self._trees.append(_make_tree(obj, ifcond, comment)) + self._trees.append(Annotated(obj, ifcond, comment)) =20 def _gen_member(self, member): obj =3D {'name': member.name, 'type': self._use_type(member.type)} @@ -224,7 +234,7 @@ def _gen_member(self, member): obj['default'] =3D None if member.features: obj['features'] =3D self._gen_features(member.features) - return _make_tree(obj, member.ifcond) + return Annotated(obj, member.ifcond) =20 def _gen_variants(self, tag_name, variants): return {'tag': tag_name, @@ -232,16 +242,17 @@ def _gen_variants(self, tag_name, variants): =20 def _gen_variant(self, variant): obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} - return _make_tree(obj, variant.ifcond) + return Annotated(obj, variant.ifcond) =20 def visit_builtin_type(self, name, info, json_type): self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) =20 def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): - self._gen_tree(name, 'enum', - {'values': [_make_tree(m.name, m.ifcond, None) - for m in members]}, - ifcond, features) + self._gen_tree( + name, 'enum', + {'values': [Annotated(m.name, m.ifcond) for m in members]}, + ifcond, features + ) =20 def visit_array_type(self, name, info, ifcond, element_type): element =3D self._use_type(element_type) @@ -258,12 +269,13 @@ def visit_object_type_flat(self, name, info, ifcond, = features, self._gen_tree(name, 'object', obj, ifcond, features) =20 def visit_alternate_type(self, name, info, ifcond, features, variants): - self._gen_tree(name, 'alternate', - {'members': [ - _make_tree({'type': self._use_type(m.type)}, - m.ifcond, None) - for m in variants.variants]}, - ifcond, features) + self._gen_tree( + name, 'alternate', + {'members': [Annotated({'type': self._use_type(m.type)}, + m.ifcond) + for m in variants.variants]}, + ifcond, features + ) =20 def visit_command(self, name, info, ifcond, features, arg_type, ret_type, gen, success_response, boxed, --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443310439986.8795426639659; Mon, 15 Feb 2021 18:41:50 -0800 (PST) Received: from localhost ([::1]:60846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqJB-00018Q-C1 for importer@patchew.org; Mon, 15 Feb 2021 21:41:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwk-0001oC-QF for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25063) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwd-00038A-DJ for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:38 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-303-v5aZLXNUNF2-Rm1MgthPAA-1; Mon, 15 Feb 2021 21:18:29 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 02AF41E567; Tue, 16 Feb 2021 02:18:28 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDCB810023AF; Tue, 16 Feb 2021 02:18:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441910; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iWDQ4uKfOwIdRFHk4WMo+mGh6/IxOmSEzhQJhqefhYA=; b=GPjmkp/Wf0qhFLzeb4aLSnM6pRFOOgE7XJg6RcJ8lqzPeYrHidh84pzbpgFl05psVrRbPW 0W24AbJ31UY+szJzP/MeJO2FvUaMGHS90BexGqUiz6ynZ1fKgrlzaJI/DAIkq3SYt0Np8A h0H7xqUYC56MPFxx0HftI3LBNM9nDH4= X-MC-Unique: v5aZLXNUNF2-Rm1MgthPAA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 11/19] qapi/introspect.py: improve _tree_to_qlit error message Date: Mon, 15 Feb 2021 21:18:01 -0500 Message-Id: <20210216021809.134886-12-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Trivial; make the error message just a pinch more explicit in case we trip this by accident in the future. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 5224be1a333..2ba0bfec733 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -125,7 +125,9 @@ def indent(level): elif isinstance(obj, bool): ret +=3D 'QLIT_QBOOL(%s)' % ('true' if obj else 'false') else: - assert False # not implemented + raise NotImplementedError( + f"type '{type(obj).__name__}' not implemented" + ) if level > 0: ret +=3D ',' return ret --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613442819; cv=none; d=zohomail.com; s=zohoarc; b=ReiWt+BL0TIJy93lS+tppCDc8kdj08C+x+qglF5vfe3O63/WXBBmEqhf5ehJpts8MZlBaqQ2nbtElUpmrf1DBhiJ43IP4+ArPu8yvAmWF3Yob0U4IoqNvJo0iQN7gbpn/8N7IHIgpak8RkRBO1Il/jIyFKdyiHYIpBBCemPyeUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613442819; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=D1BmD76ut5DQt6nhpuy+MEx8H6hEGRhJwlrYNiGm288=; b=PRsTShuW7eD5qTVtaMCiylQPPi7ZLt41BfIUmTN2JK44NZ+Iwebfu3Cci8DECmuLCk2fp8jT8LF8r7mra/LHiCOC29zDSP4SJkvDDsarH7EDuvPPVW4uE1hvg7EYLX2TqG7lO8b+bT4EpltoUpflhscSdcgNVMI+wZ969tDJOag= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613442819223491.7293324625406; Mon, 15 Feb 2021 18:33:39 -0800 (PST) Received: from localhost ([::1]:59956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqBG-0005p7-5A for importer@patchew.org; Mon, 15 Feb 2021 21:33:38 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwk-0001oI-T3 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:39 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26520) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwe-00038I-Dq for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:38 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-361-3NWiNN7DNySIEWCxpSynfg-1; Mon, 15 Feb 2021 21:18:30 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 00D4F801965; Tue, 16 Feb 2021 02:18:29 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DB3C10023AF; Tue, 16 Feb 2021 02:18:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441911; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D1BmD76ut5DQt6nhpuy+MEx8H6hEGRhJwlrYNiGm288=; b=R24uzr94oxAkSvL7F7uv9yfQDH0aPgDM6/ULGEVxcMKci04KTJkh2zzvfmgq/baV+S7li7 hfYQGAczTIFfBrNJCf77oJwKnD0omcBjDXKj9GnyDj6NlYIMHUb0vbGeO0Z9NbMTWwW2QH AtS7XnV5nBOcnPcPI7zwF65jCWhiuXA= X-MC-Unique: 3NWiNN7DNySIEWCxpSynfg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 12/19] qapi/introspect.py: improve readability of _tree_to_qlit Date: Mon, 15 Feb 2021 21:18:02 -0500 Message-Id: <20210216021809.134886-13-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Subjective, but I find getting rid of the comprehensions helps. Also, divide the sections into scalar and non-scalar sections, and remove old-style string formatting. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 2ba0bfec733..afad891bb2b 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -90,7 +90,7 @@ def indent(level): =20 ret =3D '' if obj.comment: - ret +=3D indent(level) + '/* %s */\n' % obj.comment + ret +=3D indent(level) + f"/* {obj.comment} */\n" if obj.ifcond: ret +=3D gen_if(obj.ifcond) ret +=3D _tree_to_qlit(obj.value, level) @@ -101,33 +101,36 @@ def indent(level): ret =3D '' if not dict_value: ret +=3D indent(level) + + # Scalars: if obj is None: ret +=3D 'QLIT_QNULL' elif isinstance(obj, str): - ret +=3D 'QLIT_QSTR(' + to_c_string(obj) + ')' + ret +=3D f"QLIT_QSTR({to_c_string(obj)})" + elif isinstance(obj, bool): + ret +=3D f"QLIT_QBOOL({str(obj).lower()})" + + # Non-scalars: elif isinstance(obj, list): - elts =3D [_tree_to_qlit(elt, level + 1).strip('\n') - for elt in obj] - elts.append(indent(level + 1) + "{}") ret +=3D 'QLIT_QLIST(((QLitObject[]) {\n' - ret +=3D '\n'.join(elts) + '\n' + for value in obj: + ret +=3D _tree_to_qlit(value, level + 1).strip('\n') + '\n' + ret +=3D indent(level + 1) + '{}\n' ret +=3D indent(level) + '}))' elif isinstance(obj, dict): - elts =3D [] - for key, value in sorted(obj.items()): - elts.append(indent(level + 1) + '{ %s, %s }' % - (to_c_string(key), - _tree_to_qlit(value, level + 1, True))) - elts.append(indent(level + 1) + '{}') ret +=3D 'QLIT_QDICT(((QLitDictEntry[]) {\n' - ret +=3D ',\n'.join(elts) + '\n' + for key, value in sorted(obj.items()): + ret +=3D indent(level + 1) + "{{ {:s}, {:s} }},\n".format( + to_c_string(key), + _tree_to_qlit(value, level + 1, dict_value=3DTrue) + ) + ret +=3D indent(level + 1) + '{}\n' ret +=3D indent(level) + '}))' - elif isinstance(obj, bool): - ret +=3D 'QLIT_QBOOL(%s)' % ('true' if obj else 'false') else: raise NotImplementedError( f"type '{type(obj).__name__}' not implemented" ) + if level > 0: ret +=3D ',' return ret --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613443444; cv=none; d=zohomail.com; s=zohoarc; b=jC35CUEAmCCozp6lOAJqCKs8HU9IJmQ8qtKV7hdMVxIlMoO4dKlgfs0UbRDZA1qrs8UWP05JgCtlh1gh5OxIJpX5Q6lWtXmW3DufUIPS/J8QJzZ3YXZCd0HZbWM55VPZX9JNAUCWkn1eZ17BgicoDG/eNFXG/3PVWsc9rjG0oq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613443444; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Sp2u1lIVfdVptqh5ZDczvVjhtTTjq8lIMFAyfYHoDNg=; b=SvY/0ujZM8yEBT4fR/ZuOuAFCy/hYjlP8Y9q43fU/4fmoAb5MNM+SpTXX0Ym4itAN2KQYedrtsTdDAsLxKqITDOPzNziHNnmZDPRrkezqJ2OtaB0dUY+qCjGcofRz6Tdpf/AdW5sr/UoBtdZRe2v+Z4/2eWsXwEuuLXZEkdWEuo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161344344458999.58725833331118; Mon, 15 Feb 2021 18:44:04 -0800 (PST) Received: from localhost ([::1]:38422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqLL-0003UJ-KF for importer@patchew.org; Mon, 15 Feb 2021 21:44:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwo-0001pq-ER for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwj-00039Z-Pt for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:42 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-214-9wqygy6bO7yW4Li2OUJhwA-1; Mon, 15 Feb 2021 21:18:30 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 02E3D1005501; Tue, 16 Feb 2021 02:18:30 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B19A10023AF; Tue, 16 Feb 2021 02:18:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441913; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Sp2u1lIVfdVptqh5ZDczvVjhtTTjq8lIMFAyfYHoDNg=; b=Zn1cIdAkw8lafjPboxBEKOt37RK25oXaexfwlRii6IQXIvOBXkacYq3VKX4dg3E6Aomt29 tieq2FDaflerk/yTOx1YDCcVEOhFA+W3YnW9I/8/dVjXzGwN2hes5nvr/rE3m7G17pRjhZ yB/tEp6MKieKwSvKa/wQrsIBNIjixMg= X-MC-Unique: 9wqygy6bO7yW4Li2OUJhwA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 13/19] qapi/introspect.py: remove _gen_variants helper Date: Mon, 15 Feb 2021 21:18:03 -0500 Message-Id: <20210216021809.134886-14-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It is easier to give a name to all of the dictly-typed objects we pass around in introspect.py by removing this helper, as it does not return an object that has any knowable type by itself. Inline it into its only caller instead. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index afad891bb2b..b0fcc4443c1 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -241,10 +241,6 @@ def _gen_member(self, member): obj['features'] =3D self._gen_features(member.features) return Annotated(obj, member.ifcond) =20 - def _gen_variants(self, tag_name, variants): - return {'tag': tag_name, - 'variants': [self._gen_variant(v) for v in variants]} - def _gen_variant(self, variant): obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} return Annotated(obj, variant.ifcond) @@ -268,9 +264,8 @@ def visit_object_type_flat(self, name, info, ifcond, fe= atures, members, variants): obj =3D {'members': [self._gen_member(m) for m in members]} if variants: - obj.update(self._gen_variants(variants.tag_member.name, - variants.variants)) - + obj['tag'] =3D variants.tag_member.name + obj['variants'] =3D [self._gen_variant(v) for v in variants.va= riants] self._gen_tree(name, 'object', obj, ifcond, features) =20 def visit_alternate_type(self, name, info, ifcond, features, variants): --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613443417; cv=none; d=zohomail.com; s=zohoarc; b=Ln0T71usmP+O+Y1rIsec4I64LzloScRIuX4SQ8nqeYxSr0o9srpMg9smkhTCk3XA6AexwlGZetBKhwneOfTv1Ls0OmCgT8aDHi5BVDJ9ju3tOQmWvk1cRxlPP34DB4Ifgdiwj54jSw4LgiXA+8AsyAXC++vAQAQr/IoeZgr49Bc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613443417; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=q/s45A+SguWedINdcfzDHUWLK2rpBpkBQ/3Tuuy1jq8=; b=T67bGpi/9B2A2tLrtl3BebfFNvaOBOilxpcRgykGlh9l63Kp6//jC5PtFtGOxObg5lh6kBSU4V34xEODiQ+uDonxhebQO/ewezRU73qfliYbn+DFo07dHeebg230o/cMkoQ4Ljb+VwYIdInTaJIZTHNXGf1TVHup2qVCnLMDjAU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443417497985.1955062232224; Mon, 15 Feb 2021 18:43:37 -0800 (PST) Received: from localhost ([::1]:37560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqKt-00038r-60 for importer@patchew.org; Mon, 15 Feb 2021 21:43:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwo-0001pe-8k for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60007) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwk-00039j-4o for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:40 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-474-m_OiqFI8MBuP00-hv34Kiw-1; Mon, 15 Feb 2021 21:18:32 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 175BD107ACE4; Tue, 16 Feb 2021 02:18:31 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F36A10023AF; Tue, 16 Feb 2021 02:18:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441914; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q/s45A+SguWedINdcfzDHUWLK2rpBpkBQ/3Tuuy1jq8=; b=cB9hakpUMDPcU47IskBQ7KqQeV5HSIccIbjJLfM3PnIq6lWdmax7MDFyBOzgy9/5jo58Uy vqd1XjlAc/FrDZ3Z9qhTfwr0zQWI9QjWzNxiTOphy6WFzrkfvmXLCQgj8nC4k+rJ1vbvVK LKahn5NefQuYgzeSC05olAlAyNf1e0c= X-MC-Unique: m_OiqFI8MBuP00-hv34Kiw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 14/19] qapi/introspect.py: add type hint annotations Date: Mon, 15 Feb 2021 21:18:04 -0500 Message-Id: <20210216021809.134886-15-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" NB: The type aliases (SchemaInfo et al) declare intent for some of the "dictly-typed" objects we pass around in introspect.py. They do not enforce the shape of those objects, and cannot, until Python 3.7 or later. (And even then, it may not be "worth it".) Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/introspect.py | 124 +++++++++++++++++++++++++++---------- scripts/qapi/mypy.ini | 5 -- scripts/qapi/schema.py | 2 +- 3 files changed, 92 insertions(+), 39 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index b0fcc4443c1..45284af1330 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -17,6 +17,7 @@ Iterable, List, Optional, + Sequence, Tuple, TypeVar, Union, @@ -30,10 +31,19 @@ ) from .gen import QAPISchemaMonolithicCVisitor from .schema import ( + QAPISchema, QAPISchemaArrayType, QAPISchemaBuiltinType, + QAPISchemaEntity, + QAPISchemaEnumMember, + QAPISchemaFeature, + QAPISchemaObjectType, + QAPISchemaObjectTypeMember, QAPISchemaType, + QAPISchemaVariant, + QAPISchemaVariants, ) +from .source import QAPISourceInfo =20 =20 # This module constructs a tree data structure that is used to @@ -58,6 +68,15 @@ _Value =3D Union[_Scalar, _NonScalar] JSONValue =3D Union[_Value, 'Annotated[_Value]'] =20 +# These types are based on structures defined in QEMU's schema, so we lack +# precise types for them here. Python 3.6 does not offer TypedDict constru= cts, +# so they are broadly typed here as simple Python Dicts. +SchemaInfo =3D Dict[str, object] +SchemaInfoObject =3D Dict[str, object] +SchemaInfoObjectVariant =3D Dict[str, object] +SchemaInfoObjectMember =3D Dict[str, object] +SchemaInfoCommand =3D Dict[str, object] + =20 _ValueT =3D TypeVar('_ValueT', bound=3D_Value) =20 @@ -77,9 +96,11 @@ def __init__(self, value: _ValueT, ifcond: Iterable[str], self.ifcond: Tuple[str, ...] =3D tuple(ifcond) =20 =20 -def _tree_to_qlit(obj, level=3D0, dict_value=3DFalse): +def _tree_to_qlit(obj: JSONValue, + level: int =3D 0, + dict_value: bool =3D False) -> str: =20 - def indent(level): + def indent(level: int) -> str: return level * 4 * ' ' =20 if isinstance(obj, Annotated): @@ -136,21 +157,21 @@ def indent(level): return ret =20 =20 -def to_c_string(string): +def to_c_string(string: str) -> str: return '"' + string.replace('\\', r'\\').replace('"', r'\"') + '"' =20 =20 class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor): =20 - def __init__(self, prefix, unmask): + def __init__(self, prefix: str, unmask: bool): super().__init__( prefix, 'qapi-introspect', ' * QAPI/QMP schema introspection', __doc__) self._unmask =3D unmask - self._schema =3D None - self._trees =3D [] - self._used_types =3D [] - self._name_map =3D {} + self._schema: Optional[QAPISchema] =3D None + self._trees: List[Annotated[SchemaInfo]] =3D [] + self._used_types: List[QAPISchemaType] =3D [] + self._name_map: Dict[str, str] =3D {} self._genc.add(mcgen(''' #include "qemu/osdep.h" #include "%(prefix)sqapi-introspect.h" @@ -158,10 +179,10 @@ def __init__(self, prefix, unmask): ''', prefix=3Dprefix)) =20 - def visit_begin(self, schema): + def visit_begin(self, schema: QAPISchema) -> None: self._schema =3D schema =20 - def visit_end(self): + def visit_end(self) -> None: # visit the types that are actually used for typ in self._used_types: typ.visit(self) @@ -183,18 +204,18 @@ def visit_end(self): self._used_types =3D [] self._name_map =3D {} =20 - def visit_needed(self, entity): + def visit_needed(self, entity: QAPISchemaEntity) -> bool: # Ignore types on first pass; visit_end() will pick up used types return not isinstance(entity, QAPISchemaType) =20 - def _name(self, name): + def _name(self, name: str) -> str: if self._unmask: return name if name not in self._name_map: self._name_map[name] =3D '%d' % len(self._name_map) return self._name_map[name] =20 - def _use_type(self, typ): + def _use_type(self, typ: QAPISchemaType) -> str: assert self._schema is not None =20 # Map the various integer types to plain int @@ -216,10 +237,13 @@ def _use_type(self, typ): return self._name(typ.name) =20 @staticmethod - def _gen_features(features): + def _gen_features(features: List[QAPISchemaFeature] + ) -> List[Annotated[str]]: return [Annotated(f.name, f.ifcond) for f in features] =20 - def _gen_tree(self, name, mtype, obj, ifcond, features): + def _gen_tree(self, name: str, mtype: str, obj: Dict[str, object], + ifcond: Sequence[str], + features: Optional[List[QAPISchemaFeature]]) -> None: comment: Optional[str] =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: @@ -233,42 +257,65 @@ def _gen_tree(self, name, mtype, obj, ifcond, feature= s): obj['features'] =3D self._gen_features(features) self._trees.append(Annotated(obj, ifcond, comment)) =20 - def _gen_member(self, member): - obj =3D {'name': member.name, 'type': self._use_type(member.type)} + def _gen_member(self, member: QAPISchemaObjectTypeMember + ) -> Annotated[SchemaInfoObjectMember]: + obj: SchemaInfoObjectMember =3D { + 'name': member.name, + 'type': self._use_type(member.type) + } if member.optional: obj['default'] =3D None if member.features: obj['features'] =3D self._gen_features(member.features) return Annotated(obj, member.ifcond) =20 - def _gen_variant(self, variant): - obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} + def _gen_variant(self, variant: QAPISchemaVariant + ) -> Annotated[SchemaInfoObjectVariant]: + obj: SchemaInfoObjectVariant =3D { + 'case': variant.name, + 'type': self._use_type(variant.type) + } return Annotated(obj, variant.ifcond) =20 - def visit_builtin_type(self, name, info, json_type): + def visit_builtin_type(self, name: str, info: Optional[QAPISourceInfo], + json_type: str) -> None: self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) =20 - def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): + def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], + ifcond: Sequence[str], + features: List[QAPISchemaFeature], + members: List[QAPISchemaEnumMember], + prefix: Optional[str]) -> None: self._gen_tree( name, 'enum', {'values': [Annotated(m.name, m.ifcond) for m in members]}, ifcond, features ) =20 - def visit_array_type(self, name, info, ifcond, element_type): + def visit_array_type(self, name: str, info: Optional[QAPISourceInfo], + ifcond: Sequence[str], + element_type: QAPISchemaType) -> None: element =3D self._use_type(element_type) self._gen_tree('[' + element + ']', 'array', {'element-type': elem= ent}, ifcond, None) =20 - def visit_object_type_flat(self, name, info, ifcond, features, - members, variants): - obj =3D {'members': [self._gen_member(m) for m in members]} + def visit_object_type_flat(self, name: str, info: Optional[QAPISourceI= nfo], + ifcond: Sequence[str], + features: List[QAPISchemaFeature], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> = None: + obj: SchemaInfoObject =3D { + 'members': [self._gen_member(m) for m in members] + } if variants: obj['tag'] =3D variants.tag_member.name obj['variants'] =3D [self._gen_variant(v) for v in variants.va= riants] self._gen_tree(name, 'object', obj, ifcond, features) =20 - def visit_alternate_type(self, name, info, ifcond, features, variants): + def visit_alternate_type(self, name: str, info: Optional[QAPISourceInf= o], + ifcond: Sequence[str], + features: List[QAPISchemaFeature], + variants: QAPISchemaVariants) -> None: self._gen_tree( name, 'alternate', {'members': [Annotated({'type': self._use_type(m.type)}, @@ -277,27 +324,38 @@ def visit_alternate_type(self, name, info, ifcond, fe= atures, variants): ifcond, features ) =20 - def visit_command(self, name, info, ifcond, features, - arg_type, ret_type, gen, success_response, boxed, - allow_oob, allow_preconfig, coroutine): + def visit_command(self, name: str, info: Optional[QAPISourceInfo], + ifcond: Sequence[str], + features: List[QAPISchemaFeature], + arg_type: Optional[QAPISchemaObjectType], + ret_type: Optional[QAPISchemaType], gen: bool, + success_response: bool, boxed: bool, allow_oob: bool, + allow_preconfig: bool, coroutine: bool) -> None: assert self._schema is not None =20 arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type - obj =3D {'arg-type': self._use_type(arg_type), - 'ret-type': self._use_type(ret_type)} + obj: SchemaInfoCommand =3D { + 'arg-type': self._use_type(arg_type), + 'ret-type': self._use_type(ret_type) + } if allow_oob: obj['allow-oob'] =3D allow_oob self._gen_tree(name, 'command', obj, ifcond, features) =20 - def visit_event(self, name, info, ifcond, features, arg_type, boxed): + def visit_event(self, name: str, info: Optional[QAPISourceInfo], + ifcond: Sequence[str], features: List[QAPISchemaFeatur= e], + arg_type: Optional[QAPISchemaObjectType], + boxed: bool) -> None: assert self._schema is not None + arg_type =3D arg_type or self._schema.the_empty_object_type self._gen_tree(name, 'event', {'arg-type': self._use_type(arg_type= )}, ifcond, features) =20 =20 -def gen_introspect(schema, output_dir, prefix, opt_unmask): +def gen_introspect(schema: QAPISchema, output_dir: str, prefix: str, + opt_unmask: bool) -> None: vis =3D QAPISchemaGenIntrospectVisitor(prefix, opt_unmask) schema.visit(vis) vis.write(output_dir) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 04bd5db5278..0a000d58b37 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -13,11 +13,6 @@ disallow_untyped_defs =3D False disallow_incomplete_defs =3D False check_untyped_defs =3D False =20 -[mypy-qapi.introspect] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False - [mypy-qapi.parser] disallow_untyped_defs =3D False disallow_incomplete_defs =3D False diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 353e8020a27..ff16578f6de 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -28,7 +28,7 @@ class QAPISchemaEntity: meta: Optional[str] =3D None =20 - def __init__(self, name, info, doc, ifcond=3DNone, features=3DNone): + def __init__(self, name: str, info, doc, ifcond=3DNone, features=3DNon= e): assert name is None or isinstance(name, str) for f in features or []: assert isinstance(f, QAPISchemaFeature) --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613442882273962.8477642485055; Mon, 15 Feb 2021 18:34:42 -0800 (PST) Received: from localhost ([::1]:35924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqCH-0007Y5-6p for importer@patchew.org; Mon, 15 Feb 2021 21:34:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpww-0001sM-AI for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57797) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwk-00039r-Bm for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:49 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-445-vDEoAauoOBmLWeQzc7Fnxw-1; Mon, 15 Feb 2021 21:18:33 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 37449107ACE8; Tue, 16 Feb 2021 02:18:32 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4661710023AF; Tue, 16 Feb 2021 02:18:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441915; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JbjjJaKFa+SlwK9OlMG4An3gLabHZYYQqzfTpJqeYJQ=; b=COlEAk4p9nMnokSPh/XSLmI6tlpSI+SFtnhfets++ZcY3KI01+3NBEwlfzoVjmWI6kScxd BG91G7HK88Kncqo7yc6Z4vgzMroylze3k3IwQnNVtRgrIIQjKlxlCYKRpIhsuaRs7w1Gtz tUj2me6vcFtnlENYPC6eNUZqK1C1Nbw= X-MC-Unique: vDEoAauoOBmLWeQzc7Fnxw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 15/19] qapi/introspect.py: Add docstrings to _gen_tree and _tree_to_qlit Date: Mon, 15 Feb 2021 21:18:05 -0500 Message-Id: <20210216021809.134886-16-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow --- scripts/qapi/introspect.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 45284af1330..5d4f5e23f7e 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -99,6 +99,15 @@ def __init__(self, value: _ValueT, ifcond: Iterable[str], def _tree_to_qlit(obj: JSONValue, level: int =3D 0, dict_value: bool =3D False) -> str: + """ + Convert the type tree into a QLIT C string, recursively. + + :param obj: The value to convert. + This value may not be Annotated when dict_value is True. + :param level: The indentation level for this particular value. + :param dict_value: True when the value being processed belongs to a + dict key; which suppresses the output indent. + """ =20 def indent(level: int) -> str: return level * 4 * ' ' @@ -244,6 +253,15 @@ def _gen_features(features: List[QAPISchemaFeature] def _gen_tree(self, name: str, mtype: str, obj: Dict[str, object], ifcond: Sequence[str], features: Optional[List[QAPISchemaFeature]]) -> None: + """ + Build and append a SchemaInfo object to self._trees. + + :param name: The entity's name. + :param mtype: The entity's meta-type. + :param obj: Additional entity fields, as appropriate for the meta-= type. + :param ifcond: Sequence of conditionals that apply to this entity. + :param features: Optional features field for SchemaInfo. + """ comment: Optional[str] =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613443545; cv=none; d=zohomail.com; s=zohoarc; b=Wq7htJ6fwqLMmCgVjx6vFXVGXdPmB5a3wi3vks/mWMPDA6TrlRJb/Dxj1ecFuAOC8H8tGnU33BMQBkCNKTia0V48Nb3vZrGv8IocdPvPuJ+DK8eAslfGNamX1qHtyQoJa03231z9ASjOUuQ3SbTToDqEkjxZcLMYos1l9PAaEx8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613443545; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PIdfBLgEnZ/ulGsI7dfb/9sE+cfaTugjtW7ZL1vaVqU=; b=QX4cyMgix3MBSE9QWAvXvPKaIi7fEG/GH/gng/paatNQK6Mjye2qF326g1rbXF4kdSMGcoVJXB06BIumPsT6QEuyR1+rcayOXbWu4cqNXGji07tbvrG0mz7md8CJB746H14Pb5N/fwMoMwdnQxgqBdA+QyLnORTTbVuUFw5+pCE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443545582278.92087920650715; Mon, 15 Feb 2021 18:45:45 -0800 (PST) Received: from localhost ([::1]:42764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqMy-0005G0-BR for importer@patchew.org; Mon, 15 Feb 2021 21:45:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47054) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpwv-0001rh-Nw for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53296) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwk-00039x-Ig for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:48 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-507-BodOYnl2MUSLaVwAsRhG9A-1; Mon, 15 Feb 2021 21:18:34 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5198618A08BD; Tue, 16 Feb 2021 02:18:33 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6531510023AF; Tue, 16 Feb 2021 02:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441916; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PIdfBLgEnZ/ulGsI7dfb/9sE+cfaTugjtW7ZL1vaVqU=; b=H9Jcz9KU77y5HFLcOmHZbC8kRpAZ0KbbAro3ha1HEepDxuDqWxqh9MippuPI1FFIsSkmRM KzAs0yXhGidrJl4C5MVF5sh9aqdGSCPngK8A1rtPGFJDZwwjmhNDVGufKXLhxWNbybU7Og cJoCTC/xZdVDG9f2kBcP2C5pTc1rKTU= X-MC-Unique: BodOYnl2MUSLaVwAsRhG9A-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 16/19] qapi/introspect.py: Update copyright and authors list Date: Mon, 15 Feb 2021 21:18:06 -0500 Message-Id: <20210216021809.134886-17-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" To reflect the work that went into strictly typing introspect.py, punish myself by claiming credit. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 5d4f5e23f7e..649225988d1 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -1,10 +1,11 @@ """ QAPI introspection generator =20 -Copyright (C) 2015-2018 Red Hat, Inc. +Copyright (C) 2015-2021 Red Hat, Inc. =20 Authors: Markus Armbruster + John Snow =20 This work is licensed under the terms of the GNU GPL, version 2. See the COPYING file in the top-level directory. --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443060414588.5954956113985; Mon, 15 Feb 2021 18:37:40 -0800 (PST) Received: from localhost ([::1]:43552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqF9-0002Qb-41 for importer@patchew.org; Mon, 15 Feb 2021 21:37:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpww-0001sz-Qj for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41631) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwk-0003A5-K7 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:50 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-207-888VQ6F3MYKc59EgNfgVUg-1; Mon, 15 Feb 2021 21:18:35 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8AB52801962; Tue, 16 Feb 2021 02:18:34 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8238F10023AF; Tue, 16 Feb 2021 02:18:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441917; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2mhAxduW96AZmSO+4SUDhkdACORPz0Iapanao3jJ4ys=; b=cNfqJrEnNifbljakHXxLK5MWDY/U8cCGgEXW1LFPNQk78pdovU01fwN2FGVkzwt6NMMS8H 1+wLvaIAb0yGUpHMxmUQnKb0tcj3oYYEGiKYwmq+hP18JQYtyA1LmkZjp4Ap6b7klLMmJ0 kz24kWyj5FA1A5tnAesvChUmBj6EW3M= X-MC-Unique: 888VQ6F3MYKc59EgNfgVUg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 17/19] qapi/introspect.py: Type _gen_tree variants as Sequence[str] Date: Mon, 15 Feb 2021 21:18:07 -0500 Message-Id: <20210216021809.134886-18-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Optional[List] is clunky; an empty sequence can more elegantly convey "no variants". By downgrading "List" to "Sequence", we can also accept tuples; this is useful for the empty tuple specifically, which we may use as a default parameter because it is immutable. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 649225988d1..e4d31a59503 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -247,13 +247,13 @@ def _use_type(self, typ: QAPISchemaType) -> str: return self._name(typ.name) =20 @staticmethod - def _gen_features(features: List[QAPISchemaFeature] + def _gen_features(features: Sequence[QAPISchemaFeature] ) -> List[Annotated[str]]: return [Annotated(f.name, f.ifcond) for f in features] =20 def _gen_tree(self, name: str, mtype: str, obj: Dict[str, object], ifcond: Sequence[str], - features: Optional[List[QAPISchemaFeature]]) -> None: + features: Sequence[QAPISchemaFeature] =3D ()) -> None: """ Build and append a SchemaInfo object to self._trees. =20 @@ -261,7 +261,8 @@ def _gen_tree(self, name: str, mtype: str, obj: Dict[st= r, object], :param mtype: The entity's meta-type. :param obj: Additional entity fields, as appropriate for the meta-= type. :param ifcond: Sequence of conditionals that apply to this entity. - :param features: Optional features field for SchemaInfo. + :param features: Optional, The features field for SchemaInfo. + Will be omitted from the output if empty. """ comment: Optional[str] =3D None if mtype not in ('command', 'event', 'builtin', 'array'): @@ -298,7 +299,7 @@ def _gen_variant(self, variant: QAPISchemaVariant =20 def visit_builtin_type(self, name: str, info: Optional[QAPISourceInfo], json_type: str) -> None: - self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) + self._gen_tree(name, 'builtin', {'json-type': json_type}, []) =20 def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], ifcond: Sequence[str], @@ -316,7 +317,7 @@ def visit_array_type(self, name: str, info: Optional[QA= PISourceInfo], element_type: QAPISchemaType) -> None: element =3D self._use_type(element_type) self._gen_tree('[' + element + ']', 'array', {'element-type': elem= ent}, - ifcond, None) + ifcond) =20 def visit_object_type_flat(self, name: str, info: Optional[QAPISourceI= nfo], ifcond: Sequence[str], --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443194282938.2527796036023; Mon, 15 Feb 2021 18:39:54 -0800 (PST) Received: from localhost ([::1]:53334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqHJ-0006Pf-9z for importer@patchew.org; Mon, 15 Feb 2021 21:39:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47120) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpx2-00023W-Ji for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:19:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24130) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwm-0003AN-5c for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:56 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-69-g3nFl8bOMYGg_q0mxJsNLw-1; Mon, 15 Feb 2021 21:18:36 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DBC121005501; Tue, 16 Feb 2021 02:18:35 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id D152510023AF; Tue, 16 Feb 2021 02:18:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441919; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mzODA49PLmmw6n1S5YkiLhIcb3q6IG6kueYjN/epRek=; b=Sq4upv+EdDftgRwcCqrW3CkAWdDm68xo046eFdVJEVQ4yIOE/kLf53VB+1PLO2Iop52Z9f /JL+2MSOFqymmrfcfL+Ef41PKXhOpKbn1pC20L55fQjyn4D4CopSCUMsF3xmSJzixK/X8E 2pUJh+cfS9/R7Rk3wnELXV8yQ2uW9Q4= X-MC-Unique: g3nFl8bOMYGg_q0mxJsNLw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 18/19] qapi/introspect.py: set _gen_tree's default ifcond argument to () Date: Mon, 15 Feb 2021 21:18:08 -0500 Message-Id: <20210216021809.134886-19-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We don't need to create an empty, mutable list to pass to _gen_tree; since it is now typed as a Sequence, we can use the empty tuple as a default and omit the argument. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index e4d31a59503..c6f5cf8d874 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -252,7 +252,7 @@ def _gen_features(features: Sequence[QAPISchemaFeature] return [Annotated(f.name, f.ifcond) for f in features] =20 def _gen_tree(self, name: str, mtype: str, obj: Dict[str, object], - ifcond: Sequence[str], + ifcond: Sequence[str] =3D (), features: Sequence[QAPISchemaFeature] =3D ()) -> None: """ Build and append a SchemaInfo object to self._trees. @@ -299,7 +299,7 @@ def _gen_variant(self, variant: QAPISchemaVariant =20 def visit_builtin_type(self, name: str, info: Optional[QAPISourceInfo], json_type: str) -> None: - self._gen_tree(name, 'builtin', {'json-type': json_type}, []) + self._gen_tree(name, 'builtin', {'json-type': json_type}) =20 def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], ifcond: Sequence[str], --=20 2.29.2 From nobody Fri May 17 22:16:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1613443694852854.5155277758666; Mon, 15 Feb 2021 18:48:14 -0800 (PST) Received: from localhost ([::1]:47248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBqPN-0007Dq-Oi for importer@patchew.org; Mon, 15 Feb 2021 21:48:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBpx0-0001xJ-4V for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lBpwo-0003BH-Q2 for qemu-devel@nongnu.org; Mon, 15 Feb 2021 21:18:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-147-6Cq9WWAGMrKvXsbUn6VyYQ-1; Mon, 15 Feb 2021 21:18:37 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E825518A08BD; Tue, 16 Feb 2021 02:18:36 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 145F210023AF; Tue, 16 Feb 2021 02:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613441921; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RvAM2p9Jnry+sfrZ7Q3u3rWfTFYXPxirwLNGlxvqK0Y=; b=NxSYZzI5nm+2jvq33W5B1l1W1nvCJ25+G2NPpzViYvJ357D2mEa9bYkmOdQnmEvbiMHFnr ojOa0m77dtA3gM0rCWFuOSlI8Y/h9cVJO+Do/2ysm1p8W2R4ZDEfdBC6J+XiHJPFmM9/i8 EbBMzAjAf7+tcD/prITUc4DRqHi7Le0= X-MC-Unique: 6Cq9WWAGMrKvXsbUn6VyYQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v6 19/19] qapi/introspect.py: add SchemaMetaType enum Date: Mon, 15 Feb 2021 21:18:09 -0500 Message-Id: <20210216021809.134886-20-jsnow@redhat.com> In-Reply-To: <20210216021809.134886-1-jsnow@redhat.com> References: <20210216021809.134886-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Follows the qapi/introspect.py definition of the same; this adds a more precise typing to _gen_tree's mtype parameter. NB: print(SchemaMetaType.BUILTIN) would produce the string "SchemaMetaType.BUILTIN", but when using format strings (.format or f-strin= gs), it relies on the __format__ method defined in the Enum class, which uses the "value" of the enum instead, producing the string "builtin". For consistency with old-style format strings (which simply call the __str__ method of an object), a __str__ dunder is added, though it is not actually used here in this code. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index c6f5cf8d874..008a21f5c4c 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -11,6 +11,7 @@ See the COPYING file in the top-level directory. """ =20 +from enum import Enum from typing import ( Any, Dict, @@ -79,6 +80,23 @@ SchemaInfoCommand =3D Dict[str, object] =20 =20 +class SchemaMetaType(str, Enum): + """ + Mimics the SchemaMetaType enum from qapi/introspect.json. + """ + BUILTIN =3D 'builtin' + ENUM =3D 'enum' + ARRAY =3D 'array' + OBJECT =3D 'object' + ALTERNATE =3D 'alternate' + COMMAND =3D 'command' + EVENT =3D 'event' + + def __str__(self) -> str: + # Needed for intuitive behavior with old-style format strings. + return str(self.value) + + _ValueT =3D TypeVar('_ValueT', bound=3D_Value) =20 =20 @@ -251,7 +269,8 @@ def _gen_features(features: Sequence[QAPISchemaFeature] ) -> List[Annotated[str]]: return [Annotated(f.name, f.ifcond) for f in features] =20 - def _gen_tree(self, name: str, mtype: str, obj: Dict[str, object], + def _gen_tree(self, name: str, mtype: SchemaMetaType, + obj: Dict[str, object], ifcond: Sequence[str] =3D (), features: Sequence[QAPISchemaFeature] =3D ()) -> None: """ @@ -299,7 +318,7 @@ def _gen_variant(self, variant: QAPISchemaVariant =20 def visit_builtin_type(self, name: str, info: Optional[QAPISourceInfo], json_type: str) -> None: - self._gen_tree(name, 'builtin', {'json-type': json_type}) + self._gen_tree(name, SchemaMetaType.BUILTIN, {'json-type': json_ty= pe}) =20 def visit_enum_type(self, name: str, info: Optional[QAPISourceInfo], ifcond: Sequence[str], @@ -307,7 +326,7 @@ def visit_enum_type(self, name: str, info: Optional[QAP= ISourceInfo], members: List[QAPISchemaEnumMember], prefix: Optional[str]) -> None: self._gen_tree( - name, 'enum', + name, SchemaMetaType.ENUM, {'values': [Annotated(m.name, m.ifcond) for m in members]}, ifcond, features ) @@ -316,8 +335,8 @@ def visit_array_type(self, name: str, info: Optional[QA= PISourceInfo], ifcond: Sequence[str], element_type: QAPISchemaType) -> None: element =3D self._use_type(element_type) - self._gen_tree('[' + element + ']', 'array', {'element-type': elem= ent}, - ifcond) + self._gen_tree('[' + element + ']', SchemaMetaType.ARRAY, + {'element-type': element}, ifcond) =20 def visit_object_type_flat(self, name: str, info: Optional[QAPISourceI= nfo], ifcond: Sequence[str], @@ -330,14 +349,14 @@ def visit_object_type_flat(self, name: str, info: Opt= ional[QAPISourceInfo], if variants: obj['tag'] =3D variants.tag_member.name obj['variants'] =3D [self._gen_variant(v) for v in variants.va= riants] - self._gen_tree(name, 'object', obj, ifcond, features) + self._gen_tree(name, SchemaMetaType.OBJECT, obj, ifcond, features) =20 def visit_alternate_type(self, name: str, info: Optional[QAPISourceInf= o], ifcond: Sequence[str], features: List[QAPISchemaFeature], variants: QAPISchemaVariants) -> None: self._gen_tree( - name, 'alternate', + name, SchemaMetaType.ALTERNATE, {'members': [Annotated({'type': self._use_type(m.type)}, m.ifcond) for m in variants.variants]}, @@ -361,7 +380,7 @@ def visit_command(self, name: str, info: Optional[QAPIS= ourceInfo], } if allow_oob: obj['allow-oob'] =3D allow_oob - self._gen_tree(name, 'command', obj, ifcond, features) + self._gen_tree(name, SchemaMetaType.COMMAND, obj, ifcond, features) =20 def visit_event(self, name: str, info: Optional[QAPISourceInfo], ifcond: Sequence[str], features: List[QAPISchemaFeatur= e], @@ -370,7 +389,8 @@ def visit_event(self, name: str, info: Optional[QAPISou= rceInfo], assert self._schema is not None =20 arg_type =3D arg_type or self._schema.the_empty_object_type - self._gen_tree(name, 'event', {'arg-type': self._use_type(arg_type= )}, + self._gen_tree(name, SchemaMetaType.EVENT, + {'arg-type': self._use_type(arg_type)}, ifcond, features) =20 =20 --=20 2.29.2