From nobody Tue Nov 18 05:54:45 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=1608170163; cv=none; d=zohomail.com; s=zohoarc; b=k/0W4F0iwbY1DAn5caDYJDgNshjj8ZgAOLaozOyfZLP4Wn9EHqLeKyFL3dkKjac0lh8VjtHxh3j+qyK5zODushveUKOG72Xtxv2piTn5v1VlIO2btUZiXwKBuJnUQcxos7G/dwh9OSlNHt9v/5U7KsrB555H3zsaflZUex0+pgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170163; 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=xWHrqcMBEOU3yRruC4x1dukbTB5q97mV7cjAg3LUICI=; b=nzWqP4KzSrmcEBhqtnTu+dzlCEp8gGrVCgZHmZQD42/lW//7T2udahM3ypMfskQYD3nPohQZAvPehxpVuUZlh6WqAo+t6ktjlw5dXwrrC86ox6eRHGJtK0DDT/n+sgDMx8XrZ5+wbh4tmwGRYFga7myu81wOn6e5brw5mcDG+Rs= 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 16081701636951019.1333223885232; Wed, 16 Dec 2020 17:56:03 -0800 (PST) Received: from localhost ([::1]:57786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpiWQ-0005Tc-IF for importer@patchew.org; Wed, 16 Dec 2020 20:56:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUK-0003rR-Tu for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:52 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUI-0006I5-98 for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:52 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-47-pfCUZ9_hM0arisbLAZOKrQ-1; Wed, 16 Dec 2020 20:53:46 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B674D1005513 for ; Thu, 17 Dec 2020 01:53:45 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18CA260CC4; Thu, 17 Dec 2020 01:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170028; 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=xWHrqcMBEOU3yRruC4x1dukbTB5q97mV7cjAg3LUICI=; b=dKkQLdvlTXBKdUVQjfPUvP5GkW62m0wXN9BjHKMb9LsdFP4Y99V/Kr56dNNLIwcXiekN8l PP1/qX3td5zwjC9gLDj4m6QB5ut3PtBzQ8J7mzAyYQVPCykQNyPHe5O3kRC8U2WdQ5E85Z LZZpc3CDOkPXUoPY2LalsOG7PC2TYbA= X-MC-Unique: pfCUZ9_hM0arisbLAZOKrQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 01/13] qapi/introspect.py: assert schema is not None Date: Wed, 16 Dec 2020 20:53:31 -0500 Message-Id: <20201217015343.196279-2-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170227; cv=none; d=zohomail.com; s=zohoarc; b=KSm7ovjltVLeipoAvQ20LN+X30HY87Fgra2kTdOe1Icmy5kNz0quHrzyKwU/cm2QApCmaGQ9MQMBrXP3iE/M0w4TpkzJhn6OOeghhKO1EBIfDHLj64nFLT2cb2WVHqi3x4PADdqSqg9vPe2vrLc9+OPLnHkFuY9DjvBCBTdvsCE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170227; 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=xGFmdJ3x6IPQiTvgIjvXL530rozPOQdchBURc2F7S3A=; b=AhLLGI/ahmbstNyjoDc4ANlVScoYqtYKtmdJAnR9ATjRTMY9eV9CvieYc4XcFho5kUsNBb4qhOjolkyiKyoLUFImUbabxWJcD1XMeZ46QwRq1IZ9LSho8d0yGkRZuQ8nXupLvFyhCX+NqlBvLg4QtzH44wb79lOkU3zwqWqXvEk= 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 1608170227075565.4596082968102; Wed, 16 Dec 2020 17:57:07 -0800 (PST) Received: from localhost ([::1]:60266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpiXS-0006b7-03 for importer@patchew.org; Wed, 16 Dec 2020 20:57:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUL-0003su-Nr for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:53 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49619) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUI-0006ID-IP for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-311-JT_rHQ0ANpiXLky__8K1Pg-1; Wed, 16 Dec 2020 20:53:47 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B416801FC4 for ; Thu, 17 Dec 2020 01:53:46 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDECB60CC4; Thu, 17 Dec 2020 01:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170030; 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=xGFmdJ3x6IPQiTvgIjvXL530rozPOQdchBURc2F7S3A=; b=SMlKtprFZCPYPchHhyctsE8Z1XwLctq4KSCE5sqbWAF4YJcfFe1bjBTwoRqVnF9AzpLutj qdM1vvhfay0jm7vLHtK5DflVssn5AKNAfAA0QBP6gZMUs739ifC3svDehR6c5Z4SeJtxah BvjvWeGe5JomnmoU6jhiid5n7ZUfuTk= X-MC-Unique: JT_rHQ0ANpiXLky__8K1Pg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 02/13] qapi/introspect.py: use _make_tree for features nodes Date: Wed, 16 Dec 2020 20:53:32 -0500 Message-Id: <20201217015343.196279-3-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170299; cv=none; d=zohomail.com; s=zohoarc; b=a5j2Q2IPXRTtR8wEN2F7c+Dc3R0xJvEZbK0yJzXKxVVuzLPJOeYBUbf0q9wzAA1Ffh3k7VA3zgop86oATf3qqmBHChSmHlmkyGXPct9idGy+QVMNJksYrgEwklYlU//fskhJvvd1BpjGKcb2NxGzC5Al37V01ljWiZgGQEgHaZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170299; 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=Sq4/0518jKSdKj+rlnLVqOcDGihKjaqO/ZwJhj40Yx0=; b=MFSJ09QvtEdhMdy48CjpOKpP8+xleUlYGIJ+Tm4/sNMbYvN7rUs56X3+r/MtF+0Cp6kHwSkpabKrzo4qaaeBdIX+5DLGhgXBoCw9AMA8m0qnPSNFNM2ZSK8L4efvVacAs9QbeXGppr9nlUQ1FS06tjELEBBpUFPW5G1BCAiSNOw= 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 1608170299072895.7556982926654; Wed, 16 Dec 2020 17:58:19 -0800 (PST) Received: from localhost ([::1]:37220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpiYb-0000Hj-PK for importer@patchew.org; Wed, 16 Dec 2020 20:58:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52248) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUM-0003tI-1I for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28210) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUJ-0006IM-P3 for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-197-tgvzKQnVPguXMLjY805sww-1; Wed, 16 Dec 2020 20:53:48 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DCF810054FF for ; Thu, 17 Dec 2020 01:53:47 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD30560CDE; Thu, 17 Dec 2020 01:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170031; 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=Sq4/0518jKSdKj+rlnLVqOcDGihKjaqO/ZwJhj40Yx0=; b=UMi43HbKqgC32bBxyKZqoXHEhWCgFNY9wWOB7+Zz+0fM/Qk78lFawh7qOzU6c2BBSnQrZE ksF9SfAZXymDvzefvzHwbnG1AFvaVOjMbANuu+WfSUQrFINPuzlsgxj3cl4DnCKO3T4Vu9 G+KFjsZcK3xBp8GjU3OL/o7LuNnC94M= X-MC-Unique: tgvzKQnVPguXMLjY805sww-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 03/13] qapi/introspect.py: add _gen_features helper Date: Wed, 16 Dec 2020 20:53:33 -0500 Message-Id: <20201217015343.196279-4-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170304; cv=none; d=zohomail.com; s=zohoarc; b=aac2tcndIKJKRquPf6GGJGfs7oRa64HIXcqlcVaqDVMsZ7RokHMIeYFFVdoYbZVbM4ouBp1y6R/czOhHGK1n28i3J5PqRz96Vx8wyHiN4YaFQyN20gxyKQKwDkIkGogmdIAw+eqvCFGbmPh3n/Rxup78x86+SaNOUpxLdW2pYSw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170304; 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=vR6/tBT6aYwaD0uN4EPKsDga6xc6SKZ5E5FRcjytRzs=; b=mk+6zTHuiyCKEBv30/4ObimXQarlE4MF+0zdOxX5zsFr2LENE45apbGMceeGCLFyEBMJsP4jZAeei4pZBfZTDTqp6VK7XjDCHTQNqyISoXFTeVQ28ZFR+QaY393YpLHvZB4tOymnZ5zi/2wkTyJAl2GqKblnR6IsV6tWojU0Hug= 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 1608170304706289.5808030525942; Wed, 16 Dec 2020 17:58:24 -0800 (PST) Received: from localhost ([::1]:37356 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpiYh-0000LT-MM for importer@patchew.org; Wed, 16 Dec 2020 20:58:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52274) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUN-0003v4-C1 for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59119) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUJ-0006II-Mb for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:55 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-358-6S8GaFeEMoi1SZhZXGoonQ-1; Wed, 16 Dec 2020 20:53:49 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E2411014E72 for ; Thu, 17 Dec 2020 01:53:48 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8495060CC4; Thu, 17 Dec 2020 01:53:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170030; 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=vR6/tBT6aYwaD0uN4EPKsDga6xc6SKZ5E5FRcjytRzs=; b=baj527gbdY4fhcpiQwcx3o8XdcOzmI9EfHrG+q0W8887jOkDpn2hRqdEZI4/eBZjLeYtzF EeKjNuZDzmTyBsWlWmZjK1ppJogIvvmiZbMjuCwpDYSpTZ3EgmGL0z9zF+XpJODNZz/53u DpiqzOW5DVoYd7I/IDGpeTWYQiVgxEo= X-MC-Unique: 6S8GaFeEMoi1SZhZXGoonQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 04/13] qapi/introspect.py: guard against ifcond/comment misuse Date: Wed, 16 Dec 2020 20:53:34 -0500 Message-Id: <20201217015343.196279-5-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170515; cv=none; d=zohomail.com; s=zohoarc; b=kEoSzkCglxvGPKQ7TP+g5+ibP8sZjp611CYx+XzlWOt9kHdGYl3q7TGvns8IkgIpNsKe7N32yICJpPEnP9SoLUHUlTqNFJHhyKWoYvEdszS60Ta6hnC9kbQxn/iwa8jC4t58vhBMuKjKqnL4t3AaA32CA3xfTeAez4dnsB9fq+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170515; 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=0ixpvTd8FZJbiAQUsBu1xZk5KVrQafEP1UMA7RxAVd8=; b=m6zrqUllh1afXqmuswGXvpgKldwS35ij0K0lF/IlWaBxoFuCDrzXFxsa+v/p9TmQQ7h8p5MuZG1j4cMVGBRfkKdWY7q/dGeRntpxNbLv+xYGHwRgnWmUKHOuMIKgIvjYTVe4alXBeMHBhRwiQ8yULuYkl6INyh7cy/fHmJqJBkk= 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 1608170515776956.9855882165847; Wed, 16 Dec 2020 18:01:55 -0800 (PST) Received: from localhost ([::1]:44168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpic6-0003Vo-KX for importer@patchew.org; Wed, 16 Dec 2020 21:01:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUM-0003tR-75 for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31064) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUK-0006IT-MQ for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:53 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-392-oaMwkQ4_MkCpftsayDNkyQ-1; Wed, 16 Dec 2020 20:53:49 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F360E801AA3 for ; Thu, 17 Dec 2020 01:53:48 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5662760CC4; Thu, 17 Dec 2020 01:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170031; 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=0ixpvTd8FZJbiAQUsBu1xZk5KVrQafEP1UMA7RxAVd8=; b=BrZ9rL0AM4lLoUePZTCWU4z3E6Pw3wOvp2XKpJigVHAErCeDmZzGQ0uTh8EaL/cf1MpzB8 ypbLscknllmUfn0fywAxGxU8ma5ZLd0pWAfOuc9Jc2SFbw0qchP/lp2H7zubaa/ZrFvEV1 CdDXHKNtmmC/eL6hNPioKmyjlDOJDdI= X-MC-Unique: oaMwkQ4_MkCpftsayDNkyQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 05/13] qapi/introspect.py: Unify return type of _make_tree() Date: Wed, 16 Dec 2020 20:53:35 -0500 Message-Id: <20201217015343.196279-6-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170357; cv=none; d=zohomail.com; s=zohoarc; b=WpG2mBvjceWJq/0hihGsVGyv8e4oHJkN/7CsrnGrq80jK77TPgiLva7U6DN0lNfY2Ii5JEsSNZfjFxhU0noxJOl1HNcJA7FZERtHQo5S/pGnif6unWz1M5/sP3XoqbzAgfPgDkXtyqxIYRk4K9pn1s50ghxMd75PuQJwRVoX7+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170357; 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=34OLcZSH8Jc6cjj7YTdc+clNV92TrTbEqumigufgBKg=; b=c/XZTRYJ4frbqCyTVc45d12oPO8tHObRruc2HWPB4ByLiagaPtu52v/GdJuqg28a71m8p1umND7lTOF59IEYR1yrFAudIR4pGmhYGpCdpWPfgamLyhy3sH9vslZ2KOg8n2bwkRUW/xPRVR+ATmzZwWwhqboschiY3QdUvsehAnU= 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 1608170357213631.9544608508438; Wed, 16 Dec 2020 17:59:17 -0800 (PST) Received: from localhost ([::1]:39296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpiZX-0001AS-V8 for importer@patchew.org; Wed, 16 Dec 2020 20:59:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUM-0003ty-Nn for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45488) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUK-0006If-Tw for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:54 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-73-nHp3piWCOG2FJimT7NZHqg-1; Wed, 16 Dec 2020 20:53:50 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7B62180A092 for ; Thu, 17 Dec 2020 01:53:49 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27FF760CC4; Thu, 17 Dec 2020 01:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170032; 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=34OLcZSH8Jc6cjj7YTdc+clNV92TrTbEqumigufgBKg=; b=IaUE3vet+ai+UPSbMZhxGba6Mb2v2xIeJb9TGQoqHs9FGgszNW/kn0Ic4qlU6TQBA/l54b EVcaXWVAz5lPlP0O6mn2ZDXqW+bNhPljBnbozIakXOPBhRFfnIz/AbQCh0V2NL3BZRH7od +O1cQjVYdoNbwzUGRuLOnu+5JTW0CI8= X-MC-Unique: nHp3piWCOG2FJimT7NZHqg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 06/13] qapi/introspect.py: replace 'extra' dict with 'comment' argument Date: Wed, 16 Dec 2020 20:53:36 -0500 Message-Id: <20201217015343.196279-7-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170713; cv=none; d=zohomail.com; s=zohoarc; b=aZfttNWzTYWuSDKWnzX2rBpwOEYeULXn45VQLHD+HgipjvH+GKuD/su6bseyryuBb6YE7pjaJMVIL/gDwyl5IQIpNNSSa5p1SfyEzgtTmPz+yNOkRegcO2kzPA5Pcj+OnkZIKAF2vjVBSWFDNIeblpU086o/6GQZBm8rQdVR4oo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170713; 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=HkgHh8k+I2YPr3xwSdQOVN0Z+dMhJaGNIwtCw8MwDfo=; b=D7OobXNJKE4BGtXcKOSFbJCAmQYLtkb9wfY+AQQRQy94ex7bScrxtMG/HTZHcLYCLh6MxV24GPnqTrv/Dfb7iFfyqxbK5RMBM8090lDcPOXIpYVr20weLQrPED/Q8z8NOE77IgV4p+XhlCShNA3PinyOamxncRFOMSS7884TSAM= 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 1608170713334127.44140871534171; Wed, 16 Dec 2020 18:05:13 -0800 (PST) Received: from localhost ([::1]:54258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpifI-0007bj-7k for importer@patchew.org; Wed, 16 Dec 2020 21:05:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52398) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUb-0004U8-Ex for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:54:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35802) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUM-0006Is-08 for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:54: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-251-HPL8xIWKP3OWArGBdygOyg-1; Wed, 16 Dec 2020 20:53:51 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9556659 for ; Thu, 17 Dec 2020 01:53:50 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDDD760CC4; Thu, 17 Dec 2020 01:53:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170033; 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=HkgHh8k+I2YPr3xwSdQOVN0Z+dMhJaGNIwtCw8MwDfo=; b=WS9b6R0rEJ9oT3fdR9+8YLFyngfn2nBNN5s1bD19huOOTvhM3SPMQHvMOQaEQ9PKiXtdK2 5uyu1FQXzlSKAt/y5kMiDBkz8i7U8jPA2qbPHY7ek5QtCNlFeCtvRzopYSh6Er3Ye/U7VI WUDMohbdSMd/DXFqPADvU2sRPicm5Gs= X-MC-Unique: HPL8xIWKP3OWArGBdygOyg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 07/13] qapi/introspect.py: Introduce preliminary tree typing Date: Wed, 16 Dec 2020 20:53:37 -0500 Message-Id: <20201217015343.196279-8-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: 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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170649; cv=none; d=zohomail.com; s=zohoarc; b=MO0AU5TmPkOgfomoeIP7nEICBGgroRxxJOmcBbFbJed8sr64V+92xmRQ1KmeTVFY06a6aZu3PsgWGiVLKqdVRNKYbE7731O7LohYH5bIiVG6+yq/PqXZ0su841gqpM1QKuYrEQb4VjRfkT1mYIiwzIJMcLso0J3KbvfcPeTb+y0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170649; 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=30SDIKT1qXvskfH5M7R0jI4I22sJvJkbJUQGSlk0o3Y=; b=PqizBa90lvnpn/4RF4tQK2zqNH3AV0AvnEj3zUuRtBn/uKfeKK67ASPEInKgD1YduDT5tjIQCITJcIFGh6VcCUcEHqu/xzJSpZCxN+akbwzdjNVY5kt8X85HyWib4uKIhexBsyArQ/Vulo/MMDN7zlQrFnV1vOj/jATZRYnYsRQ= 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 160817064946780.80663401084757; Wed, 16 Dec 2020 18:04:09 -0800 (PST) Received: from localhost ([::1]:52128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpieG-0006jx-6A for importer@patchew.org; Wed, 16 Dec 2020 21:04:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUP-0003zk-7e for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUN-0006J8-2v for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:56 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-255-MrqkzyD0M4q6LO6Wx9ePAA-1; Wed, 16 Dec 2020 20:53:52 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 654F9107ACE4 for ; Thu, 17 Dec 2020 01:53:51 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD51460CDE; Thu, 17 Dec 2020 01:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170034; 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=30SDIKT1qXvskfH5M7R0jI4I22sJvJkbJUQGSlk0o3Y=; b=c8U7AiO4qFPG9uvGq8fnP2dQZVyIZpeocXtLEm0l+3KBLHXLu1Of5uJZF0WscdM+PTdjUw DuOnjIJSgXwFlHg0cYGm4QKNaDftWdttJBaBgS57iPJv28fhhXAE7zXGpa2NifnIoFfrNr 4YNf+uGjlEYS42heqAUkJ4g191HoXxk= X-MC-Unique: MrqkzyD0M4q6LO6Wx9ePAA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 08/13] qapi/introspect.py: create a typed 'Annotated' data strutcure Date: Wed, 16 Dec 2020 20:53:38 -0500 Message-Id: <20201217015343.196279-9-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170511; cv=none; d=zohomail.com; s=zohoarc; b=VDrfpdFCZpTNYasMP82rHPNoizeVuvCY/DJ33rDeg8ZTzo5uc8kvOi5RN50FddN+QTO+LJ4wO+pB/DpnupxFLq5jYi2KDdKOf+R5w4Lp6Eu+eHF9ULnRQ4OMvg1qU4TkN4A7gy7cwoS3782bkfkiFnGTmemrdK92+qrS+pBAXio= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170511; 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=kYc96/QWpx7U3Rrnv8010zmYeEPAMXMcZYt+E9+WYuQ=; b=bVlBKtDKMybDRnU5SK7N2RcOKWFePwwaOe63q0ByIVAyZvba2h1aGz44oJvW4iTn4mPLZf0Mq+o/nRrE+J07E9iYU7/owTLqklFh6WFXzA2gilLebwG+RVbU4F80NRVjUUri+hEDuB8SB+k8ut82YUi+ZVxkxYc3NV1eviX1nh8= 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 160817051182033.619209716090154; Wed, 16 Dec 2020 18:01:51 -0800 (PST) Received: from localhost ([::1]:44180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpic2-0003W8-G7 for importer@patchew.org; Wed, 16 Dec 2020 21:01:50 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUP-00040J-D4 for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33295) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUN-0006JH-Pu for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:57 -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-293-F1PVpq-bPNyErJnAXC2mWg-1; Wed, 16 Dec 2020 20:53:53 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D73059 for ; Thu, 17 Dec 2020 01:53:52 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C43060CE1; Thu, 17 Dec 2020 01:53:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170035; 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=kYc96/QWpx7U3Rrnv8010zmYeEPAMXMcZYt+E9+WYuQ=; b=Eik1BEgjqPEjypnAYK7AHnqB7t4Lkk1X5VRRy949Ds817zt+EHObIcYZYShbroynj421pY fczoQ2FoszW/dTiMVYuID0XdhUAb/slKqx8O15JdesCRIOc3jLdi3znaalVhQ23/MolRt5 YnjnpRsAzdJBaWxBFVjycJ6Z6n2AJXM= X-MC-Unique: F1PVpq-bPNyErJnAXC2mWg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 09/13] qapi/introspect.py: improve _tree_to_qlit error message Date: Wed, 16 Dec 2020 20:53:39 -0500 Message-Id: <20201217015343.196279-10-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170817; cv=none; d=zohomail.com; s=zohoarc; b=COIj6yc77Xa4KODlQkQTaDLeeAM+ePwBtVPjnyVB3kfFGsvmwFvx8H04z+3jqvRDgKX2tGagyerpwndIy2VNsme493Q5J437EdafCXQQipTi/SqDPMXxZG920XAjJ7Nc35kp2xT8MrklGheWCczb20lrZL1MycEKV6HvNUJbgAg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170817; 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=aM8XGySP3WbjyXDiKB/rVYu/2P4W81VSgBXQPORtOk4=; b=H4jRUbs4D9jaG+6JSLIZIwxkCuKZHrL8Uc4osBRggUovDJsMdQNNkuKUCY/tlHFYJYjXkozHm/lrLJwY2NlXIcpGMF5XeEs9VPNtoG9ljlW6y0W2sG5EUHWURZNHUa5H/W3RrMOTejg0YQYn/UURtR8CGP2GPr6OIsLlxJ6ykog= 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 1608170817298641.8789956486982; Wed, 16 Dec 2020 18:06:57 -0800 (PST) Received: from localhost ([::1]:58592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpigx-00011r-Sp for importer@patchew.org; Wed, 16 Dec 2020 21:06:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52338) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUQ-00043f-SN for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57186) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUP-0006Jd-3c for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:53:58 -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-317-0Bx6f3zaOKKKij7suSnPuA-1; Wed, 16 Dec 2020 20:53:54 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF144E758 for ; Thu, 17 Dec 2020 01:53:53 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 940C560CC4; Thu, 17 Dec 2020 01:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170036; 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=aM8XGySP3WbjyXDiKB/rVYu/2P4W81VSgBXQPORtOk4=; b=KA0kdYFicGEASz0ng76azAteEOvefhlVwBlWpKRFwAEGMjNpVYeS/620G0pDrowF8Ggxx4 QpZVhM14b8somMLgd54W+GrxXS2S7yMCU7/8eNUfN5k0ylDWoDJ87ztPJvSeIkL9si0VNj mH9FlCClyn8uH/jXFsbE9jUERbyyPkw= X-MC-Unique: 0Bx6f3zaOKKKij7suSnPuA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 10/13] qapi/introspect.py: improve readability of _tree_to_qlit Date: Wed, 16 Dec 2020 20:53:40 -0500 Message-Id: <20201217015343.196279-11-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170188; cv=none; d=zohomail.com; s=zohoarc; b=Ck4BqaN+31zAVEiuI7LoD8u2nbnPHRMQlCuGzCNMxFkNJLtdySTp7UfWLw9f7BTM5tkzuLCsBw2WhlwTltgOgSLpGGVAXBsPaBtnPzq8yN2mlCemOBzrXYAyFPesG7P/kegaIMe22aUs1t0IrNKMCak3p2MCHUL4eZrxvqVH6i0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170188; 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=sojRU4s2Ky3US5+neP7GO26G15OfPTCL2fXhMAKCfKg=; b=dkhE9N/VJ19Qb+m63dw4dd5aJQoIkloUbM63Tyqno01nPwRYgN81UWXxs8GrBJg3sjEuFI4pswzBHWsS7wNMAeu99zV0Q8PVmY6Apn21yzwcYEdhG6YYmRvDuYX8mUzVp23MRl4wzk8dDVIR0MdHik2xQLGvkkpT5/Ej/R94hPk= 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 1608170188286963.7965505806649; Wed, 16 Dec 2020 17:56:28 -0800 (PST) Received: from localhost ([::1]:58838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpiWo-00060n-2v for importer@patchew.org; Wed, 16 Dec 2020 20:56:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52372) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUS-00048I-SV for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:54:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52331) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUQ-0006Jz-JO for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:54:00 -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-224-Ps2IKTzNMSWHlCidqpG2DA-1; Wed, 16 Dec 2020 20:53:55 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 17521180A092 for ; Thu, 17 Dec 2020 01:53:55 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0109B60CC4; Thu, 17 Dec 2020 01:53:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170037; 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=sojRU4s2Ky3US5+neP7GO26G15OfPTCL2fXhMAKCfKg=; b=jV94MP6jr7vghNUEulGaN3jeUxBDPQZZVaYJ9HsGPW4t4gY0oKMaeZ6H4O890MFSgl/egu 0tubSB04N7ZM4bWBS43IOxNybH43/yjTnkIdocCEj/GNw03mYAtNS4obrdaEjRb3tO8jJC nJfuuIfjMaBVZUBIgIgww4CtbRd4IwQ= X-MC-Unique: Ps2IKTzNMSWHlCidqpG2DA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 11/13] qapi/introspect.py: add type hint annotations Date: Wed, 16 Dec 2020 20:53:41 -0500 Message-Id: <20201217015343.196279-12-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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 | 114 ++++++++++++++++++++++++++----------- scripts/qapi/mypy.ini | 5 -- scripts/qapi/schema.py | 2 +- 3 files changed, 81 insertions(+), 40 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 60ec326d2c7..590898baf93 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: 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: 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: 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: QAPISourceInfo, + 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: QAPISourceInfo, + 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,37 @@ 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: 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: 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 0235208966a..1e5f5aee4d8 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -29,7 +29,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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170570; cv=none; d=zohomail.com; s=zohoarc; b=Rpn09iGuJdl+1OFwH8EJ6XjEw8LUCkZz/+y59DNaWIVojN7CA4R02sLYeC9c55Rh0kP5OdZWBZfuGHts9HSOk1mxluq/OVT/pbpBnpg7NIUnnXXvD0BI6XK26xjRQL5rPcTECuE4MTGh4IvWiiTODSrMpOZSipKx1dm1NaRMZ/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170570; 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=vFZ9pyFEeriExnyWXREkdCUhynnKVqtGGoUWxl0nB6w=; b=KJP/kFMSh7apXfoUKmKll+VMvaGRCem7HX3/oFyqMIL3a/4ABBvCYK+o45QGlIBwfbzkGWbws5UKRKHl8g7XxHMJX9M/eonR2gdmWuFfE3opKaDpeoEWG8Gr6iRYAFifXmFePNyS32mqd0ysN59CWBXfOi5yw5hf+nS/N6rKcxQ= 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 1608170570253363.23331424388516; Wed, 16 Dec 2020 18:02:50 -0800 (PST) Received: from localhost ([::1]:47030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpicy-0004hZ-Si for importer@patchew.org; Wed, 16 Dec 2020 21:02:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUT-00048o-7m for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:54:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46286) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUR-0006KA-AU for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:54:00 -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-477-bkuc4keiP029cYedkCBH3Q-1; Wed, 16 Dec 2020 20:53:56 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F03FC107ACE3 for ; Thu, 17 Dec 2020 01:53:55 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50B3B60CC4; Thu, 17 Dec 2020 01:53:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170038; 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=vFZ9pyFEeriExnyWXREkdCUhynnKVqtGGoUWxl0nB6w=; b=Za8i2vSf7VC3PT3B/t7LP0ctclOcsw7Yv+P/r9ocMlu4fupV6U44SC2+TD2CFAN2w/YSQy L6sCETgQnBdrLlCAmx1pbL+8X/9bBSwmLlN1Btm70ipao+h2EsTMgIX+Qkq78azxxPWyxi nMLY8rYwhiWRpKpZ+IbLscxgy8egNpY= X-MC-Unique: bkuc4keiP029cYedkCBH3Q-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 12/13] qapi/instrospect.py: add introspect.json dummy types Date: Wed, 16 Dec 2020 20:53:42 -0500 Message-Id: <20201217015343.196279-13-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 48 ++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 590898baf93..428397a6954 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -66,8 +66,14 @@ _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] +# We lack precise object types, so SchemaInfo, children, and related types= are +# typed here loosely as simply 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 +166,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 +238,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 +264,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 +275,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 +309,12 @@ def visit_object_type_flat(self, name: str, info: QAP= ISourceInfo, 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: QAPISourceInfo, @@ -326,7 +338,7 @@ def visit_command(self, name: str, info: QAPISourceInfo= , ifcond: List[str], =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.26.2 From nobody Tue Nov 18 05:54:45 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=1608170711; cv=none; d=zohomail.com; s=zohoarc; b=U9eGKP1T/G3JLYyE5w1r6sM29f086ec2bmia/LB0dazd0OO33UaDswXy5CSl1FWRHb/LBH1RNpdlvPdxxXqBQQXU3ej3Ewqu+f1b4tO4sA5CBgE9KHsl1e75hslCSmoa+HDMHAxtcb4mfP3iCST2UGD4YOmbP49COmp7DtTFP0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608170711; 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=SJ9IYkcUet9X5jxo9RQKcovqVr2pXoL0iYTwcE9VwJM=; b=RJtMaRZWf7GVvTabc8+gfGbLnE9DpqgL3TIhbsQuZAP4cWckQS8zFpw1ac+wDT+c9v4lgkOxpAFguer8UOyo5pcpcFKh9NIBmwdL8rNVl+hZ41rb84VHqrbj/9JCVFTkjT5MKMOC9AFimsKHFV+Pg95EuOmdriZGCMcliEoq0zE= 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 1608170711263876.8198600706188; Wed, 16 Dec 2020 18:05:11 -0800 (PST) Received: from localhost ([::1]:54130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpifG-0007Yj-7K for importer@patchew.org; Wed, 16 Dec 2020 21:05:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52378) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpiUT-0004AG-R6 for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:54:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56454) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpiUS-0006KL-3O for qemu-devel@nongnu.org; Wed, 16 Dec 2020 20:54:01 -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-432-BjDQ5Ca8Mj-yb7KVO8kYbA-1; Wed, 16 Dec 2020 20:53:57 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA585800D55 for ; Thu, 17 Dec 2020 01:53:56 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-131.rdu2.redhat.com [10.10.112.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24F0760CE1; Thu, 17 Dec 2020 01:53:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608170039; 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=SJ9IYkcUet9X5jxo9RQKcovqVr2pXoL0iYTwcE9VwJM=; b=Hwz9f3qphc1B5VBSs2f5NxTpKc9Z9RxFRfQaP/eDDidtPv9yoixfbYMk1Piq70GEpOfL4o bk8RfuTEfbHGfDDW3U3UsP4Or8u+rpBs6+r8Mwam0RYZKAF1ph2dl44x/YUv8GvutVOFe6 jfIJlOB3ljBvjzNgXke2CZv83M3DfKU= X-MC-Unique: BjDQ5Ca8Mj-yb7KVO8kYbA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v3 13/13] qapi/introspect.py: Add docstring to _tree_to_qlit Date: Wed, 16 Dec 2020 20:53:43 -0500 Message-Id: <20201217015343.196279-14-jsnow@redhat.com> In-Reply-To: <20201217015343.196279-1-jsnow@redhat.com> References: <20201217015343.196279-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 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 Reviewed-by: Cleber Rosa Signed-off-by: John Snow --- scripts/qapi/introspect.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 428397a6954..8d5b8513fc8 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. @@ -96,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.26.2