From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613748806; cv=none; d=zohomail.com; s=zohoarc; b=JRzLR3Zpf5deNrSYV0E6IxQeeKSeWb4ETB017FEx0ClkKThk8gCPWpR/MysGcK+XRCqhAiEXuTV4i84x6ys3kneot+GAKQEm9aSkqYvMajn4v6muxKZF4rwyi5D3fSw86K00gfXbDSSeC0aN8q/c5WFAHF02caxmCk25mDack/g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613748806; 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=tHAtws+imYRp5WLRxXY+1UYV1caRGeIQdggY3VW/Ryk=; b=VH49v4j07ivJ3b+JwCOv89MuZ5/7barlEbEvzT/TsGq1Z3KBf9YcSjGUtmAQBix5Z8xphEKPDp2dMf14/tCc5k7PZTSiKVW42XRb9wym+pmabfG0LebVzNITA8GRVI5PAElE2GN9tq7nSh+Wnrw7mljbwF3hQzCSFQYjULcQhjU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613748806433126.10532617112835; Fri, 19 Feb 2021 07:33:26 -0800 (PST) Received: from localhost ([::1]:60000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7mX-0006St-9Q for importer@patchew.org; Fri, 19 Feb 2021 10:33:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76P-0004kM-1Z for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43893) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76H-0004gG-AF for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:52 -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-109-P12HuQUlMxSRZFKFawy_-w-1; Fri, 19 Feb 2021 09:49:42 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 20CFF107ACE3; Fri, 19 Feb 2021 14:49:41 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C0120189C4; Fri, 19 Feb 2021 14:49:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5041E11384A9; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746184; 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=tHAtws+imYRp5WLRxXY+1UYV1caRGeIQdggY3VW/Ryk=; b=IbXPLxJR63p8Q6U7ubYWueuG4RKFqDbHg2cR8wKQFip2t1b5Wl55wQen70k7W+RMyuCNOF IHs1GqBQd3jnhfsPjWIn2lezg/W0PiMPl05+FVQtYgBJQzs4do2V2JIoWyQvCH3cnI9Hk7 UvAfmkLSLbNrobiy0RdufUup50C14bE= X-MC-Unique: P12HuQUlMxSRZFKFawy_-w-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 01/18] qapi: Replace List[str] with Sequence[str] for ifcond Date: Fri, 19 Feb 2021 15:49:22 +0100 Message-Id: <20210219144939.604488-2-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 safely with a Mutable type like a List. Signed-off-by: John Snow Message-Id: <20210216021809.134886-2-jsnow@redhat.com> Reviewed-by: Markus Armbruster [Commit message tweaked] Signed-off-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 54af519f44..0a75a9371b 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -17,6 +17,7 @@ from typing import ( Dict, List, Optional, + Sequence, Set, ) =20 @@ -297,7 +298,7 @@ void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) 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 8c57deb2b8..90d2f6156d 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,7 +12,7 @@ This work is licensed under the terms of the GNU GPL, ver= sion 2. 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 @@ void %(event_emit)s(%(event_enum)s event, QDict *qdict); 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 63549cc8d4..1fa503bdbd 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -17,8 +17,8 @@ import re from typing import ( Dict, Iterator, - List, Optional, + Sequence, Tuple, ) =20 @@ -85,7 +85,7 @@ class QAPIGen: 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 @@ class QAPIGenH(QAPIGenC): =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 2bdd626847..20d572a23a 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -13,7 +13,7 @@ This work is licensed under the terms of the GNU GPL, ver= sion 2. # 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 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): 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 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): 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 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): 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 @@ class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisito= r): 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 22e62df901..9aa0b1e11e 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -13,7 +13,7 @@ This work is licensed under the terms of the GNU GPL, ver= sion 2. 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 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): 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 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): 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 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): 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 @@ class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisit= or): 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613748449; cv=none; d=zohomail.com; s=zohoarc; b=k/DQJ7q4Ic8mjl3DETz0KwNMUCL5+xklfDN+jjfuAr0YaD4Br6QJqBEcq3Phq5ybwqdhmRES6jjLFIyjqAYR+NSVmqsQyW/d3cG+0N9yMVXeuNqVb+7OC3aqU26PArymS+XGYCbLXZ6jbycuVwoiUP5+nU2xLXH8BZMslcuEOKw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613748449; 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=HBOtivzueR7DXVHddcxof+IkSn6IyrqQ6SQevqUYueA=; b=Ff1N0CCDa35QhD4EK5AQBKFKacf8Mv/VRRBI20AU87MXL2953OCXxMHV8FtSDuqGg34sSHSsSe6uH02nYkDbFF8+B4v8hgiu9XVDkoqdzn0NXTndMszefq5IFPrxfxffn+p1Db86YqWJm1W4tKprgocK3CVOYq0mnj4IHZd1x3A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 16137484494101012.3357997932824; Fri, 19 Feb 2021 07:27:29 -0800 (PST) Received: from localhost ([::1]:43172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7gk-0007b3-7o for importer@patchew.org; Fri, 19 Feb 2021 10:27:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76L-0004ci-MZ for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:49 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53116) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76G-0004g7-Sc for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49: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-281-6LOTebJlNWCqnutGyMOf9Q-1; Fri, 19 Feb 2021 09:49:42 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F032780196C; Fri, 19 Feb 2021 14:49:40 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C145C5D720; Fri, 19 Feb 2021 14:49:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 538041138467; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746184; 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=HBOtivzueR7DXVHddcxof+IkSn6IyrqQ6SQevqUYueA=; b=Y+mfoQ/Z8rs4qzZIyYv7zHwh6/wBxHR1/L9EHGiwbzwoSPtXW2YB9EeWSMZ/SlC/29HjNW 4EzCmzu7ABY4W3hE+JoIXelADAhiVYmJvSxTSG8N9NQcqI2OvaHQRiaRj+gpMLT3h6uBAJ gj+lnvQ+yOvm3yTGHXlq2ratDQdWMrw= X-MC-Unique: 6LOTebJlNWCqnutGyMOf9Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 02/18] qapi/introspect.py: assert schema is not None Date: Fri, 19 Feb 2021 15:49:23 +0100 Message-Id: <20210219144939.604488-3-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-3-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/introspect.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index fafec94e02..43ab4be1f7 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -147,6 +147,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613749291; cv=none; d=zohomail.com; s=zohoarc; b=BPMULZcDdMdYvaNwKXNJtZUq+ff4L5mf1Ldz94470P1e4fgTXiGkEgLtzzBhb+NCpCpw/DsePgMmTsxAn9BFUgZmYjF4t7GDVQQ8qfSs3eZSD61pjGG3cdEtX6oHCx8ah3fJVg5zUGKAlsXTnSdc1wpQNnxIZLBQym9KcukQv7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749291; 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=H4iGPlygXsWFDu+3pe20e9H86zjZ6x8sPPEUJPlXGFo=; b=kgNk83WXCBItNG1krFsfjSqEfHJGATnR07BfRN/3TuB5XJl77awEnbsyXUj0N+vSVQKCLgLTQu53obfvWmHG/BlVaZRrEUjdEEkEThmzn1rC4r4wXEOROHOtI+/W5cVF0myorp/fnW8qmLuZKNV3MqK/hIeNQOxbfAmtUKPNNtA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613749291135820.0659691589926; Fri, 19 Feb 2021 07:41:31 -0800 (PST) Received: from localhost ([::1]:56996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7uL-0001uz-ST for importer@patchew.org; Fri, 19 Feb 2021 10:41:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35672) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD77f-0006H7-7O for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:51:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49770) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD77d-0005Gw-8m for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:51:10 -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-215-y1sGrziVOlmPvWjdcWO4Gg-1; Fri, 19 Feb 2021 09:49:42 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0089A193578F; Fri, 19 Feb 2021 14:49:41 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5A9160918; Fri, 19 Feb 2021 14:49:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 56BE11132C27; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746268; 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=H4iGPlygXsWFDu+3pe20e9H86zjZ6x8sPPEUJPlXGFo=; b=LfacbP+8R4IYgGxy/Qn1tz+V1B5WndPLMqTZpaxvYgYzH4/bkQI/tsEC+mYnZBO4Qrk4rS QzaST4bW8lnmBPAMyZ4sx3pQW6xSDYdac2cWitDVuNX9Zai+HHQOsTWsGy4toGjgz0dY4G wZuAKfriYx8xQOB17QtjEhWEISfmkx4= X-MC-Unique: y1sGrziVOlmPvWjdcWO4Gg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 03/18] qapi/introspect.py: use _make_tree for features nodes Date: Fri, 19 Feb 2021 15:49:24 +0100 Message-Id: <20210219144939.604488-4-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-4-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 43ab4be1f7..3295a15c98 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613748345; cv=none; d=zohomail.com; s=zohoarc; b=PRJFHMyxabmfnZNKyzVzhNDlF3dpRA0YpMkhKRUAbhpnyQLeKkumtxE9NbxPxl5GLyF9ERnAda/bBojngzbslwfZk+W3TDp0LNrEmUFCqy86HTK4xTsHTf8C7uX1WvnCe5sZ9P6d9IOD/pVzRjTlqnA5Rgp7zvKefQSaSuP7nyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613748345; 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=Y4+4XzK2YlPze0zoq4fG6+eJnV5feYSAPBwxa0jzBwI=; b=QnM7AKwo2ESXW/784ZJ0raUNQ/IlG9qcAUTpQDiI3tWf2koxT5L69Io4Z1TUn+hcyZnxM/HCs1K1WHqHGUREw4uIGeXsRUa98zxYvwz4X8TnyjJCtaFJRWqTn87sgbxYjQU6Se3oGp5774qJuoFoQpARXSf6FSzbdpT27UcedSw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613748345629839.0257633688626; Fri, 19 Feb 2021 07:25:45 -0800 (PST) Received: from localhost ([::1]:36076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7f6-0004Z3-Cc for importer@patchew.org; Fri, 19 Feb 2021 10:25:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD77X-00061g-Pt for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:51:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40103) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD77U-0005CR-55 for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:51:03 -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-25-1PFIKKPMMz-xEtrrabYaMw-1; Fri, 19 Feb 2021 09:49:42 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01F24804036; Fri, 19 Feb 2021 14:49:41 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C786418B4B; Fri, 19 Feb 2021 14:49:40 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5A0211132C28; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746259; 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=Y4+4XzK2YlPze0zoq4fG6+eJnV5feYSAPBwxa0jzBwI=; b=RpXeAXH7ZIsaNjUfy1pLhy4/CLmPzDgrJpIuU9YdltYnE7C4ktl1K60KfCmVXeN87WZPFq wdyxbzCkcKm0a4vhCVNURORC3JTboG/q1RqniG2bpzPsf4AgNQhuKcO+qf5MjQH2Y7WoiV GhGm6ZCtAXfrNqd9IQdXWpu/hqifhIk= X-MC-Unique: 1PFIKKPMMz-xEtrrabYaMw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 04/18] qapi/introspect.py: add _gen_features helper Date: Fri, 19 Feb 2021 15:49:25 +0100 Message-Id: <20210219144939.604488-5-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow _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 Message-Id: <20210216021809.134886-5-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 3295a15c98..4749f65ea3 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -24,15 +24,11 @@ from .schema import ( ) =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 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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 @@ const QLitObject %(c_name)s =3D %(c_string)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 @@ const QLitObject %(c_name)s =3D %(c_string)s; =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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613748810; cv=none; d=zohomail.com; s=zohoarc; b=L+qM3zhgf/O0YsbAfO4FRYWNC0/2fT1DSFUGUAyekfIS68y+KjrJv3neQH9T3nvjTIWi3Qhgf17UxrbLmIEPXBRygirKiXAsXeVOIUbHZ1BryUYR9JBAMzh1Z9JrmM76MhziPhQnBF1n+Pqhq/akMi7AT5P+fkGlzazMoriOvQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613748810; 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=sKvSCrWJgDaM1XL5Ydgj2XX97p/M7blbQpYX0fUnAWA=; b=jEhzJn+GlEnZGqk2AlsoLjkFNgIejsx3wsGNbIY09grUo1id732ZF9kQyu8xdLjm88SriaxEkkztDikrKQPVv7/H1taIv17KQeMluwPcODk/IFXRU1z1J2LQ8cBYGKXQu2O6ERiWs4WoBtgoHCHLJEfDde8rYiCn4O3f8QtmQYo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 161374881012960.500367381681144; Fri, 19 Feb 2021 07:33:30 -0800 (PST) Received: from localhost ([::1]:60264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7mb-0006bS-0P for importer@patchew.org; Fri, 19 Feb 2021 10:33:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76N-0004hy-TF for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21146) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76L-0004hY-7d for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:51 -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-277-QiJq0ZqPMK-6_koEY3p5Fg-1; Fri, 19 Feb 2021 09:49:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 612791005501; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 31E3D60BFA; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5D3681132C29; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746185; 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=sKvSCrWJgDaM1XL5Ydgj2XX97p/M7blbQpYX0fUnAWA=; b=cz+XQFBkLhN23crCfz3MbVRYR//POY1tPFOgt0eKb31e9nW/F0gXhQQymnMOoxwLfWXnCk fr+g2YgEdKh0vMs40zRAfIr6DC7blZ/nrQI/PXoaMdAGyou3OenZ8ss0HEZhsGAQhH7fEw TH11EPt2M9b/5wntzGq2Zva9LSryHxg= X-MC-Unique: QiJq0ZqPMK-6_koEY3p5Fg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 05/18] qapi/introspect.py: guard against ifcond/comment misuse Date: Fri, 19 Feb 2021 15:49:26 +0100 Message-Id: <20210219144939.604488-6-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow _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 Message-Id: <20210216021809.134886-6-jsnow@redhat.com> Reviewed-by: Markus Armbruster [Comment wrapped to conform to PEP 8] Signed-off-by: Markus Armbruster --- scripts/qapi/introspect.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 4749f65ea3..a111cec725 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,13 @@ def _tree_to_qlit(obj, level=3D0, suppress_first_indent= =3DFalse): 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:value pair; those values can't be decorated with + # comments or conditionals. + 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 +61,7 @@ def _tree_to_qlit(obj, level=3D0, suppress_first_indent= =3DFalse): 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(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 1613748199478425.3423104305584; Fri, 19 Feb 2021 07:23:19 -0800 (PST) Received: from localhost ([::1]:55906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7ck-0000To-6Q for importer@patchew.org; Fri, 19 Feb 2021 10:23:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76b-00054K-FT for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46901) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76U-0004mF-KR for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:05 -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-468-1BrJlc8hNnm_YUdTXB3FVw-1; Fri, 19 Feb 2021 09:49:43 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 63BE556C8B; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 34F355D720; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 61DE51132C2A; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746197; 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=/FOMD62ivIBj2i5Y6ge+3y6DOR8xIgGfMFEQyFgGVGw=; b=QMRpSZK+wuTh4HGiw196mV14LfKHaJcGqYmo4K2eQdvpvsFOIEI7NjV7gWbLou/ckSK9I9 xkmkKChQnIZlT4egIRPw3uq/l1Jy/orKMGyb11+nqu7Y49gx4voTz2roQe83AF+d+TOG+c 7Q4GHkZOL5F65iiBHUGnIeVkbu9yusU= X-MC-Unique: 1BrJlc8hNnm_YUdTXB3FVw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 06/18] qapi/introspect.py: Unify return type of _make_tree() Date: Fri, 19 Feb 2021 15:49:27 +0100 Message-Id: <20210219144939.604488-7-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Returning two different types conditionally can be complicated to type. Return one type for consistency. Signed-off-by: John Snow Message-Id: <20210216021809.134886-7-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 a111cec725..7cce0de975 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613748017; cv=none; d=zohomail.com; s=zohoarc; b=Yjjs/z9XXaO+QppdCbYgujrQ7R1GoDhRMu+Ov5HZccMAJ4zxWcjd0JdUOGG3bZpks3G0VCF1filTWfLRyE0zbmZOUYwbOkLnbMkw/f3miEQTUddKEP7mKkvMYRGpL7gdXnF93jH0q1cszPXUfZjxWlVjE7FbiRqMxoBF3nOu7HM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613748017; 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=Y6s5De957ndfIjSccxJ/JckAz5b81HflxdPH5EbzcmM=; b=bdhiljh8TnN4ZSyr9wQcOqMSHjsLuky9+/mHXs5ha51tgFLxdO/VxRS7LXJEfP/DhNxQEW2HVHupotq2unZ8SXw1hwXRxmRPkaCJMttRI7BW6uNlbCJdQPxmpjnhGCmatnfzuGhX3+Vk6MsNuhx9h1b8TY51B8lDJXKVxw2Q6Mg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613748016335189.72562085827133; Fri, 19 Feb 2021 07:20:16 -0800 (PST) Received: from localhost ([::1]:45260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7Zm-0004RL-E8 for importer@patchew.org; Fri, 19 Feb 2021 10:20:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35298) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76Z-00051p-Q6 for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51599) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76U-0004lv-7h for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:03 -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-249-gRN9nYKtOhuSV59M4x2bCw-1; Fri, 19 Feb 2021 09:49:43 -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 6952D804023; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A1F410016F6; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 63B011132BCA; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746197; 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=Y6s5De957ndfIjSccxJ/JckAz5b81HflxdPH5EbzcmM=; b=iDX8HIzH0JK0O8i05utEDg7uYqFZiwighvDxl9WDSLW6JmQAX7nSX4sbQ9Iyvo+9FWMZ/Q /MdHH7x06LVDTEseJbgQT4D+5W3iNcUNNI1/F1OCbREbZfoQAdpuGOVfzbzqFygRYDjsyG 6uZcyly3oscbUgfi0HOxgqeZhrR43Qg= X-MC-Unique: gRN9nYKtOhuSV59M4x2bCw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 07/18] qapi/introspect.py: replace 'extra' dict with 'comment' argument Date: Fri, 19 Feb 2021 15:49:28 +0100 Message-Id: <20210219144939.604488-8-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@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=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-8-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 7cce0de975..c4326d42cb 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,6 +10,8 @@ This work is licensed under the terms of the GNU GPL, ver= sion 2. 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 @@ from .schema import ( ) =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 @@ -175,18 +178,18 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613749224; cv=none; d=zohomail.com; s=zohoarc; b=RHCd69NNpZYXmz5QSKQmd19YR6WGf8RLeITOll1ymNnqf9XmxxdAXhhPhChpH+DdsRvCfSf/7v99cHxgOfxCD6EnNs19ok9o6saZ2+Pp6S18cBAfOblxiSTiKs3l1pzBxScI44R9zlnD6mSmCzfAAgKAa3QTQ2Z8x2gsXHwpRwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749224; 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=Tz1BoVgdyudwnalNO9Lnr8YzIE3ksFbBSc9cpe2j8WU=; b=W7PynW+i5d+mNwpz9IpacGqPduFDtqBxPqhUA586EGVv66lkOB3MPU1Il6Tmk12CoWtA51VhNoR0qYL36g/p+quYTQYAzFp4m9qKBce+2uQDUuhEELo7ITsrbiSAeV1HVo8BijYovEzllFL0dFIgC1H3Il+5q3U1dPnGdFh6A8w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613749223627387.5458434473052; Fri, 19 Feb 2021 07:40:23 -0800 (PST) Received: from localhost ([::1]:53972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7tG-0000bx-F1 for importer@patchew.org; Fri, 19 Feb 2021 10:40:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76R-0004rf-WA for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:56 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76L-0004hi-E1 for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:55 -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-544-PY6Z6HpaMsq-dOwszA33DA-1; Fri, 19 Feb 2021 09:49:43 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6C08256C95; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C8011970D; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 66E431132BCE; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746186; 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=Tz1BoVgdyudwnalNO9Lnr8YzIE3ksFbBSc9cpe2j8WU=; b=A5RQPqSK+yzFC+kQTiAEgKhvymw/wWW0dw+xqXWhafh1167EW9zDPP2t8Y6SEiemQPUv6M ilWWBKExS8sw8usl+ZO/TB2J+Ign3+ZTC/uoKCK8Rv1NyqdTxDVayR6oviklvZ0VXzSgRS 5RurH5blP1a7GiE8NkYvCNlEvoqbG/M= X-MC-Unique: PY6Z6HpaMsq-dOwszA33DA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 08/18] qapi/introspect.py: Always define all 'extra' dict keys Date: Fri, 19 Feb 2021 15:49:29 +0100 Message-Id: <20210219144939.604488-9-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-9-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 c4326d42cb..88af5383d5 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -27,11 +27,10 @@ from .schema import ( =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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613748953; cv=none; d=zohomail.com; s=zohoarc; b=Slzl33PlebeLBNeUPL+N5cQvt+N8im+rlXmV/Ep8wL8GUPg1Hx1/zlR3RRFIPqWgiAjs4r4AD7VeN1LEUabJ8kTVbqKKtJimUPASpOR0/UH/Dkjv1rEa5pGFVPY0YqZkD1ntsdz7qXyPqdM3drd32a2zTX9WlR0xbzK3SHloyu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613748953; 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=udx7BRgtU4reuY5BaNoVk9odBuwqVgSNpOhXbpa/k6I=; b=PRbObMltVFEry5C84yDtE4ZMVxEPryxHj+WmGDprqNyrevCwuUrDcfPIMaFX4tyVOyDj5SaV1o39Vcpzsr08zHgs7QolBqW7YvPCuL1pZQO/uNdbpmZwzupJHTvOYw1zPBMEfS70l/6njV89jaVY4PIFG8nZGTeK5IAp2tKVvkg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613748953208495.32278039064863; Fri, 19 Feb 2021 07:35:53 -0800 (PST) Received: from localhost ([::1]:38742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7ot-0002SZ-Ht for importer@patchew.org; Fri, 19 Feb 2021 10:35:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76a-00053Z-RC for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47030) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76U-0004mG-KU for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:04 -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-468-_uXCTNM3NT2xj4uDvk1b3g-1; Fri, 19 Feb 2021 09:49:43 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6BDE1107ACE6; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3D64F5C1BB; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6A18A1132A01; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746197; 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=udx7BRgtU4reuY5BaNoVk9odBuwqVgSNpOhXbpa/k6I=; b=K6hSJQI0swImtsB2t8a1gBfJNKGObHR2vqtMhn5euv8+wnkuO29/GAmTK5IxF/ksVvbcxA cxVpO8lXNvncsTAm/d8z+6A9R20oI05P4KSr/yJj2Fx7plAYLDir1bSJOG0/Eei9x5/u9H zQ0hRp+y2xzLoQnZjFro5eT2zzTXY2c= X-MC-Unique: _uXCTNM3NT2xj4uDvk1b3g-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 09/18] qapi/introspect.py: Introduce preliminary tree typing Date: Fri, 19 Feb 2021 15:49:30 +0100 Message-Id: <20210219144939.604488-10-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-10-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 88af5383d5..c271006100 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,7 +10,13 @@ This work is licensed under the terms of the GNU GPL, ve= rsion 2. 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 @@ from .schema import ( ) =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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(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 1613749090676118.99009203667651; Fri, 19 Feb 2021 07:38:10 -0800 (PST) Received: from localhost ([::1]:47570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7r7-0006MG-E8 for importer@patchew.org; Fri, 19 Feb 2021 10:38:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76c-00055V-2r for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28662) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76U-0004mL-RT for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:05 -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-320-dAD8MWk1MKG4eZZT97Nj2Q-1; Fri, 19 Feb 2021 09:49:43 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 92D3F193578B; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3D75A5D9C6; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6D62011329C9; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746198; 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=bFbDP2zZlfNtuHqScBQx2anYs3WMbWPjSozyJA2xQy8=; b=aB71rN/g3IZVsZPXhasMC0qaKNNMeVaOj6ncfnczSfpOPuthCYVrLwbs+R5SZInohMUBH3 Rxz9wQNuom6rpQlOQZR1f8iZyQGx6DVtUfb0ZAn85cZc6aiUOxcwGm9OXROeiTf1C/UYx5 mT6QNPLv+DGD54lYRUbhPqfLzEzy7g0= X-MC-Unique: dAD8MWk1MKG4eZZT97Nj2Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 10/18] qapi/introspect.py: create a typed 'Annotated' data strutcure Date: Fri, 19 Feb 2021 15:49:31 +0100 Message-Id: <20210219144939.604488-11-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-11-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 c271006100..715220afe7 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -13,8 +13,12 @@ See the COPYING file in the top-level directory. from typing import ( Any, Dict, + Generic, + Iterable, List, Optional, + Tuple, + TypeVar, Union, ) =20 @@ -52,15 +56,25 @@ _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. +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,11 +82,7 @@ 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:value pair; those values can't be decorated with # comments or conditionals. @@ -80,13 +90,13 @@ def _tree_to_qlit(obj, level=3D0, dict_value=3DFalse): 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 '' @@ -203,7 +213,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; =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 @@ -217,7 +227,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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)} @@ -225,7 +235,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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, @@ -233,16 +243,17 @@ const QLitObject %(c_name)s =3D %(c_string)s; =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) @@ -259,12 +270,13 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613748595; cv=none; d=zohomail.com; s=zohoarc; b=D5ASEiwRKHX7U5CB6IjMIB+0ZtBqU+KOAjTKfmkk8YJdBhMTgxIQMoxcJBY3SKWZJ4rzPXdTfbbN3vNuQZ74CG6j0erYCcBvS0AXV2qYPy1HHKckDN33vDWkOIn4qGzF9/v4w+7nnw88i3vz0I+wcmuyNnyskS1Ta64JCl1L6rc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613748595; 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=D2NR4siZrjkEsUqCno2TD3dq5aJK9LAAFJH/Co6AXpQ=; b=GAAOx1fANsr02FT5woNZLQWREktPFGpq7uBw/LB0RKrEn3WgqTIsXV37Xv9EX8mV2DlqeamwthFHXY8NfF1K4A/lCmJsH17162rZVRszylyIMKYpgR6wmq7t2o+myE0F5OAxQKqfaltyftdG/CF7BUhTCR0w4kkPmsMrQAgKS60= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613748595503493.87702172522813; Fri, 19 Feb 2021 07:29:55 -0800 (PST) Received: from localhost ([::1]:51624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7j8-0002k4-Dt for importer@patchew.org; Fri, 19 Feb 2021 10:29:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35228) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76O-0004k1-OM for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23099) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76L-0004hU-EK for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:52 -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-544-ay05VjqNOgeP_fyFO233eA-1; Fri, 19 Feb 2021 09:49:43 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6E75A100CC85; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 404625D723; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7092311329A2; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746185; 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=D2NR4siZrjkEsUqCno2TD3dq5aJK9LAAFJH/Co6AXpQ=; b=OwNprXWxKqfeC8N+pgPLxZJ6o4ofdMXDbm2+1NW1r9QVIYFjdyVWGAhfBwZkmHsrkftjcZ gPOG2UrDTrwnoZhZEUULtuwp/FTmPIwyU8Sb6HQfhWbZxMWerK7pu24hd3CnX3v6GE3pcJ xCZ5ZSmznDZtwGWKbAfkekb75l3fT28= X-MC-Unique: ay05VjqNOgeP_fyFO233eA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 11/18] qapi/introspect.py: improve _tree_to_qlit error message Date: Fri, 19 Feb 2021 15:49:32 +0100 Message-Id: <20210219144939.604488-12-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-12-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 715220afe7..96dfbb4cef 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -126,7 +126,9 @@ def _tree_to_qlit(obj, level=3D0, dict_value=3DFalse): 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613748593; cv=none; d=zohomail.com; s=zohoarc; b=gVEMoWWr6/Hh8y2lGBFUWcJRIWjfmVwYzhFp27Y2jkRcapD0NWX32PqP6SCjlH/rLwKm+ta7ap4IsZaAmSAXxMnf+WSuXJ8J00VsmR4eOYH344lwXUfT+JszkNaGcgxHhZ36PvTe2o2nD7hyrLH654nlMOLCdev4+Ig8CL/cp+U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613748593; 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=T3cc89Sl99+zLX9xLPVTTO5/N5O6bSWD2sDB9yhJVZA=; b=Tz9nNkTeKHcYcbZbUJOH2XDJmcWM8E97bJRF9uZqcq4NDbPt/t9reoTHO9/KXjHtfxRme/lm3uK9k5jKS30FhwdDsPebGBvdETzFrDv6RHxVoqKqrkNRS+z7x2Z6Jco2o8aRfD9Tnpr0q1X1UPO1UwaEYYsk8oN6LfvLbv87SV0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613748593218141.52611373412321; Fri, 19 Feb 2021 07:29:53 -0800 (PST) Received: from localhost ([::1]:51332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7j6-0002cu-2f for importer@patchew.org; Fri, 19 Feb 2021 10:29:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76N-0004ga-DJ for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32400) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76I-0004hW-7p for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:51 -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-287-2ebxoio5PEqcX6r2LLA8pw-1; Fri, 19 Feb 2021 09:49:43 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 760CF801965; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 466E719713; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 73C6D11329A3; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746185; 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=T3cc89Sl99+zLX9xLPVTTO5/N5O6bSWD2sDB9yhJVZA=; b=WGP7k1GVet4oQjl6ARHXHYuhKPNGcbLeNuZg+XY4YWKQkJ9kekUoOjhdpd5FWxw6NLwh1X u15qzw3S9h6s8GiRepdAD9BPYymAvRYmy/6SbFFj+fqLryOpGDxYo5qnHJtk7oF9/TQg0E SehC6l2yZ9+H5TGUvfJiziswfJA6ZxI= X-MC-Unique: 2ebxoio5PEqcX6r2LLA8pw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 12/18] qapi/introspect.py: improve readability of _tree_to_qlit Date: Fri, 19 Feb 2021 15:49:33 +0100 Message-Id: <20210219144939.604488-13-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-13-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 96dfbb4cef..26e6f73e5d 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -91,7 +91,7 @@ def _tree_to_qlit(obj, level=3D0, dict_value=3DFalse): =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) @@ -102,33 +102,36 @@ def _tree_to_qlit(obj, level=3D0, dict_value=3DFalse): 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613748804; cv=none; d=zohomail.com; s=zohoarc; b=oF/9Q9ZBx+ujMk0XTiRrZz3Z9lSYuEMLMe9HLo1bYOAjjymDzQ+53ZLuOe+hlv/xxHUs8sq+fkWK0vUPcDzBcta9t/dh1PpfZH0P5dTwDKWKklu/GIQPMg82pBTkVNhkHyme4cPQ9QsMF2+lzd7yZmwta8azTpY9VmgKiUwAjMk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613748804; 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=c1P56x1e3+Bf1AMBGNHTRRAEJh+aLuyzwL4YZp50C+4=; b=RJX9l90YkygaVAcMKw2y+LflrvwmWRwGHyy5GFdXC1X0Pt/kVkqpNypN6v95nx8mvIqZvS+sFhTEL+TNIfatw6IZA+P6Pi7cSAE8GJugLPgFRMzxnu+REaTkDghFYOTtesvMOrYBWmwvlJ/ZO3obNxR+9uT03jD6IPpEmLnYIoI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613748804079255.3557360864147; Fri, 19 Feb 2021 07:33:24 -0800 (PST) Received: from localhost ([::1]:59718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7mU-0006H8-QG for importer@patchew.org; Fri, 19 Feb 2021 10:33:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35266) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76R-0004pz-A3 for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22126) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76L-0004hu-F7 for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:55 -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-320-u6XjjyifNX-Evz27aAL7Cw-1; Fri, 19 Feb 2021 09:49:43 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8C92B56C96; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EA5613470; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 76FAC11329A9; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746187; 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=c1P56x1e3+Bf1AMBGNHTRRAEJh+aLuyzwL4YZp50C+4=; b=B8ad77lD6oveUmja+l/2R9xr8AJoVaMCPtFg9ZXItDDRzqK9CUrN8eIq8lVJw0scCFyJud eZbO3oWNGVQc2BkU2r/YlxPoD3sdI1j3s5Rf8WIcnuYn0b/ZfabBT+lLSz2ApANZytOl7I oxOfU4IVTn+sUpty+u/VxpBWkAu72i8= X-MC-Unique: u6XjjyifNX-Evz27aAL7Cw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 13/18] qapi/introspect.py: remove _gen_variants helper Date: Fri, 19 Feb 2021 15:49:34 +0100 Message-Id: <20210219144939.604488-14-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-14-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 26e6f73e5d..da7bc8883c 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -242,10 +242,6 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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) @@ -269,9 +265,8 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613749085; cv=none; d=zohomail.com; s=zohoarc; b=gn1jjV+LRcQOfpVkVWTpYh+mdNjLPD+A3y/7r8RlOBXd4OB1aTMVAPyLXHLRlek4iM/UuA9saHY5FNP/d4tXKZj8Md9hG3C/QCUB/3Em60BiO1qZI6s33zpenXKcjn/WbXwy5S7Ijm9xchTDybUh4CLh9sclbJJVrD20ihHjC2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749085; 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=QIR+F/RXcDUT3PnedrRlQ10I5Cz+44aTve4QC0Z4tr8=; b=X6b9xg8q84x5jZKilttG9I+uS4LcKmuQCHCPxusu1xaUACbAQEHzA5KOeaEAUBJh2c7TlpAKQoGhzx0tlYHtte+U1X96KfPTTrg3qfeEAVMod3mo/epJLsMEiVBm7NGMSs6HkeTlBpWCspVBEUitsdLMLrcCb/g18k7jfKRj0Ac= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 161374908479249.371100756601436; Fri, 19 Feb 2021 07:38:04 -0800 (PST) Received: from localhost ([::1]:47156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7r1-0006C5-JO for importer@patchew.org; Fri, 19 Feb 2021 10:38:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76c-00056C-F6 for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31791) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76U-0004mP-Sb for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:06 -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-318-XDIwwFpIMEOYxRG-HMSylA-1; Fri, 19 Feb 2021 09:49:43 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E399D1935780; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 680A318B4B; Fri, 19 Feb 2021 14:49:42 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7A5A4112F05F; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746198; 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=QIR+F/RXcDUT3PnedrRlQ10I5Cz+44aTve4QC0Z4tr8=; b=FrqD60jmoI9WL1t069pQ8ho6OuXREd/rr2OCglmJLPvxXKnV8hcA/qDKhaqTsmaBDIhNxl /WHdrDf9z6gD/rAbfEUZzfPeb7HqcLNPZKsJV329pYcDI6Kt5ulAfyiPtheO+1Ljj2x+rV zBHj0Z2sYjELZwEddNDLBqTC6luSFA0= X-MC-Unique: XDIwwFpIMEOYxRG-HMSylA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 14/18] qapi/introspect.py: add type hint annotations Date: Fri, 19 Feb 2021 15:49:35 +0100 Message-Id: <20210219144939.604488-15-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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".) Annotations are also added to the QAPISchemaEntity __init__ method in schema.py to allow mypy to statically prove the type of typ.name, needed to prove the return type of QAPISchemaGenIntrospectVisitor._use_type(). Signed-off-by: John Snow Message-Id: <20210216021809.134886-15-jsnow@redhat.com> Reviewed-by: Markus Armbruster [Note on QAPISchemaEntity.__init__() squashed into commit message, Comment wrapped to conform to PEP 8] Signed-off-by: Markus Armbruster --- scripts/qapi/introspect.py | 125 +++++++++++++++++++++++++++---------- scripts/qapi/mypy.ini | 5 -- scripts/qapi/schema.py | 2 +- 3 files changed, 93 insertions(+), 39 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index da7bc8883c..05c1a196e9 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -17,6 +17,7 @@ from typing import ( Iterable, List, Optional, + Sequence, Tuple, TypeVar, Union, @@ -30,10 +31,19 @@ from .common import ( ) 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,16 @@ _NonScalar =3D Union[Dict[str, _Stub], List[_Stub]] _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 constructs, 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 +97,11 @@ class Annotated(Generic[_ValueT]): 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): @@ -137,21 +159,21 @@ def _tree_to_qlit(obj, level=3D0, dict_value=3DFalse): 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" @@ -159,10 +181,10 @@ class QAPISchemaGenIntrospectVisitor(QAPISchemaMonoli= thicCVisitor): ''', 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) @@ -184,18 +206,18 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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 @@ -217,10 +239,13 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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: @@ -234,42 +259,65 @@ const QLitObject %(c_name)s =3D %(c_string)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)}, @@ -278,27 +326,38 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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 04bd5db527..0a000d58b3 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 353e8020a2..ff16578f6d 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -28,7 +28,7 @@ from .parser import QAPISchemaParser 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(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 1613748959317812.5074384931451; Fri, 19 Feb 2021 07:35:59 -0800 (PST) Received: from localhost ([::1]:39394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7p0-0002nj-2n for importer@patchew.org; Fri, 19 Feb 2021 10:35:58 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76P-0004l9-EE for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32222) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76L-0004hm-EY for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49: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-2-gjbHWZ1fPnqDU0WxUqyZ8Q-1; Fri, 19 Feb 2021 09:49:44 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CE5C256C9E; Fri, 19 Feb 2021 14:49:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9E0675D720; Fri, 19 Feb 2021 14:49:43 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7D96B112EFE5; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746187; 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=SNrjT1Likzm4FHeJKHVlEcPZfAcKmK35Uffa+RKx6sw=; b=DZLoUYcTfjhHpdB62nlyTcMpJEhvN7Ai77b69zZGkg5gVGlY4oqiCUCCbSa/FVZwzqEcYf HO3i4DZMwU9iXNaQqcwFYNLPrkfoRJIksmS5U+1prZOxe5tRcF9yRu2usCwozWUXbBdV/U 1gsNtIg/IF0tummeZvGyqdZqrqS5oF4= X-MC-Unique: gjbHWZ1fPnqDU0WxUqyZ8Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 15/18] qapi/introspect.py: Add docstrings to _gen_tree and _tree_to_qlit Date: Fri, 19 Feb 2021 15:49:36 +0100 Message-Id: <20210219144939.604488-16-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=170.10.133.124; envelope-from=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Signed-off-by: John Snow Message-Id: <20210216021809.134886-16-jsnow@redhat.com> Reviewed-by: Markus Armbruster [Doc string improvements squashed in] Signed-off-by: Markus Armbruster --- scripts/qapi/introspect.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 05c1a196e9..15cce6854d 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -100,6 +100,15 @@ class Annotated(Generic[_ValueT]): 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 * ' ' @@ -246,6 +255,17 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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 SchemaInfo's name. + :param mtype: The SchemaInfo's meta-type. + :param obj: Additional SchemaInfo members, as appropriate for + the meta-type. + :param ifcond: Conditionals to apply to the SchemaInfo. + :param features: The SchemaInfo's features. + Will be omitted from the output if empty. + """ comment: Optional[str] =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: --=20 2.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613749405; cv=none; d=zohomail.com; s=zohoarc; b=Sqa+BcK3TvnEr/dHdNFkIRY3WXA1PXbrymstMcE3+khga3U9Itz5CuevSSrxcyqZP4cw5DpPHG2N0QWB7a9M/JuV0V1UpnIfJnRCC61Mli23Qn/cgEUOuzB/XeeklYPFYn7aGzyGu+8b27argnYMM6Tk5Txda6+hVopC2ZiF8+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613749405; 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=9wA5EfIRRNGMnFdxNZLWp0aICNvjDjFT2of5/uzvqd4=; b=PQBk7KePmUfdjFpWLAoLmRt2lf9DEMhFmtKWyizB3d8afAbnKKOkZE3eiksWldvsiYpETv9lOrmqCq0zmd+1RSIaIu7YAkv42J6SqrzjMu5iJqomf9hciVE6B+EFVS3ifb4dUz9dYLCTxFHQqPjRjZm7VQFJwf+uA1ntwDVAl98= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613749405426190.76544201960917; Fri, 19 Feb 2021 07:43:25 -0800 (PST) Received: from localhost ([::1]:34032 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7wC-00047u-Ar for importer@patchew.org; Fri, 19 Feb 2021 10:43:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD776-0005MM-JR for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58639) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD774-00052v-Hj for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:50:36 -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-578-pZJ57xTqNSmuwvMiHsiPIg-1; Fri, 19 Feb 2021 09:49:46 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0F1FF801965; Fri, 19 Feb 2021 14:49:45 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0A5A5C1BB; Fri, 19 Feb 2021 14:49:43 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 80C0D112EFEC; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746233; 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=9wA5EfIRRNGMnFdxNZLWp0aICNvjDjFT2of5/uzvqd4=; b=J1abhQdH84PrxgTKRCu5efuEnX2bH1VaH0771qMjZelrjFGadReDaW9gC1DsluOYDJwOvN xKP0EB46Nh9cVQc/alqbT8fhpV+oiX5DDHf2npXbfzFa/X5DwOu72x5/QvNRiuZbGSE55y cYmbzVzgw0ycRIhEUAdTbyTno3LZIqY= X-MC-Unique: pZJ57xTqNSmuwvMiHsiPIg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 16/18] qapi/introspect.py: Update copyright and authors list Date: Fri, 19 Feb 2021 15:49:37 +0100 Message-Id: <20210219144939.604488-17-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow To reflect the work that went into strictly typing introspect.py, punish myself by claiming credit. Signed-off-by: John Snow Message-Id: <20210216021809.134886-17-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 15cce6854d..e770c9432b 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613747810; cv=none; d=zohomail.com; s=zohoarc; b=m2IKECm25XjeDNNqp4idF4TEiIc4QNxKdUEj5eyeCVrgzwErfeTM4ATC9PQO1m//CTnK4n8OEQUdiruoat/agMP5BKSNJqnpLvuiZpY2X/vMltD56rQkTCSMqdfpqjAnuXofgdOX21B3RjztvAEB10NI4+XZct+fDOxQ8tlBBZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613747810; 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=5G6Uult3K5VI6ei7HCvvqbEYUw3mZuVFNs0bUUVkXeQ=; b=Lt3mBtB+fQNBemQo3nKLKhclVEpFw9Cq0QT9WVkH8lSmlnJSLQG5JmDD1+Ooz9qCbPpJYd8dpRhMAeHKpACxRJHFb7cBtV03mpQ6QyPd8F2mT0XQ+cv8/fjYmRA29ffE8w50CRgbpagPX8qzVHrVRa/p8yRHpu3iu3PpqQZ7iEM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1613747810494264.4665750477641; Fri, 19 Feb 2021 07:16:50 -0800 (PST) Received: from localhost ([::1]:36494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7WT-0000k8-C9 for importer@patchew.org; Fri, 19 Feb 2021 10:16:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76R-0004pZ-5O for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38080) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76L-0004ho-DO for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:54 -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-337-I46xMaV-OBi09X8zp8_sWg-1; Fri, 19 Feb 2021 09:49:44 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D0202100CC8D; Fri, 19 Feb 2021 14:49:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A1794189C4; Fri, 19 Feb 2021 14:49:43 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 8401C112F00D; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746187; 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=5G6Uult3K5VI6ei7HCvvqbEYUw3mZuVFNs0bUUVkXeQ=; b=DYs34X4N9/D0CHXOYx22FKRa7AEBdc0oIbr+n5nJ4T3Tt8fSa+78F6q/1nUvp+eYPi3yB8 ztTNB7K3L3BKpZteX2Wm/JQ8WUQN+6bKXQzeURr+QpdmTc4b+UmgPLfAdZNynkQYwWD5lZ v/PzWtolNCLA/wcMLgtFcTnfKMV6NkQ= X-MC-Unique: I46xMaV-OBi09X8zp8_sWg-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 17/18] qapi/introspect.py: Type _gen_tree variants as Sequence[str] Date: Fri, 19 Feb 2021 15:49:38 +0100 Message-Id: <20210219144939.604488-18-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-18-jsnow@redhat.com> Reviewed-by: Markus Armbruster [Doc string touched up] Reviewed-by: Markus Armbruster --- scripts/qapi/introspect.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index e770c9432b..d0b0fd19ed 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -249,13 +249,13 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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 @@ -302,7 +302,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; =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], @@ -320,7 +320,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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.26.2 From nobody Thu May 9 12:44:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(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 1613749086402431.9152869965791; Fri, 19 Feb 2021 07:38:06 -0800 (PST) Received: from localhost ([::1]:47308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lD7r3-0006Fr-28 for importer@patchew.org; Fri, 19 Feb 2021 10:38:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lD76Q-0004or-Sh for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44644) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lD76N-0004ja-Qo for qemu-devel@nongnu.org; Fri, 19 Feb 2021 09:49:54 -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-525-SOs_vSv6P7KbM2aUMkrrug-1; Fri, 19 Feb 2021 09:49:44 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D77B4107ACC7; Fri, 19 Feb 2021 14:49:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-115-79.ams2.redhat.com [10.36.115.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A88425D723; Fri, 19 Feb 2021 14:49:43 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 874D4112F00E; Fri, 19 Feb 2021 15:49:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613746191; 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=NJsuE+XY10A55L2ra06E5BJAIiWIFCTpd7myuOY+Ogk=; b=TnY/2Di2WJm06dd9cWHfm4fqQYKCGzzPm2hAWwDqn3+MP2Ek5tXSZiTDzeYqQnXB6ZWnPw gTEZ+QEHd1sjMPQ5BQYMSvZ6kPJlw3gVjJJa2R8v2hJfvFYGxEQSj2CToTx5ezX+19NrOX HabTaufCjnN8CxmoLWV9AUK/8fh37xA= X-MC-Unique: SOs_vSv6P7KbM2aUMkrrug-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 18/18] qapi/introspect.py: set _gen_tree's default ifcond argument to () Date: Fri, 19 Feb 2021 15:49:39 +0100 Message-Id: <20210219144939.604488-19-armbru@redhat.com> In-Reply-To: <20210219144939.604488-1-armbru@redhat.com> References: <20210219144939.604488-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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=armbru@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: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow 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 Message-Id: <20210216021809.134886-19-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- 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 d0b0fd19ed..9a348ca2e5 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -254,7 +254,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; 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. @@ -302,7 +302,7 @@ const QLitObject %(c_name)s =3D %(c_string)s; =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.26.2