From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288137; cv=none; d=zohomail.com; s=zohoarc; b=h4UO/3DfFXOHQWL7njM3h75poncwZ9Ws/lBrSDaqjs9DBzfBxFcFhc7lGm0kcJtQLPXDsNBPItXSJ2kjIg3vpDxybrpyms1dwqLncfoHcAFFPW2mIU7I9NBMmA124RBi8/4HtHq7IZqApyIPUJM3eEtgpX2NOR3h3+CcT5fhVvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288137; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XWr0AcRlsQez5Aq3NxYWxDa4M/wcTgndy6zggib5YUk=; b=d308X7FYlIX1ZyL2tn9QzXXmnFrky4OKEYA9OiNqiSlrCgvBHsPdE7s7ZNakBFA6Tm7oCEMnsWBQ6m3/+loP51IdUxnILyo2aMzNBTbSHDcnDHX1G7R0FJaR7nhMFEfQY/hS3sto6uClbzKXfCor+dYeh0OunEU4AOIpvC61Q4Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288137979411.66419597264303; Tue, 2 Feb 2021 09:48:57 -0800 (PST) Received: from localhost ([::1]:50834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6znM-0006UA-Ms for importer@patchew.org; Tue, 02 Feb 2021 12:48:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlW-0004j3-9G for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39947) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlU-0008AS-Cu for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:02 -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-384-S5AIT4FVMK6rNaXOXqz8ZA-1; Tue, 02 Feb 2021 12:46:56 -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 E2062835E21; Tue, 2 Feb 2021 17:46:53 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 278F85C1CF; Tue, 2 Feb 2021 17:46:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288018; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XWr0AcRlsQez5Aq3NxYWxDa4M/wcTgndy6zggib5YUk=; b=RIeSZhtLMYmmQQ+jLSDSvwSftwg9kYRMopsWaEjsgn+5oRvHIfx26H4jEbYsv3gqiAAp4A NZhXhjwbPGseBzwGQJZivm5ia1JOInoIVpH6jEuwoA+BqDF+YknBB4qZkJ3CFqA9DnzQMG 5i0RxN9TvHAYp5yNYhqEtbMMlZ47rvE= X-MC-Unique: S5AIT4FVMK6rNaXOXqz8ZA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 01/14] qapi/introspect.py: assert schema is not None Date: Tue, 2 Feb 2021 12:46:38 -0500 Message-Id: <20210202174651.2274166-2-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The introspect visitor is stateful, but expects that it will have a schema to refer to. Add assertions that state this. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index fafec94e022..43ab4be1f77 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -147,6 +147,8 @@ def _name(self, name): return self._name_map[name] =20 def _use_type(self, typ): + assert self._schema is not None + # Map the various integer types to plain int if typ.json_type() =3D=3D 'int': typ =3D self._schema.lookup_type('int') @@ -225,6 +227,8 @@ def visit_alternate_type(self, name, info, ifcond, feat= ures, variants): def visit_command(self, name, info, ifcond, features, arg_type, ret_type, gen, success_response, boxed, allow_oob, allow_preconfig, coroutine): + assert self._schema is not None + arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type obj =3D {'arg-type': self._use_type(arg_type), @@ -234,6 +238,7 @@ def visit_command(self, name, info, ifcond, features, self._gen_tree(name, 'command', obj, ifcond, features) =20 def visit_event(self, name, info, ifcond, features, arg_type, boxed): + assert self._schema is not None arg_type =3D arg_type or self._schema.the_empty_object_type self._gen_tree(name, 'event', {'arg-type': self._use_type(arg_type= )}, ifcond, features) --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288379; cv=none; d=zohomail.com; s=zohoarc; b=Tx1vzkW7xqqHJsFtblux5kNZjNnb1yFyfzOU+0XKSoN3KpfUQl1UHnVzj/bjemZgCdsGWwrMbq/qcYRon1+G1A9jjiqQhr6JPDV7LrPSu6SxU3NLn5o7lxhzr5s+muU2bYvwlAZUepw/x/CbQVsfxR8Ea/8VH7aYdAvVNLcfIf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288379; 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=8DOXV3YUlb956rFhumyfuqnFObM1oyNO6UcyQdM6/4Q=; b=oFdvJlgjUwzrC1rRFUTSZbq964fSFeTxtjLRVCY9cTFB9v57o7HA9jShLKOmS5xym5m2ngbApcZBAuQv/xp8oS43uwQZttAM0AQr0WQTT6sCtmipyS6W5kTh7BjjgMgLYGXGyH0duRg5qnx4ThCrEc2CFXdHeDLxbvdtJ286kt4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288379227260.94221216521885; Tue, 2 Feb 2021 09:52:59 -0800 (PST) Received: from localhost ([::1]:59094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zrF-0001h1-SS for importer@patchew.org; Tue, 02 Feb 2021 12:52:57 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlX-0004jz-2j for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28068) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlV-0008BG-GI for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:02 -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-480-egD_HxESPRObyIV1JFpysg-1; Tue, 02 Feb 2021 12:46:56 -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 11614106BAE8; Tue, 2 Feb 2021 17:46:55 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 344CA5C5FC; Tue, 2 Feb 2021 17:46:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288020; 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=8DOXV3YUlb956rFhumyfuqnFObM1oyNO6UcyQdM6/4Q=; b=Ja+Na7IALTtUg3AI4y3pWcyFx1hxkRMPvMql6vTyBEVsWcdw113RWiYfu6COfthoq6EjhK I4p2xhzig7Snm86dtOm+B31XaKOJplqU+zLLlTI5cKb29CwXVQqgq6Q2l4SFhqFLiDE0P2 pmDKafT8OzUewF6zLlo0EHVVko6xCC0= X-MC-Unique: egD_HxESPRObyIV1JFpysg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 02/14] qapi/introspect.py: use _make_tree for features nodes Date: Tue, 2 Feb 2021 12:46:39 -0500 Message-Id: <20210202174651.2274166-3-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 43ab4be1f77..3295a15c98e 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -30,7 +30,9 @@ def _make_tree(obj, ifcond, features, extra=3DNone): if ifcond: extra['if'] =3D ifcond if features: - obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in features] + obj['features'] =3D [ + _make_tree(f.name, f.ifcond, None) for f in features + ] if extra: return (obj, extra) return obj --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288200; cv=none; d=zohomail.com; s=zohoarc; b=Ej9DxqJp25l3G4hSOfs9Xnf5HmzyaNk5I+Jo5Bm1QvlK1LGMdpoUAfHZVYMW/5F8GA3WSdS4WPMg/963N0Jffr3mh0WUZsMUqkhoLnVIxYRQfP5b7LB1UD+wb4K+ZJlJ/PUMBXGfsswvsrWCd1009Tw5xQFuI6TnNKcic9D21vg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288200; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=acrxd18H7FqKyFi0v69UbUmTdPkZgFPrjuidbeAGGhQ=; b=WrTiGdbk66Q5Z1yD/WzohF4sn586QuSixVykN4DFszxZFMN5cPHjrLtAXzOj8imQJlJL1waK1zaMmPNzaM1bJuifWCafeUrRaDpm5AHo/Oud6msKoQx8NTKx41WmOL67jZ9s/SkjcB5JPeCfhuWQs7Acwm3WKvFDarcFtDif2JQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288200454550.3109630430325; Tue, 2 Feb 2021 09:50:00 -0800 (PST) Received: from localhost ([::1]:52824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zoE-0007Ik-Qh for importer@patchew.org; Tue, 02 Feb 2021 12:49:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43828) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlY-0004m7-3b for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlW-0008BU-9v for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47: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-444-J30PkeZ2O7i1QlfI2fmJzA-1; Tue, 02 Feb 2021 12:46:57 -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 ED744107ACE8; Tue, 2 Feb 2021 17:46:55 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 391F45C1CF; Tue, 2 Feb 2021 17:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288021; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=acrxd18H7FqKyFi0v69UbUmTdPkZgFPrjuidbeAGGhQ=; b=hzc1ukhxaUgAAc12Iiuf2XHBpkoiczfndPVoEIzYMuLUqsFO/pALvoKHawQJO5eGRhXSVX b21fnIa7BzAl69UqtUwrj0ksNzmHcnctoirLWdARS7Ry6WKANzwFRxcGnEksnkmmrjnxwd Ybvi4KvW8gxkXqkr+0QBcAzn5h1i1UM= X-MC-Unique: J30PkeZ2O7i1QlfI2fmJzA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 03/14] qapi/introspect.py: add _gen_features helper Date: Tue, 2 Feb 2021 12:46:40 -0500 Message-Id: <20210202174651.2274166-4-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" _make_tree might receive a dict (a SchemaInfo object) or some other type (usually, a string) for its obj parameter. Adding features information should arguably be performed by the caller at such a time when we know the type of the object and don't have to re-interrogate it. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 3295a15c98e..4749f65ea3c 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -24,15 +24,11 @@ ) =20 =20 -def _make_tree(obj, ifcond, features, extra=3DNone): +def _make_tree(obj, ifcond, extra=3DNone): if extra is None: extra =3D {} if ifcond: extra['if'] =3D ifcond - if features: - obj['features'] =3D [ - _make_tree(f.name, f.ifcond, None) for f in features - ] if extra: return (obj, extra) return obj @@ -169,6 +165,10 @@ def _use_type(self, typ): return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) =20 + @staticmethod + def _gen_features(features): + return [_make_tree(f.name, f.ifcond) for f in features] + def _gen_tree(self, name, mtype, obj, ifcond, features): extra =3D None if mtype not in ('command', 'event', 'builtin', 'array'): @@ -179,13 +179,17 @@ def _gen_tree(self, name, mtype, obj, ifcond, feature= s): name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype - self._trees.append(_make_tree(obj, ifcond, features, extra)) + if features: + obj['features'] =3D self._gen_features(features) + self._trees.append(_make_tree(obj, ifcond, extra)) =20 def _gen_member(self, member): obj =3D {'name': member.name, 'type': self._use_type(member.type)} if member.optional: obj['default'] =3D None - return _make_tree(obj, member.ifcond, member.features) + if member.features: + obj['features'] =3D self._gen_features(member.features) + return _make_tree(obj, member.ifcond) =20 def _gen_variants(self, tag_name, variants): return {'tag': tag_name, @@ -193,7 +197,7 @@ def _gen_variants(self, tag_name, variants): =20 def _gen_variant(self, variant): obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} - return _make_tree(obj, variant.ifcond, None) + return _make_tree(obj, variant.ifcond) =20 def visit_builtin_type(self, name, info, json_type): self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288626; cv=none; d=zohomail.com; s=zohoarc; b=HijCFDkp1cS0bNZpQXMXVaRdibrR4pMNdMoR4bi+Jn82+xNDufGjuL6eQspZaFWEyFJuxuaWmzn8PqaqO5IbvjUMCqzK1Atz+gTDVv7XqYAqemXmwj3FaQlRkcMX3q1u+4zGIAggPI9AYMgt58oz7wqsFt8RlSMGZJlHKcfBvkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288626; 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=vAvdidcxAG70q1T89fjw/Ce4mvUGyQrT1MKRfSG98VM=; b=fnQljZObK0WXqvTG4mEQL6doiAvcdD7BE9tteZd9oVTeYvYZ9RU2eWBqDigMLNFHnk25+BvnTsCxsT+SYHe5TeR6vH+83DU0sJv/D/GEUFWX3IlGclaS8isfl4ukQdHB9nhG2p7LTTrvjPjr0RgXxWVTbhhYOXw4S476Acu9W8Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288626126496.6390378632793; Tue, 2 Feb 2021 09:57:06 -0800 (PST) Received: from localhost ([::1]:39390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zvE-0005tO-N2 for importer@patchew.org; Tue, 02 Feb 2021 12:57:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlX-0004ky-Ow for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50727) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlU-0008At-Ak for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47: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-204-MGjz74EMNHmtfuMZuOEhBA-1; Tue, 02 Feb 2021 12:46:57 -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 D515E1934100; Tue, 2 Feb 2021 17:46:56 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2328B5C22B; Tue, 2 Feb 2021 17:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288019; 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=vAvdidcxAG70q1T89fjw/Ce4mvUGyQrT1MKRfSG98VM=; b=c/mk9QPSYqxGZ0bT9TVmJkAVj+hQC+n7mDGXYp1T8tiuRvd+QFn0tUB2yXWAOjcdZyX3IK wsQZ60phzBZsBBOKomCzIYeTXrjz49nwVGlcFkLt1LGauoo/kr9qF64R8wHf7kCqk5WTR0 W4eiD7qTzCqHedNk2h7pN0ra9ssmRng= X-MC-Unique: MGjz74EMNHmtfuMZuOEhBA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 04/14] qapi/introspect.py: guard against ifcond/comment misuse Date: Tue, 2 Feb 2021 12:46:41 -0500 Message-Id: <20210202174651.2274166-5-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" _tree_to_qlit is called recursively on dict values alone; 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. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 4749f65ea3c..ccdf4f1c0d0 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -43,6 +43,12 @@ def indent(level): ifobj, extra =3D obj ifcond =3D extra.get('if') comment =3D extra.get('comment') + + # NB: _tree_to_qlit is called recursively on the values of a key:v= alue + # pair; those values can't be decorated with comments or condition= als. + msg =3D "dict values cannot have attached comments or if-condition= als." + assert not suppress_first_indent, msg + ret =3D '' if comment: ret +=3D indent(level) + '/* %s */\n' % comment --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288380; cv=none; d=zohomail.com; s=zohoarc; b=FcjzJ827FTR5+gmEX7sPOYzfNDCilHX2y/HRkaqX87W+PVGjIVyXS/QTt+7xrqJMX7sc62ADy+QS8y186PEs0PXyjxRl1UwriRC6NAq9VxEIy4XH5QkFV+IOViaFBGgS/mz4BanzshoBYgyIKgxdsyLpvVid+yitb0RTyiuHyvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288380; 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=ldeAmiIKnAEFKCFQiHI4++OADpvPK+E3kx7sPHnd2IU=; b=Dksi4Jn8t5zHPidcS8TEvkS0sm7ENuCEsNE78Sr3ekMffWdP/9YvEgIPglkjzli7VW4Aet0Zhh6J43ulVCivDotLBfWRXsxyzpreZ/X9rdCSP20lt8VTOYV+RbgBHmsSvijtiWu2mFWDbcklCM4y6cTMTJ5okhQSd1w9BqwHST0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288380823555.5473115518573; Tue, 2 Feb 2021 09:53:00 -0800 (PST) Received: from localhost ([::1]:59238 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zrH-0001ku-J3 for importer@patchew.org; Tue, 02 Feb 2021 12:52:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlY-0004n8-IT for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlW-0008BS-CA for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47: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-469-qyPyJnk5PRWBzudEnoRWLg-1; Tue, 02 Feb 2021 12:46:58 -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 C05DA1800D50; Tue, 2 Feb 2021 17:46:57 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0948E5C1CF; Tue, 2 Feb 2021 17:46:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288021; 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=ldeAmiIKnAEFKCFQiHI4++OADpvPK+E3kx7sPHnd2IU=; b=X5hNOi3Wvq/JGt38d01KzMI3HcPhVARflTPk5sMtluzvtm0TPNYoPElsK+ZtEZ9jshadPY SQ03T50KQQB11ZzXiXG72Qc84PipJUCWF8hZ+Vtk4plGOIFu+a0QqZ/icqE346MLPp789g qGp9XPojtYjfdLUlvXYrvKx1s6NJuJI= X-MC-Unique: qyPyJnk5PRWBzudEnoRWLg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 05/14] qapi/introspect.py: Unify return type of _make_tree() Date: Tue, 2 Feb 2021 12:46:42 -0500 Message-Id: <20210202174651.2274166-6-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Returning two different types conditionally can be complicated to type. Return one type for consistency. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index ccdf4f1c0d0..d3fbf694ad2 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, suppress_first_indent=3DFalse): --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288151; cv=none; d=zohomail.com; s=zohoarc; b=SPmyDJ8589dmIEE8UJwMikE5AdNP+7Y5Zvz3lsE5MQPhetT08l9ZqTv/OKgngkLw+7xrvedz8pjfh3EuWW/Yj5Hu1vgUwsAKZfs6kream/OVuGDGpRksAcRcKgi35s0jwKYvxpk5D9DMjHOYn29kePyK/2GbviOlptOaU8zZv40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288151; 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=Qz/o09IKu9KjjNwsj6ta2xekFpM0AVQ8ov8SHgO3d34=; b=ZDrxVJXwoS+6cVOcUUNH1miAqSZJL3pJBIkl8/Q6tWpThz4Sv+G482OczTUThYN43c5FdMQPW7CYIM8L0ofKjHn/pa6uIGOv0/S8Ice08aSeuCIuCa4F8vDXh5q4PZYgAQm9cDXE+48yAehKcAMT93TmIiCNk8Yda5Au89KssiI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288151038734.2069614403462; Tue, 2 Feb 2021 09:49:11 -0800 (PST) Received: from localhost ([::1]:51220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6znX-0006dj-Tp for importer@patchew.org; Tue, 02 Feb 2021 12:49:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zla-0004qR-7h for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:30477) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlY-0008Cs-B0 for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47: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-408-5SGYpHA9Pi-ePS6omsvE2w-1; Tue, 02 Feb 2021 12:47:00 -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 AC6F91934100; Tue, 2 Feb 2021 17:46:58 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6AEA5C22B; Tue, 2 Feb 2021 17:46:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288023; 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=Qz/o09IKu9KjjNwsj6ta2xekFpM0AVQ8ov8SHgO3d34=; b=RmhVdaQlWcapk/BtgZYYwWk0pyp1qSsvpUbs2mwNb2LV/LG15uIoTwdZGwVtj63VRbY6V/ VQgdR2iJmXApzacgGmD5ijidXwGeng0Z0qwEsaZzQXz0rNvHmy6MMhO78T+E0LtYgSLclo fW3DkoyuLABTqLP/JSJYZ5z62BRE2xk= X-MC-Unique: 5SGYpHA9Pi-ePS6omsvE2w-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 06/14] qapi/introspect.py: replace 'extra' dict with 'comment' argument Date: Tue, 2 Feb 2021 12:46:43 -0500 Message-Id: <20210202174651.2274166-7-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is only used to pass in a dictionary with a comment already set, so skip the runaround and just accept the comment. This works because _tree_to_qlit() treats 'if': None; 'comment': None exactly like absent 'if'; 'comment'. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index d3fbf694ad2..0aa3b77109f 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,6 +10,8 @@ See the COPYING file in the top-level directory. """ =20 +from typing import Optional + from .common import ( c_name, gen_endif, @@ -24,11 +26,11 @@ ) =20 =20 -def _make_tree(obj, ifcond, extra=3DNone): - if extra is None: - extra =3D {} - if ifcond: - extra['if'] =3D ifcond +def _make_tree(obj, ifcond, comment=3DNone): + extra =3D { + 'if': ifcond, + 'comment': comment, + } return (obj, extra) =20 =20 @@ -174,18 +176,18 @@ def _gen_features(features): return [_make_tree(f.name, f.ifcond) for f in features] =20 def _gen_tree(self, name, mtype, obj, ifcond, features): - extra =3D None + comment: Optional[str] =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: # Output a comment to make it easy to map masked names # back to the source when reading the generated output. - extra =3D {'comment': '"%s" =3D %s' % (self._name(name), n= ame)} + comment =3D f'"{self._name(name)}" =3D {name}' name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype if features: obj['features'] =3D self._gen_features(features) - self._trees.append(_make_tree(obj, ifcond, extra)) + self._trees.append(_make_tree(obj, ifcond, comment)) =20 def _gen_member(self, member): obj =3D {'name': member.name, 'type': self._use_type(member.type)} --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288854; cv=none; d=zohomail.com; s=zohoarc; b=Qi8GVJCKrP5cGHUAtM2P7EobtW0Q/b8zFs/89/rLQorcL9vVQr9LiecxJrWDzd5LBw3e/+hkhPSWd/UyADiXO7beFWyFa6S0GQAyzcfGZew8GJ7Wm/dYTpZwiPerJImfoC2ZF4roApxLrO+4RXte08ZWFSfyLI5lU0DGKrdI5fg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288854; 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=HFDyOxoGjdw/M6uGtxwmb9fdlj1TAK7OqU/iyC4IfjE=; b=E1YOPgHsZjGOfqaaQy/sNfuOhXNM3RcCUjPh6QpzYA9N2Oo08LBaSFni2PMim4TGMsOnP4g6BVe3dD+Nh1LXxbDRcQFHPQPLx5l/tm7I3YbTryCC6yqdP04sGzs24UaHMg6AfhSqX5AdLFlVKq+wHpRMSsyyYOAqxWP7SOfwrzE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288854008256.91340700381625; Tue, 2 Feb 2021 10:00:54 -0800 (PST) Received: from localhost ([::1]:47946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zyt-0001PU-KZ for importer@patchew.org; Tue, 02 Feb 2021 13:00:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlZ-0004p5-Kq for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlX-0008Cg-Ub for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47: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-55-u_6yA9MoMCq3oNaXwsaYMg-1; Tue, 02 Feb 2021 12:47:00 -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 93AAF835E22; Tue, 2 Feb 2021 17:46:59 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id D314E5C1CF; Tue, 2 Feb 2021 17:46:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288023; 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=HFDyOxoGjdw/M6uGtxwmb9fdlj1TAK7OqU/iyC4IfjE=; b=JVqPdAo1Nti8ldi5PpWOUnTXjL4Wmg9lvg1qL8C+yCoyhbDcfjeS7ByMOIQiLk1uB09kDy Z4pBaT0GgF0veaYXcitTqppDuEMIEchA1Yr6051YRpAy20GXLueTzyFEDkIW1+qgNqKyM7 4e2xDo9DRMiyjipdSeuam2TGY5+FFeM= X-MC-Unique: u_6yA9MoMCq3oNaXwsaYMg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 07/14] qapi/introspect.py: Introduce preliminary tree typing Date: Tue, 2 Feb 2021 12:46:44 -0500 Message-Id: <20210202174651.2274166-8-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The types will be used in forthcoming patches to add typing. These types describe the layout and structure of the objects passed to _tree_to_qlit, but lack the power to describe annotations until the next commit. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 0aa3b77109f..b82efe16f6e 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,7 +10,13 @@ See the COPYING file in the top-level directory. """ =20 -from typing import Optional +from typing import ( + Any, + Dict, + List, + Optional, + Union, +) =20 from .common import ( c_name, @@ -26,6 +32,28 @@ ) =20 =20 +# This module constructs a tree data structure that is used to +# generate the introspection information for QEMU. It behaves similarly +# to 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, TreeValue], List[TreeValue]] +# +# With optional annotations, the type of all values is: +# TreeValue =3D Union[_value, Annotated[_value]] +# +# Sadly, mypy does not support recursive types, so we must approximate thi= s. +_stub =3D Any +_scalar =3D Union[str, bool, None] +_nonscalar =3D Union[Dict[str, _stub], List[_stub]] +_value =3D Union[_scalar, _nonscalar] +# TreeValue =3D Union[_value, 'Annotated[_value]'] + + def _make_tree(obj, ifcond, comment=3DNone): extra =3D { 'if': ifcond, --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288411; cv=none; d=zohomail.com; s=zohoarc; b=CTznx3iLhMN+/pX4zrc1t55/MDSrsDd1tZNjGxMFDQn+UcSRIAaxzvFrda59bizr5v335X+ho3P8CqMOMYskz7lMWjfNapt2MAoFxoSolOk7AZBNn+FSt5RwEzLHu6GPlSCoIIZJ0Eg2FzwpVv3eOy3ZOPCX7IsJyr2emfOZetM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288411; 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=YH/r0keMcLdV84njaSdaWHfrPxmjV8hvfdDHSpdMn8A=; b=iKqyk8xaAWE/T5nHlBxLURG6ORWcJSWNBa5gGtA/2ojwiS3n33thW39zlIpJyb+q/fNGqytA0TAgb8BeDj+zgb/ma6/T32Qh8Sb0ICxKPfCpZFQgblPg9c/BeyaEJsfb625U0pbnK+BhFNe+hlUOe2fp4qG2GHzpfUGVqas37bo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161228841100436.199870170210374; Tue, 2 Feb 2021 09:53:31 -0800 (PST) Received: from localhost ([::1]:33008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zrl-0002f4-U4 for importer@patchew.org; Tue, 02 Feb 2021 12:53:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlb-0004sk-Cn for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40981) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlY-0008D2-S1 for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:07 -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-462-AOVPclDqN1yW1fhQUiWjgA-1; Tue, 02 Feb 2021 12:47:01 -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 7AA5C106BAE4; Tue, 2 Feb 2021 17:47:00 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB0CE5C1CF; Tue, 2 Feb 2021 17:46:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288024; 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=YH/r0keMcLdV84njaSdaWHfrPxmjV8hvfdDHSpdMn8A=; b=B6CnyJw8i96eRMT2pZQnAtFd5MCQ7/bZEizEXlKeMnN0jPDQ3EHYdmTPsiaDUY8VtQnhbT aCFnbJVNlMOVq25FBupKHrq4bL8p4xGGQm0I8ApQK0q3Ca9aYhtne00uw19P2ExzmUHSe6 SQvT5VWNNC/Q8OIoJbN8wfCv93M6xBY= X-MC-Unique: AOVPclDqN1yW1fhQUiWjgA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 08/14] qapi/introspect.py: create a typed 'Annotated' data strutcure Date: Tue, 2 Feb 2021 12:46:45 -0500 Message-Id: <20210202174651.2274166-9-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Presently, we use a tuple to attach a dict containing annotations (comments and compile-time conditionals) to a tree node. This is undesirable because dicts are difficult to strongly type; promoting it to a real class allows us to name the values and types of the annotations we are expecting. In terms of typing, the Annotated type serves as a generic container where the annotated node's type is preserved, allowing for greater specificity than we'd be able to provide without a generic. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 77 ++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index b82efe16f6e..2b90a52f016 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -13,8 +13,12 @@ from typing import ( Any, Dict, + Generic, + Iterable, List, Optional, + Tuple, + TypeVar, Union, ) =20 @@ -51,15 +55,25 @@ _scalar =3D Union[str, bool, None] _nonscalar =3D Union[Dict[str, _stub], List[_stub]] _value =3D Union[_scalar, _nonscalar] -# TreeValue =3D Union[_value, 'Annotated[_value]'] +TreeValue =3D Union[_value, 'Annotated[_value]'] =20 =20 -def _make_tree(obj, ifcond, comment=3DNone): - extra =3D { - 'if': ifcond, - 'comment': comment, - } - return (obj, extra) +_NodeT =3D TypeVar('_NodeT', bound=3DTreeValue) + + +class Annotated(Generic[_NodeT]): + """ + 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. + """ + # Remove after 3.7 adds @dataclass: + # pylint: disable=3Dtoo-few-public-methods + def __init__(self, value: _NodeT, 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, suppress_first_indent=3DFalse): @@ -67,24 +81,20 @@ def _tree_to_qlit(obj, level=3D0, suppress_first_indent= =3DFalse): def indent(level): return level * 4 * ' ' =20 - if isinstance(obj, tuple): - ifobj, extra =3D obj - ifcond =3D extra.get('if') - comment =3D extra.get('comment') - + if isinstance(obj, Annotated): # NB: _tree_to_qlit is called recursively on the values of a key:v= alue # pair; those values can't be decorated with comments or condition= als. msg =3D "dict values cannot have attached comments or if-condition= als." assert not suppress_first_indent, 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, suppress_first_indent) + if obj.ifcond: + ret +=3D '\n' + gen_endif(obj.ifcond) return ret =20 ret =3D '' @@ -201,7 +211,7 @@ def _use_type(self, typ): =20 @staticmethod def _gen_features(features): - return [_make_tree(f.name, f.ifcond) for f in features] + return [Annotated(f.name, f.ifcond) for f in features] =20 def _gen_tree(self, name, mtype, obj, ifcond, features): comment: Optional[str] =3D None @@ -215,7 +225,7 @@ def _gen_tree(self, name, mtype, obj, ifcond, features): obj['meta-type'] =3D mtype if features: obj['features'] =3D self._gen_features(features) - self._trees.append(_make_tree(obj, ifcond, comment)) + self._trees.append(Annotated(obj, ifcond, comment)) =20 def _gen_member(self, member): obj =3D {'name': member.name, 'type': self._use_type(member.type)} @@ -223,7 +233,7 @@ def _gen_member(self, member): obj['default'] =3D None if member.features: obj['features'] =3D self._gen_features(member.features) - return _make_tree(obj, member.ifcond) + return Annotated(obj, member.ifcond) =20 def _gen_variants(self, tag_name, variants): return {'tag': tag_name, @@ -231,16 +241,17 @@ def _gen_variants(self, tag_name, variants): =20 def _gen_variant(self, variant): obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} - return _make_tree(obj, variant.ifcond) + return Annotated(obj, variant.ifcond) =20 def visit_builtin_type(self, name, info, json_type): self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) =20 def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): - self._gen_tree(name, 'enum', - {'values': [_make_tree(m.name, m.ifcond, None) - for m in members]}, - ifcond, features) + self._gen_tree( + name, 'enum', + {'values': [Annotated(m.name, m.ifcond) for m in members]}, + ifcond, features + ) =20 def visit_array_type(self, name, info, ifcond, element_type): element =3D self._use_type(element_type) @@ -257,12 +268,12 @@ def visit_object_type_flat(self, name, info, ifcond, = features, self._gen_tree(name, 'object', obj, ifcond, features) =20 def visit_alternate_type(self, name, info, ifcond, features, variants): - self._gen_tree(name, 'alternate', - {'members': [ - _make_tree({'type': self._use_type(m.type)}, - m.ifcond, None) - for m in variants.variants]}, - ifcond, features) + self._gen_tree(name, 'alternate', {'members': [ + Annotated({'type': self._use_type(m.type)}, m.ifcond) + for m in variants.variants + ]}, + ifcond, features + ) =20 def visit_command(self, name, info, ifcond, features, arg_type, ret_type, gen, success_response, boxed, --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288384; cv=none; d=zohomail.com; s=zohoarc; b=OIcwwvg9XMsu1PgsY7FmOE1csq4JxqmtPMXdIaqgKFnLG7LuzzAjnI/qQcJLQPwkUuEV+KTUVXyQ8Cr+wmLuwntCnklQeRSp7Spvn/R5EDB3v4SngJkTteamOc7be676gI9jgyaPTQMa0EprEb+TvJin+CNuD1INkZVJqxA746c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288384; 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=JIIHBaH5jer7KgMFZCSjC6Gf07YQuTK0ZAzFHouzS0s=; b=EHHo7DQGLRnmp5083qO1wtSpkRg9grhJ0Nna+U90ixaYZ67hbhzfVjwOxVY2KqvuNvmX/qbO781d6MCiertNPHz7XLzHCcqX9JXUYdKq1faA1kxz98wtCi0sZk/vxCKSZ7UrQH0uam04NeKcn+IaQxLXkRrsssNCH1Z7uBruaPc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288384231539.517849226114; Tue, 2 Feb 2021 09:53:04 -0800 (PST) Received: from localhost ([::1]:59586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zrL-0001uu-49 for importer@patchew.org; Tue, 02 Feb 2021 12:53:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlc-0004vx-O7 for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46179) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlY-0008Cy-Hx for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:08 -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-174-KhTk3VFsNLiENT5k7n7aGw-1; Tue, 02 Feb 2021 12:47:02 -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 5A8E31800D50; Tue, 2 Feb 2021 17:47:01 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F30F5C1CF; Tue, 2 Feb 2021 17:47:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288023; 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=JIIHBaH5jer7KgMFZCSjC6Gf07YQuTK0ZAzFHouzS0s=; b=DcIVq7NiNKwcs+yYW1CiLBURD6lHik2YoWKWIkzGQW9Vg5TJRriJ40gAOh5hbNPAahyJvP FEbNAihk01vI81PTLWwuDXY6AeThWMn4ZLVfhR6P4F/t4zh030/n1mXsU9oxlxuOL2x+p+ 09b4cqcEaqbG1f4nSiK9Ae7YZ4deyPo= X-MC-Unique: KhTk3VFsNLiENT5k7n7aGw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 09/14] qapi/introspect.py: improve _tree_to_qlit error message Date: Tue, 2 Feb 2021 12:46:46 -0500 Message-Id: <20210202174651.2274166-10-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Trivial; make the error message just a pinch more explicit in case we trip this by accident in the future. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 2b90a52f016..c72beeeed27 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -124,7 +124,9 @@ def indent(level): elif isinstance(obj, bool): ret +=3D 'QLIT_QBOOL(%s)' % ('true' if obj else 'false') else: - assert False # not implemented + raise NotImplementedError( + f"type '{type(obj).__name__}' not implemented" + ) if level > 0: ret +=3D ',' return ret --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288651; cv=none; d=zohomail.com; s=zohoarc; b=BTY1WjNdzYdbqp6nqrlYE4HRJ37TjDGSSk+ESed6KBmx+ikewMmheEIiecxxPYV06WCO4oV9qZmHzUPpnITCSMYz/LE7JyhGqoEtyRBcQY8DsbTFTWAF9XVYrEOUnE2w0VPWhx8mFBtQ/p5hlFlH/bbnaFccjsdKzJivF26qkPY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288651; 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=96PaxVN1+MOOFep/lXNZxqncK3TVoXRtBdD76kel934=; b=QY2lzLHiCQikiwtz7ru1NnoHlc8jq+k11rLBAxblqKzwY4qWYmpkrkLDb401Z+3F0Sqr+znRsKYfNaf93Jy1/8ts0HA1LL1vVlQfxx7Ww2q6pnJqhldXinvcsFNYY0wr6zzEGHwIypin3eoTFyjGwcXk/hJLGYFfb/53DKC3YXg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288651180890.0620226995193; Tue, 2 Feb 2021 09:57:31 -0800 (PST) Received: from localhost ([::1]:41580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zve-00072i-4R for importer@patchew.org; Tue, 02 Feb 2021 12:57:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlb-0004tQ-O5 for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20060) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlZ-0008DQ-Jt for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:07 -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-497-ZK7X56dtPNKlHbK56pwOug-1; Tue, 02 Feb 2021 12:47:03 -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 3F000107ACE3; Tue, 2 Feb 2021 17:47:02 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 822D65C1CF; Tue, 2 Feb 2021 17:47:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288024; 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=96PaxVN1+MOOFep/lXNZxqncK3TVoXRtBdD76kel934=; b=EWERNjDPLJTyxA3lzF2SqbuY+iZT/sHG1dbYdGBfKHhNF6GSRtIPWCufjHTxuL5ohmS+dK +FULDiG7XUl5hPqjyDTgybH90fdKXm7x6fr49YkPqiBiORH9SWFQIcXzcLwFgMC72Xtrw0 gkTmvkXJlGhDuUbc1Sp80IIvZXj3+AQ= X-MC-Unique: ZK7X56dtPNKlHbK56pwOug-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 10/14] qapi/introspect.py: improve readability of _tree_to_qlit Date: Tue, 2 Feb 2021 12:46:47 -0500 Message-Id: <20210202174651.2274166-11-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Subjective, but I find getting rid of the comprehensions helps. Also, divide the sections into scalar and non-scalar sections, and remove old-style string formatting. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index c72beeeed27..60ec326d2c7 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -89,7 +89,7 @@ def indent(level): =20 ret =3D '' if obj.comment: - ret +=3D indent(level) + '/* %s */\n' % obj.comment + ret +=3D indent(level) + f"/* {obj.comment} */\n" if obj.ifcond: ret +=3D gen_if(obj.ifcond) ret +=3D _tree_to_qlit(obj.value, level, suppress_first_indent) @@ -100,33 +100,36 @@ def indent(level): ret =3D '' if not suppress_first_indent: 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, suppress_first_indent=3DTr= ue) + ) + ret +=3D indent(level + 1) + '{}\n' ret +=3D indent(level) + '}))' - elif isinstance(obj, bool): - ret +=3D 'QLIT_QBOOL(%s)' % ('true' if obj else 'false') else: raise NotImplementedError( f"type '{type(obj).__name__}' not implemented" ) + if level > 0: ret +=3D ',' return ret --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288631; cv=none; d=zohomail.com; s=zohoarc; b=FZFnHy00MePoEef0NYqEon+ktGzinPZyhIhBwqzNl9okBXROdtjzOt4FkLNwDYtr3/qV1OHXXnS7+eCO/4Q1BtS+wXnkPY1U2+6y9mgTkWS0GWrTVYt1ob4rzBp/NoxfPvystJHK+Yst87so5qmwet1o0JFskpBnoyPOSKhhGgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288631; 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=Ba6lItiflmZcaPCPB5SEdKY07Sr3A9ytgApkZOKRKnE=; b=ENjPXhj0HdCj+su2JPe4H4arsuvyXSREPmSLz9oSzxh48blneabnSBcY8brQS5cuonymPZe8UZ62ia7PQQAemf/UTtXjFA7sfZQVbu063iNScV3sifTsl70HCewgen+mwy74JXmmpfnd28iXfO+oZK5OJZRpMT1awhHlsmUNttI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288631662643.4913765732152; Tue, 2 Feb 2021 09:57:11 -0800 (PST) Received: from localhost ([::1]:39882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zvK-0006BW-Eo for importer@patchew.org; Tue, 02 Feb 2021 12:57:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43942) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zle-0004zq-5V for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56374) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlb-0008EW-Jk for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:09 -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-220-7MGDTRFQNkKgkJz4wzudyQ-1; Tue, 02 Feb 2021 12:47:04 -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 246DB1800D50; Tue, 2 Feb 2021 17:47:03 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6640C5C22B; Tue, 2 Feb 2021 17:47:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288026; 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=Ba6lItiflmZcaPCPB5SEdKY07Sr3A9ytgApkZOKRKnE=; b=SZqV/zn8qRb1RJKemZgIRhCJ/3Ry3bMKfC5jnCkRIPafnaDlourbyM+lkBh4R8uhChm8K9 LTWjrnckuz/OFGkFWqR63ihu5bWUYQ/AyUH36kkhg3/s9PZB9GrT/lR51sV3Qa9zJID6j5 uzZbKi51sNEBOPE5JXG+N3H+//hAOsU= X-MC-Unique: 7MGDTRFQNkKgkJz4wzudyQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 11/14] qapi/introspect.py: add type hint annotations Date: Tue, 2 Feb 2021 12:46:48 -0500 Message-Id: <20210202174651.2274166-12-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow --- scripts/qapi/introspect.py | 115 ++++++++++++++++++++++++++----------- scripts/qapi/mypy.ini | 5 -- scripts/qapi/schema.py | 2 +- 3 files changed, 82 insertions(+), 40 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 60ec326d2c7..b7f2a6cf260 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -30,10 +30,19 @@ ) from .gen import QAPISchemaMonolithicCVisitor from .schema import ( + QAPISchema, QAPISchemaArrayType, QAPISchemaBuiltinType, + QAPISchemaEntity, + QAPISchemaEnumMember, + QAPISchemaFeature, + QAPISchemaObjectType, + QAPISchemaObjectTypeMember, QAPISchemaType, + QAPISchemaVariant, + QAPISchemaVariants, ) +from .source import QAPISourceInfo =20 =20 # This module constructs a tree data structure that is used to @@ -57,6 +66,8 @@ _value =3D Union[_scalar, _nonscalar] TreeValue =3D Union[_value, 'Annotated[_value]'] =20 +# This is a (strict) alias for an arbitrary object non-scalar, as above: +_DObject =3D Dict[str, object] =20 _NodeT =3D TypeVar('_NodeT', bound=3DTreeValue) =20 @@ -76,9 +87,11 @@ def __init__(self, value: _NodeT, ifcond: Iterable[str], self.ifcond: Tuple[str, ...] =3D tuple(ifcond) =20 =20 -def _tree_to_qlit(obj, level=3D0, suppress_first_indent=3DFalse): +def _tree_to_qlit(obj: TreeValue, + level: int =3D 0, + suppress_first_indent: bool =3D False) -> str: =20 - def indent(level): + def indent(level: int) -> str: return level * 4 * ' ' =20 if isinstance(obj, Annotated): @@ -135,21 +148,21 @@ def indent(level): return ret =20 =20 -def to_c_string(string): +def to_c_string(string: str) -> str: return '"' + string.replace('\\', r'\\').replace('"', r'\"') + '"' =20 =20 class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor): =20 - def __init__(self, prefix, unmask): + def __init__(self, prefix: str, unmask: bool): super().__init__( prefix, 'qapi-introspect', ' * QAPI/QMP schema introspection', __doc__) self._unmask =3D unmask - self._schema =3D None - self._trees =3D [] - self._used_types =3D [] - self._name_map =3D {} + self._schema: Optional[QAPISchema] =3D None + self._trees: List[Annotated[_DObject]] =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" @@ -157,10 +170,10 @@ def __init__(self, prefix, unmask): ''', prefix=3Dprefix)) =20 - def visit_begin(self, schema): + def visit_begin(self, schema: QAPISchema) -> None: self._schema =3D schema =20 - def visit_end(self): + def visit_end(self) -> None: # visit the types that are actually used for typ in self._used_types: typ.visit(self) @@ -182,18 +195,18 @@ def visit_end(self): self._used_types =3D [] self._name_map =3D {} =20 - def visit_needed(self, entity): + def visit_needed(self, entity: QAPISchemaEntity) -> bool: # Ignore types on first pass; visit_end() will pick up used types return not isinstance(entity, QAPISchemaType) =20 - def _name(self, name): + def _name(self, name: str) -> str: if self._unmask: return name if name not in self._name_map: self._name_map[name] =3D '%d' % len(self._name_map) return self._name_map[name] =20 - def _use_type(self, typ): + def _use_type(self, typ: QAPISchemaType) -> str: assert self._schema is not None =20 # Map the various integer types to plain int @@ -215,10 +228,13 @@ def _use_type(self, typ): return self._name(typ.name) =20 @staticmethod - def _gen_features(features): + def _gen_features(features: List[QAPISchemaFeature] + ) -> List[Annotated[str]]: return [Annotated(f.name, f.ifcond) for f in features] =20 - def _gen_tree(self, name, mtype, obj, ifcond, features): + def _gen_tree(self, name: str, mtype: str, obj: _DObject, + ifcond: List[str], + features: Optional[List[QAPISchemaFeature]]) -> None: comment: Optional[str] =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: @@ -232,47 +248,67 @@ def _gen_tree(self, name, mtype, obj, ifcond, feature= s): obj['features'] =3D self._gen_features(features) self._trees.append(Annotated(obj, ifcond, comment)) =20 - def _gen_member(self, member): - obj =3D {'name': member.name, 'type': self._use_type(member.type)} + def _gen_member(self, member: QAPISchemaObjectTypeMember + ) -> Annotated[_DObject]: + obj: _DObject =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_variants(self, tag_name, variants): + def _gen_variants(self, tag_name: str, + variants: List[QAPISchemaVariant]) -> _DObject: return {'tag': tag_name, 'variants': [self._gen_variant(v) for v in variants]} =20 - def _gen_variant(self, variant): - obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} + def _gen_variant(self, variant: QAPISchemaVariant) -> Annotated[_DObje= ct]: + obj: _DObject =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: List[str], features: List[QAPISchemaFeatur= e], + 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: List[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: List[str], + features: List[QAPISchemaFeature], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> = None: + obj: _DObject =3D {'members': [self._gen_member(m) for m in member= s]} if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) =20 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: List[str], + features: List[QAPISchemaFeature], + variants: QAPISchemaVariants) -> None: self._gen_tree(name, 'alternate', {'members': [ Annotated({'type': self._use_type(m.type)}, m.ifcond) for m in variants.variants @@ -280,27 +316,38 @@ def visit_alternate_type(self, name, info, ifcond, fe= atures, variants): ifcond, features ) =20 - def visit_command(self, name, info, ifcond, features, - arg_type, ret_type, gen, success_response, boxed, - allow_oob, allow_preconfig, coroutine): + def visit_command(self, name: str, info: Optional[QAPISourceInfo], + ifcond: List[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: _DObject =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: List[str], features: List[QAPISchemaFeature], + arg_type: Optional[QAPISchemaObjectType], + boxed: bool) -> None: assert self._schema is not None + arg_type =3D arg_type or self._schema.the_empty_object_type self._gen_tree(name, 'event', {'arg-type': self._use_type(arg_type= )}, ifcond, features) =20 =20 -def gen_introspect(schema, output_dir, prefix, opt_unmask): +def gen_introspect(schema: QAPISchema, output_dir: str, prefix: str, + opt_unmask: bool) -> None: vis =3D QAPISchemaGenIntrospectVisitor(prefix, opt_unmask) schema.visit(vis) vis.write(output_dir) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 04bd5db5278..0a000d58b37 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -13,11 +13,6 @@ disallow_untyped_defs =3D False disallow_incomplete_defs =3D False check_untyped_defs =3D False =20 -[mypy-qapi.introspect] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False - [mypy-qapi.parser] disallow_untyped_defs =3D False disallow_incomplete_defs =3D False diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 353e8020a27..ff16578f6de 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -28,7 +28,7 @@ class QAPISchemaEntity: meta: Optional[str] =3D None =20 - def __init__(self, name, info, doc, ifcond=3DNone, features=3DNone): + def __init__(self, name: str, info, doc, ifcond=3DNone, features=3DNon= e): assert name is None or isinstance(name, str) for f in features or []: assert isinstance(f, QAPISchemaFeature) --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288627; cv=none; d=zohomail.com; s=zohoarc; b=l5BVyu5bL/zqYrmdX3X1K0a8a28dTvx/nVg3Oy0QVe2wHSVwhdan3KH8IejNQ9c//5OzrUwtSONFHESpgzab5fOvMOVrsD3h+nwotdBZnYWh1sRTcaE+7swYRas/GHIA8HZOVjEQpsC0Ucho3b7UyWWCc7avQoinNHspeJKYvPI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288627; 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=igXdpddoN154z3gheiDaIM2pkxAGZEJVxhZzCsNwTjc=; b=c2F4pk/Dzx23KhNGITgeuJ84N5ePnXFaUa5f+evICu5voLWc186atCe+3fzHOk8+9hvKJ/HVijxZxo6BZNwT7Nb+o6cxRJnCxG/XBv6LGV2w7o7FlW9XRECF6+SeWK1OjWwJYii6omeQWwEURrW3hXSiqxNbaWg8rITRmXbTFFo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288627245162.98883585933345; Tue, 2 Feb 2021 09:57:07 -0800 (PST) Received: from localhost ([::1]:39506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zvG-0005wV-02 for importer@patchew.org; Tue, 02 Feb 2021 12:57:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zle-00051U-O0 for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59316) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zlc-0008El-Kl for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47: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-563-ZaCI4Ga2P5KuNzYMJVPAcQ-1; Tue, 02 Feb 2021 12:47:05 -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 0A3AC106BAED; Tue, 2 Feb 2021 17:47:04 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4ECA65C1CF; Tue, 2 Feb 2021 17:47:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288028; 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=igXdpddoN154z3gheiDaIM2pkxAGZEJVxhZzCsNwTjc=; b=VRJHWMitfxGE+eV00yoCAuyWwgw95OGQbmGlYik4VA2x40ajRNY509mMl8l6iBRkuOoXp7 lWQHO1utmeETTW7qncMD5azXj5KticNBUdf85T3KogfgpZQYm0BYmZW0gK4m4ph4hhJDJz ElVQo31ZmUFdPg63Q9iPJkDTQi4Ncgg= X-MC-Unique: ZaCI4Ga2P5KuNzYMJVPAcQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 12/14] qapi/introspect.py: add introspect.json dummy types Date: Tue, 2 Feb 2021 12:46:49 -0500 Message-Id: <20210202174651.2274166-13-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add some aliases that declare intent for some of the "dictly-typed" objects we pass around in introspect.py. Signed-off-by: John Snow --- This patch is optional, it can be dropped if desired. It is purely for the sake of demonstrating what the _DObject was meant to convey: a Python Dict that represents some JSON Object. It does not add any type safety in and of itself, but does have some (light) annotational benefit. In this case, it's usually a specific data structure from the QAPI Schema we are referencing, but do not have "compile-time" access to in Python. These are loosely typed and don't bother reproducing the exact structure of the real types. Python 3.6 does not have support for TypedDict structures, so this is as good as we can do without involving a third-party library (e.g. Pydantic), in which we might be able to say: class SchemaMetaType(str, enum.Enum): BUILTIN =3D "builtin" ENUM =3D "enum" ARRAY =3D "array" OBJECT =3D "object" ALTERNATE =3D "alternate" COMMAND =3D "command" EVENT =3D "event" class SchemaInfo(pydantic.BaseModel): name: str meta-type: SchemaMetaType features: Optional[List[str]] data: Union[SchemaInfoBuiltin, SchemaInfoEnum, SchemaInfoArray, SchemaInfoObject, SchemaInfoAlternate, SchemaInfoCommand, SchemaInfoEvent] However, the cost of reproducing and keeping these structure definitions in-sync between the user-defined portion of the schema and the code generator is likely not worth doing any such thing. However, it does illustrate an interesting dependency the generator has on the user-defined schema itself in terms of types. So, I settled on using some light types that suggest the form of the object instead of enforcing the form. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 49 ++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index b7f2a6cf260..eb5d34cdb42 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -66,8 +66,15 @@ _value =3D Union[_scalar, _nonscalar] TreeValue =3D Union[_value, 'Annotated[_value]'] =20 -# This is a (strict) alias for an arbitrary object non-scalar, as above: -_DObject =3D Dict[str, object] +# These types are based on structures defined in QEMU's schema, so we lack +# precise types for them here. Python 3.6 does not offer TypedDict constru= cts, +# so they are loosely 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 _NodeT =3D TypeVar('_NodeT', bound=3DTreeValue) =20 @@ -160,7 +167,7 @@ def __init__(self, prefix: str, unmask: bool): ' * QAPI/QMP schema introspection', __doc__) self._unmask =3D unmask self._schema: Optional[QAPISchema] =3D None - self._trees: List[Annotated[_DObject]] =3D [] + self._trees: List[Annotated[SchemaInfo]] =3D [] self._used_types: List[QAPISchemaType] =3D [] self._name_map: Dict[str, str] =3D {} self._genc.add(mcgen(''' @@ -232,9 +239,18 @@ 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: str, mtype: str, obj: _DObject, + def _gen_tree(self, name: str, mtype: str, obj: Dict[str, object], ifcond: List[str], features: Optional[List[QAPISchemaFeature]]) -> None: + """ + Build and append a SchemaInfo object to self._trees. + + :param name: The entity's name. + :param mtype: The entity's meta-type. + :param obj: Additional entity fields, as appropriate for the meta-= type. + :param ifcond: List of conditionals that apply to this entire enti= ty. + :param features: Optional features field for SchemaInfo. + """ comment: Optional[str] =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: @@ -249,8 +265,8 @@ def _gen_tree(self, name: str, mtype: str, obj: _DObjec= t, self._trees.append(Annotated(obj, ifcond, comment)) =20 def _gen_member(self, member: QAPISchemaObjectTypeMember - ) -> Annotated[_DObject]: - obj: _DObject =3D { + ) -> Annotated[SchemaInfoObjectMember]: + obj: SchemaInfoObjectMember =3D { 'name': member.name, 'type': self._use_type(member.type) } @@ -260,13 +276,9 @@ def _gen_member(self, member: QAPISchemaObjectTypeMemb= er obj['features'] =3D self._gen_features(member.features) return Annotated(obj, member.ifcond) =20 - def _gen_variants(self, tag_name: str, - variants: List[QAPISchemaVariant]) -> _DObject: - return {'tag': tag_name, - 'variants': [self._gen_variant(v) for v in variants]} - - def _gen_variant(self, variant: QAPISchemaVariant) -> Annotated[_DObje= ct]: - obj: _DObject =3D { + def _gen_variant(self, variant: QAPISchemaVariant + ) -> Annotated[SchemaInfoObjectVariant]: + obj: SchemaInfoObjectVariant =3D { 'case': variant.name, 'type': self._use_type(variant.type) } @@ -298,11 +310,12 @@ def visit_object_type_flat(self, name: str, info: Opt= ional[QAPISourceInfo], features: List[QAPISchemaFeature], members: List[QAPISchemaObjectTypeMember], variants: Optional[QAPISchemaVariants]) -> = None: - obj: _DObject =3D {'members': [self._gen_member(m) for m in member= s]} + obj: SchemaInfoObject =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: str, info: Optional[QAPISourceInf= o], @@ -327,7 +340,7 @@ def visit_command(self, name: str, info: Optional[QAPIS= ourceInfo], =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: _DObject =3D { + obj: SchemaInfoCommand =3D { 'arg-type': self._use_type(arg_type), 'ret-type': self._use_type(ret_type) } --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288858; cv=none; d=zohomail.com; s=zohoarc; b=TyExTASr8/felDaeGyIm17ovI8P2Ad58uly4bPvrMg6fuXLa3JefKm0zsTEkNv0LaZRTS37qlRikzWeGTaO9WNHXXr/4RW1jPyO3faOUKPUn5trt1shty+P5hKksJ168QblydsFAFUxN6RrmdRSZrEel8ByOoSDh7tlS9OJKkqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288858; 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=GftNvl9QqS+qriNjqxWY8yBmQfUNiK84j48aT3ZfqnI=; b=YubkZfSkBxlwtbgvBAPy1seMJjl2EgJcDjHQgNH672ZfR2UcglEVt3dvbJbt1RJap/0hOkPkvzTa/GlSLN4DKyN1ZWvMYAnWU7j3WVMwwZtt0ZNilMLt/7rc0FmKmi+JjsrXNlJzqSQFUeQaL7yEGubxQwOBZonO89XZvz9iP8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161228885875584.04588577082484; Tue, 2 Feb 2021 10:00:58 -0800 (PST) Received: from localhost ([::1]:48154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6zyv-0001Ux-T1 for importer@patchew.org; Tue, 02 Feb 2021 13:00:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlf-00053t-Ml for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:34565) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zle-0008Fp-0Y for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:11 -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-372-RkRTVukKPcSMV6d-RYSrKg-1; Tue, 02 Feb 2021 12:47:06 -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 E1374107ACE3; Tue, 2 Feb 2021 17:47:04 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 312A75C1CF; Tue, 2 Feb 2021 17:47:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288029; 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=GftNvl9QqS+qriNjqxWY8yBmQfUNiK84j48aT3ZfqnI=; b=bpUwPVNvGIjZBrvjqkd7mp2+mpT/oUkGZG3X01fbyLr25wEEGdJ77nXRl0SWMGHmNlLES7 9UaO8iwDAhAUo+iNr5o5flUUIHUfLTV40sKW6n/8+5wlcaUg/PjVCqMi1wW+6Lqc87aOYd ffI6iTB07XDn7GfwzhcLbWoGBOL03Es= X-MC-Unique: RkRTVukKPcSMV6d-RYSrKg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 13/14] qapi/introspect.py: Add docstring to _tree_to_qlit Date: Tue, 2 Feb 2021 12:46:50 -0500 Message-Id: <20210202174651.2274166-14-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow --- scripts/qapi/introspect.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index eb5d34cdb42..3e59caf7d4d 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -97,6 +97,13 @@ def __init__(self, value: _NodeT, ifcond: Iterable[str], def _tree_to_qlit(obj: TreeValue, level: int =3D 0, suppress_first_indent: bool =3D False) -> str: + """ + Convert the type tree into a QLIT C string, recursively. + + :param obj: The value to convert. + :param level: The indentation level for this particular value. + :param suppress_first_indent: True for dict value children. + """ =20 def indent(level: int) -> str: return level * 4 * ' ' --=20 2.29.2 From nobody Tue Nov 18 18:19:10 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1612288941; cv=none; d=zohomail.com; s=zohoarc; b=K3zhqIKclCKT0yd1sqR7eMZL9wy8/ZHKGjjMwQYvM/dQjI87pESxGAJ15MYSU4yF3cccM4KG6tlY2UE8sHnA+RZ7OtyovcrNy4dVFj00KaXrM2sVU/EVGf5iay1X4POJYL4M8CAaFdf6WJUHXW73tFFoT5FXWfVIqK4Qxz+oNWY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612288941; 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=Wc+/HVD+JUT3BB8ApyOe2tjoujvknFEE3Ny6WjFYXjw=; b=MXbd3pv+CHIOdXepzWJOgnhhhdEzPXs4FU9YoSn58jDauBCF1doBOdmWvnGevOzo4JIbvVu7xSDWlNPxVh54PfMOpK4bJLYCdF5Gwi5F/8l7ilUDt/+GJn409Sa0NDbkBqysG0B3BWbVav1AjWS1Vmz/k/eBHuftgmd0PTwYxqg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1612288941721985.9072414357918; Tue, 2 Feb 2021 10:02:21 -0800 (PST) Received: from localhost ([::1]:50182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l700J-0002Q2-Ma for importer@patchew.org; Tue, 02 Feb 2021 13:02:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6zlf-00052n-8V for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59264) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1l6zld-0008FO-I6 for qemu-devel@nongnu.org; Tue, 02 Feb 2021 12:47: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-222-CD_LTG1dN1KHfyJklr_FYw-1; Tue, 02 Feb 2021 12:47:07 -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 47915107ACFC; Tue, 2 Feb 2021 17:47:06 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-247.rdu2.redhat.com [10.10.112.247]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1454A5C1CF; Tue, 2 Feb 2021 17:47:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612288028; 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=Wc+/HVD+JUT3BB8ApyOe2tjoujvknFEE3Ny6WjFYXjw=; b=Z30LGmFm0U/1EyJcdkZj0GIMq9GOhqvbeYqURq2ph9zY+hg2v+HgvTV7QnmyEX19TRISJZ /oN44tYfQ7/2mObkhgybfpsWJKRmWrfq2WMJs645vTQfJblp0hlDQF8WqP8zeFtCibeeqy m6Q/r9kp3da2qWqVFVStvRQyAbO5FGc= X-MC-Unique: CD_LTG1dN1KHfyJklr_FYw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v4 14/14] qapi/introspect.py: Update copyright and authors list Date: Tue, 2 Feb 2021 12:46:51 -0500 Message-Id: <20210202174651.2274166-15-jsnow@redhat.com> In-Reply-To: <20210202174651.2274166-1-jsnow@redhat.com> References: <20210202174651.2274166-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.386, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow --- scripts/qapi/introspect.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 3e59caf7d4d..df2bb50df32 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-2020 Red Hat, Inc. =20 Authors: Markus Armbruster + John Snow =20 This work is licensed under the terms of the GNU GPL, version 2. See the COPYING file in the top-level directory. --=20 2.29.2