From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827635; cv=none; d=zohomail.com; s=zohoarc; b=EDxZg3TOd0jc6/I3shEZZhr9HodypBHHlUlYeK+pD7jnot3fTRFvMUJPvdmNoKke94C2EQ28gozjWX1YplpnGgB4/b4FV7Gooavb2bORcymd/DR/5cf4UCxl/AEZYwQCaIzk9VLbTUrKoOnjO1KZGymgAa0j4Sd+IIewdG4FzbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827635; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HRuhZWiF06Tp20gjR8Q/NfKBJU7LeSLPPudzwY0KDmk=; b=nufmsVqZ1CJ56pgbx+CPjFRDirQobvBRLX72ch0mNKyIhSs+sxFORWXppgQG566kJTUgVf22j/0iNC56f1F4ShbJeCUeF8TauD4o6oxPkY0IqQxEichJahsZlRZvQ1BSt+yR2nQmlffTr+i2K6n59MeXy7+AIKV3NUGQaTodfJk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827635627975.1126446023313; Thu, 1 Feb 2024 14:47:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm2-0006Df-Q8; Thu, 01 Feb 2024 17:43:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflu-00069X-PC for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflp-0006aK-Sd for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:02 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-110-D5Ld1syYOQKYRcH2fUvcqA-1; Thu, 01 Feb 2024 17:42:51 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E6EBE185A781; Thu, 1 Feb 2024 22:42:50 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE4CA2166B33; Thu, 1 Feb 2024 22:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HRuhZWiF06Tp20gjR8Q/NfKBJU7LeSLPPudzwY0KDmk=; b=VJzldOkEGKHPzQs4iNtFJIoZhx1CgDgRE2cmGXvJWK0FPDYjyMF4jFpomHD1bB65AiN4FU RuUfMCvr/iR3Nm3nIWYd/yFTQfBuQdt1xFqCBBPxkb0j3J5GdqyFHWCxnUgA6p3cpPbPFI FAZE1FqjYE5E9XlJht3JugSTwdU5GyI= X-MC-Unique: D5Ld1syYOQKYRcH2fUvcqA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 01/20] qapi: sort pylint suppressions Date: Thu, 1 Feb 2024 17:42:27 -0500 Message-ID: <20240201224246.39480-2-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827636598100001 Content-Type: text/plain; charset="utf-8" Suggested-by: Markus Armbruster Signed-off-by: John Snow --- scripts/qapi/pylintrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index 90546df5345..1342412c3cf 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -16,13 +16,13 @@ ignore-patterns=3Dschema.py, # --enable=3Dsimilarities". If you want to run only the classes checker, b= ut have # no Warning level messages displayed, use "--disable=3Dall --enable=3Dcla= sses # --disable=3DW". -disable=3Dfixme, +disable=3Dconsider-using-f-string, + fixme, missing-docstring, too-many-arguments, too-many-branches, - too-many-statements, too-many-instance-attributes, - consider-using-f-string, + too-many-statements, useless-option-value, =20 [REPORTS] --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827616; cv=none; d=zohomail.com; s=zohoarc; b=Jf2Vy9SGWaVuiGymQiql/KB8alW1zh8vhB4dXkTLlFWmjT4MGxRMH4yqfwhjKnhZJH2x5krrS7e+HsuZp/nlztWP3myHFqysk7OPJIx5jbHbsvBpwFMUxXDXu+ZSUGmyKloPe6NU8dGZqzpGLqpvbo9Si6tyWqEcnWd3KzoQnEg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827616; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NbvVQRggaouWq3+WTtvTbyOSHBEZ4Cs7EA+H9kbnD5A=; b=B0cbAssCXkJZotTH3TXo9hG5FFfq/Mrey0Awfvz8+v8LBeKxI9jllWYhoTm8BGOsYZIHJweXDdgAMkOIPGGmsvTHrkjiCD7WMa3Hik2sOo+rkbuas3+06xPq22/KFs0XzoMrrWjmQPkkWMv+cMOj32PFvEch+JOTbxfBzzMdhD4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827616359576.5290676122493; Thu, 1 Feb 2024 14:46:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm6-0006FG-HY; Thu, 01 Feb 2024 17:43:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflt-00069Q-NP for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflp-0006a2-4i for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:01 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-81-kccGcPnzPOuTReD8ghfHYg-1; Thu, 01 Feb 2024 17:42:51 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 293CD185A782; Thu, 1 Feb 2024 22:42:51 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id F182C2166B34; Thu, 1 Feb 2024 22:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NbvVQRggaouWq3+WTtvTbyOSHBEZ4Cs7EA+H9kbnD5A=; b=GiVu357h0YLokmk9Z9sFwgB4i6jf7PWqDFYZJOkBz7lsnEtKT00MQ9a1WXcQY47//Nju/J D6i0CTX4QVx3ilh/XMWRay6cL+pM84x9hTd0Y7/iVfpjzGJECtqIgvlHaSJK3XSxvmJd4W TiCigK+vKDSKHj934I/NKMum4zu+wLA= X-MC-Unique: kccGcPnzPOuTReD8ghfHYg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 02/20] qapi/schema: add pylint suppressions Date: Thu, 1 Feb 2024 17:42:28 -0500 Message-ID: <20240201224246.39480-3-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827616550100001 Content-Type: text/plain; charset="utf-8" With this patch, pylint is happy with the file, so enable it in the configuration. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/pylintrc | 5 ----- scripts/qapi/schema.py | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index 1342412c3cf..c028a1f9f51 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -1,10 +1,5 @@ [MASTER] =20 -# Add files or directories matching the regex patterns to the ignore list. -# The regex matches against base names, not paths. -ignore-patterns=3Dschema.py, - - [MESSAGES CONTROL] =20 # Disable the message, report, category or checker with the given id(s). Y= ou diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 6a836950a9a..b7830672e57 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -12,6 +12,8 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 +# pylint: disable=3Dtoo-many-lines + # TODO catching name collisions in generated code would be nice =20 from collections import OrderedDict @@ -83,6 +85,7 @@ def c_name(self): return c_name(self.name) =20 def check(self, schema): + # pylint: disable=3Dunused-argument assert not self._checked seen =3D {} for f in self.features: @@ -117,6 +120,7 @@ def is_implicit(self): return not self.info =20 def visit(self, visitor): + # pylint: disable=3Dunused-argument assert self._checked =20 def describe(self): @@ -135,6 +139,7 @@ def visit_module(self, name): pass =20 def visit_needed(self, entity): + # pylint: disable=3Dunused-argument # Default to visiting everything return True =20 --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827534; cv=none; d=zohomail.com; s=zohoarc; b=IKd1BVFa2X+WMmXXlR+aIfyUUZEYu3TiOZm6yLRp702oyrELNL3hnZ9foiirn9a4HAivZTQUNxCsA0d9rM/HZf3UfAIH9kSHBNI/5AkI4f8Q4FLQZt6YEhhZs8iI+eyIN8LGbjbEQWpTvaR6rhIaAwwtgfli5pklVG95/PpqjJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827534; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DeFvgnkVPBysZQ0YddRtZdYsDBNg0KraEEcpe3D+od0=; b=JynhnhOaV6aYJVq3LJ+OKeK0awn5U9DsgIdvO5ZkVt7ls96g5VYDbQbYYUsSteIlyVVfABH0DeYkKIuVm2Rw3Oy4abAmcmmAAh9y7JCnzwDPqi5XtmfVjDUgZP+cHnWTrgmr63R3RTYidZBM6tjhsSyU9UN3BZxxSCMcnCGGAIE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827534447878.344537461998; Thu, 1 Feb 2024 14:45:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfmB-0006Iu-Fs; Thu, 01 Feb 2024 17:43:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfm8-0006Gh-J2 for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflp-0006aO-55 for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:16 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-368-lInJ2MyzPdip4vVUGFRFVw-1; Thu, 01 Feb 2024 17:42:51 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 603E78352A0; Thu, 1 Feb 2024 22:42:51 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34E762166B33; Thu, 1 Feb 2024 22:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DeFvgnkVPBysZQ0YddRtZdYsDBNg0KraEEcpe3D+od0=; b=AVnYvK8vQCayWm5YU0j0OH+37QAqKENNBqpooGzMLYtGBj972r+i6fb0vLNA+lk2vYeImh sQ/w+eli7ntAFfLawWvyXOZxrCRSeRqO58DfAzT5YpEY9/Ps9Tukj4//KgWiz5JDpmxL9c dR3XA4RzVr8wP67hUiFrqJAA+30ua7M= X-MC-Unique: lInJ2MyzPdip4vVUGFRFVw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 03/20] qapi: create QAPISchemaDefinition Date: Thu, 1 Feb 2024 17:42:29 -0500 Message-ID: <20240201224246.39480-4-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827536439100003 Content-Type: text/plain; charset="utf-8" Include entities don't have names, but we generally expect "entities" to have names. Reclassify all entities with names as *definitions*, leaving the nameless include entities as QAPISchemaEntity instances. This is primarily to help simplify typing around expectations of what callers expect for properties of an "entity". Suggested-by: Markus Armbruster Signed-off-by: John Snow --- scripts/qapi/schema.py | 152 ++++++++++++++++++++++++----------------- 1 file changed, 88 insertions(+), 64 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index b7830672e57..7f790d44742 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -55,14 +55,13 @@ def is_present(self): =20 =20 class QAPISchemaEntity: - meta: Optional[str] =3D None + """ + A schema entity. =20 - 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) - f.set_defined_in(name) - self.name =3D name + This is either a directive, such as include, or a definition. + The latter uses sub-class `QAPISchemaDefinition`. + """ + def __init__(self, info): self._module =3D None # For explicitly defined entities, info points to the (explicit) # definition. For builtins (and their arrays), info is None. @@ -70,37 +69,20 @@ def __init__(self, name: str, info, doc, ifcond=3DNone,= features=3DNone): # triggered the implicit definition (there may be more than one # such place). self.info =3D info - self.doc =3D doc - self._ifcond =3D ifcond or QAPISchemaIfCond() - self.features =3D features or [] self._checked =3D False =20 def __repr__(self): - if self.name is None: - return "<%s at 0x%x>" % (type(self).__name__, id(self)) - return "<%s:%s at 0x%x>" % (type(self).__name__, self.name, - id(self)) - - def c_name(self): - return c_name(self.name) + return "<%s at 0x%x>" % (type(self).__name__, id(self)) =20 def check(self, schema): # pylint: disable=3Dunused-argument - assert not self._checked - seen =3D {} - for f in self.features: - f.check_clash(self.info, seen) self._checked =3D True =20 def connect_doc(self, doc=3DNone): - doc =3D doc or self.doc - if doc: - for f in self.features: - doc.connect_feature(f) + pass =20 def check_doc(self): - if self.doc: - self.doc.check() + pass =20 def _set_module(self, schema, info): assert self._checked @@ -111,6 +93,51 @@ def _set_module(self, schema, info): def set_module(self, schema): self._set_module(schema, self.info) =20 + def visit(self, visitor): + # pylint: disable=3Dunused-argument + assert self._checked + + +class QAPISchemaDefinition(QAPISchemaEntity): + meta: Optional[str] =3D None + + def __init__(self, name: str, info, doc, ifcond=3DNone, features=3DNon= e): + assert isinstance(name, str) + super().__init__(info) + for f in features or []: + assert isinstance(f, QAPISchemaFeature) + f.set_defined_in(name) + self.name =3D name + self.doc =3D doc + self._ifcond =3D ifcond or QAPISchemaIfCond() + self.features =3D features or [] + + def __repr__(self): + return "<%s:%s at 0x%x>" % (type(self).__name__, self.name, + id(self)) + + def c_name(self): + return c_name(self.name) + + def check(self, schema): + assert not self._checked + super().check(schema) + seen =3D {} + for f in self.features: + f.check_clash(self.info, seen) + + def connect_doc(self, doc=3DNone): + super().connect_doc(doc) + doc =3D doc or self.doc + if doc: + for f in self.features: + doc.connect_feature(f) + + def check_doc(self): + super().check_doc() + if self.doc: + self.doc.check() + @property def ifcond(self): assert self._checked @@ -119,10 +146,6 @@ def ifcond(self): def is_implicit(self): return not self.info =20 - def visit(self, visitor): - # pylint: disable=3Dunused-argument - assert self._checked - def describe(self): assert self.meta return "%s '%s'" % (self.meta, self.name) @@ -222,7 +245,7 @@ def visit(self, visitor): =20 class QAPISchemaInclude(QAPISchemaEntity): def __init__(self, sub_module, info): - super().__init__(None, info, None) + super().__init__(info) self._sub_module =3D sub_module =20 def visit(self, visitor): @@ -230,7 +253,7 @@ def visit(self, visitor): visitor.visit_include(self._sub_module.name, self.info) =20 =20 -class QAPISchemaType(QAPISchemaEntity): +class QAPISchemaType(QAPISchemaDefinition): # Return the C type for common use. # For the types we commonly box, this is a pointer type. def c_type(self): @@ -801,7 +824,7 @@ def __init__(self, name, info, typ, ifcond=3DNone): super().__init__(name, info, typ, False, ifcond) =20 =20 -class QAPISchemaCommand(QAPISchemaEntity): +class QAPISchemaCommand(QAPISchemaDefinition): meta =3D 'command' =20 def __init__(self, name, info, doc, ifcond, features, @@ -872,7 +895,7 @@ def visit(self, visitor): self.coroutine) =20 =20 -class QAPISchemaEvent(QAPISchemaEntity): +class QAPISchemaEvent(QAPISchemaDefinition): meta =3D 'event' =20 def __init__(self, name, info, doc, ifcond, features, arg_type, boxed): @@ -943,23 +966,24 @@ def __init__(self, fname): self.check() =20 def _def_entity(self, ent): + self._entity_list.append(ent) + + def _def_definition(self, defn): # Only the predefined types are allowed to not have info - assert ent.info or self._predefining - self._entity_list.append(ent) - if ent.name is None: - return + assert defn.info or self._predefining + self._def_entity(defn) # TODO reject names that differ only in '_' vs. '.' vs. '-', # because they're liable to clash in generated C. - other_ent =3D self._entity_dict.get(ent.name) - if other_ent: - if other_ent.info: - where =3D QAPISourceError(other_ent.info, "previous defini= tion") + other_defn =3D self._entity_dict.get(defn.name) + if other_defn: + if other_defn.info: + where =3D QAPISourceError(other_defn.info, "previous defin= ition") raise QAPISemError( - ent.info, - "'%s' is already defined\n%s" % (ent.name, where)) + defn.info, + "'%s' is already defined\n%s" % (defn.name, where)) raise QAPISemError( - ent.info, "%s is already defined" % other_ent.describe()) - self._entity_dict[ent.name] =3D ent + defn.info, "%s is already defined" % other_defn.describe()) + self._entity_dict[defn.name] =3D defn =20 def lookup_entity(self, name, typ=3DNone): ent =3D self._entity_dict.get(name) @@ -1001,7 +1025,7 @@ def _def_include(self, expr: QAPIExpression): QAPISchemaInclude(self._make_module(include), expr.info)) =20 def _def_builtin_type(self, name, json_type, c_type): - self._def_entity(QAPISchemaBuiltinType(name, json_type, c_type)) + self._def_definition(QAPISchemaBuiltinType(name, json_type, c_type= )) # Instantiating only the arrays that are actually used would # be nice, but we can't as long as their generated code # (qapi-builtin-types.[ch]) may be shared by some other @@ -1027,15 +1051,15 @@ def _def_predefineds(self): self._def_builtin_type(*t) self.the_empty_object_type =3D QAPISchemaObjectType( 'q_empty', None, None, None, None, None, [], None) - self._def_entity(self.the_empty_object_type) + self._def_definition(self.the_empty_object_type) =20 qtypes =3D ['none', 'qnull', 'qnum', 'qstring', 'qdict', 'qlist', 'qbool'] qtype_values =3D self._make_enum_members( [{'name': n} for n in qtypes], None) =20 - self._def_entity(QAPISchemaEnumType('QType', None, None, None, Non= e, - qtype_values, 'QTYPE')) + self._def_definition(QAPISchemaEnumType( + 'QType', None, None, None, None, qtype_values, 'QTYPE')) =20 def _make_features(self, features, info): if features is None: @@ -1057,7 +1081,8 @@ def _make_enum_members(self, values, info): def _make_array_type(self, element_type, info): name =3D element_type + 'List' # reserved by check_defn_name_st= r() if not self.lookup_type(name): - self._def_entity(QAPISchemaArrayType(name, info, element_type)) + self._def_definition(QAPISchemaArrayType( + name, info, element_type)) return name =20 def _make_implicit_object_type(self, name, info, ifcond, role, members= ): @@ -1072,7 +1097,7 @@ def _make_implicit_object_type(self, name, info, ifco= nd, role, members): # later. pass else: - self._def_entity(QAPISchemaObjectType( + self._def_definition(QAPISchemaObjectType( name, info, None, ifcond, None, None, members, None)) return name =20 @@ -1083,7 +1108,7 @@ def _def_enum_type(self, expr: QAPIExpression): ifcond =3D QAPISchemaIfCond(expr.get('if')) info =3D expr.info features =3D self._make_features(expr.get('features'), info) - self._def_entity(QAPISchemaEnumType( + self._def_definition(QAPISchemaEnumType( name, info, expr.doc, ifcond, features, self._make_enum_members(data, info), prefix)) =20 @@ -1111,7 +1136,7 @@ def _def_struct_type(self, expr: QAPIExpression): info =3D expr.info ifcond =3D QAPISchemaIfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) - self._def_entity(QAPISchemaObjectType( + self._def_definition(QAPISchemaObjectType( name, info, expr.doc, ifcond, features, base, self._make_members(data, info), None)) @@ -1141,7 +1166,7 @@ def _def_union_type(self, expr: QAPIExpression): info) for (key, value) in data.items()] members: List[QAPISchemaObjectTypeMember] =3D [] - self._def_entity( + self._def_definition( QAPISchemaObjectType(name, info, expr.doc, ifcond, features, base, members, QAPISchemaVariants( @@ -1160,7 +1185,7 @@ def _def_alternate_type(self, expr: QAPIExpression): info) for (key, value) in data.items()] tag_member =3D QAPISchemaObjectTypeMember('type', info, 'QType', F= alse) - self._def_entity( + self._def_definition( QAPISchemaAlternateType( name, info, expr.doc, ifcond, features, QAPISchemaVariants(None, info, tag_member, variants))) @@ -1185,11 +1210,10 @@ def _def_command(self, expr: QAPIExpression): if isinstance(rets, list): assert len(rets) =3D=3D 1 rets =3D self._make_array_type(rets[0], info) - self._def_entity(QAPISchemaCommand(name, info, expr.doc, ifcond, - features, data, rets, - gen, success_response, - boxed, allow_oob, allow_preconf= ig, - coroutine)) + self._def_definition( + QAPISchemaCommand(name, info, expr.doc, ifcond, features, data, + rets, gen, success_response, boxed, allow_oo= b, + allow_preconfig, coroutine)) =20 def _def_event(self, expr: QAPIExpression): name =3D expr['event'] @@ -1202,8 +1226,8 @@ def _def_event(self, expr: QAPIExpression): data =3D self._make_implicit_object_type( name, info, ifcond, 'arg', self._make_members(data, info)) - self._def_entity(QAPISchemaEvent(name, info, expr.doc, ifcond, - features, data, boxed)) + self._def_definition(QAPISchemaEvent(name, info, expr.doc, ifcond, + features, data, boxed)) =20 def _def_exprs(self, exprs): for expr in exprs: --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827592; cv=none; d=zohomail.com; s=zohoarc; b=HdMaFbTf/tRAjRYrPORQDH/CKZdpr06MgclJU4yvvX8fjH+2j/TYvPn+ouDtx9Vb3yPpRAxoxC4BO5EGnTUBaP5r5RD8Wkp40gqk+JjqWHNjoEcEMUjFi5ctsaZfULxnhOUxfOcraUSO/yA00B6zuxdP4g/GVzKLrsoO8cPhSok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827592; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xT/7bG4q93m/rp3nW0NzalgP88f1PSwra5CYEJjemBY=; b=nhnko+R8jKYjbz5jUl93Jf5KrTrreSgKVH5znKhP4GGFP9ep7Yr+aXmU2uKIRJETusJnJu6PwUFXNcxG9U79rqesuJzBWUntBjOI99qx0BWVTV3QU5RcnHnUFv0y8Q5hwPF+ymmpvUcDhKKlHS2fplBvSljVechqA2m7j7f715o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170682759218711.854415557869402; Thu, 1 Feb 2024 14:46:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm2-0006Db-Ml; Thu, 01 Feb 2024 17:43:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflu-00069T-9F for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflp-0006a3-4j for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:00 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-465-J5VZBG_qP16PLOPvX-7v9w-1; Thu, 01 Feb 2024 17:42:51 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 94D31380662A; Thu, 1 Feb 2024 22:42:51 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 691A02166B33; Thu, 1 Feb 2024 22:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827373; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xT/7bG4q93m/rp3nW0NzalgP88f1PSwra5CYEJjemBY=; b=W3R8gicISaB0VEwT61vkcRfWt7+hx+BawJaNXQvp7Sk2RyKetzto7v5MvisRsIKhIbNe4O IODZUr7Anm86ByQyxJOFFPY5GpJW3F1ti8lNNL7FKB0hoBWngeHzoSh22dAspRk4Lbdr8G nE9+J07qGj6UNPlw7KfOEmbSgXJfU5A= X-MC-Unique: J5VZBG_qP16PLOPvX-7v9w-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 04/20] qapi/schema: declare type for QAPISchemaObjectTypeMember.type Date: Thu, 1 Feb 2024 17:42:30 -0500 Message-ID: <20240201224246.39480-5-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827592516100001 Content-Type: text/plain; charset="utf-8" A QAPISchemaObjectTypeMember's type gets resolved only during .check(). We have QAPISchemaObjectTypeMember.__init__() initialize self.type =3D None, and .check() assign the actual type. Using .type before .check() is wrong, and hopefully crashes due to the value being None. Works. However, it makes for awkward typing. With .type: Optional[QAPISchemaType], mypy is of course unable to see that it's None before .check(), and a QAPISchemaType after. To help it over the hump, we'd have to assert self.type is not None before all the (valid) uses. The assertion catches invalid uses, but only at run time; mypy can't flag them. Instead, declare .type in .__init__() as QAPISchemaType *without* initializing it. Using .type before .check() now certainly crashes, which is an improvement. Mypy still can't flag invalid uses, but that's okay. Addresses typing errors such as these: qapi/schema.py:657: error: "None" has no attribute "alternate_qtype" [attr= -defined] qapi/schema.py:662: error: "None" has no attribute "describe" [attr-define= d] Signed-off-by: John Snow --- scripts/qapi/schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 7f790d44742..74a32656249 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -794,7 +794,7 @@ def __init__(self, name, info, typ, optional, ifcond=3D= None, features=3DNone): assert isinstance(f, QAPISchemaFeature) f.set_defined_in(name) self._type_name =3D typ - self.type =3D None + self.type: QAPISchemaType # set during check() self.optional =3D optional self.features =3D features or [] =20 --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827487; cv=none; d=zohomail.com; s=zohoarc; b=NpdHT17nKFp1YuF5uhJP46i4lQj+hw8/A2ADqWxOb5YwTFA7x6fIRqyOSKRlvxN+oAHHcJPTGCGColS/cKTrJyHlVZD5k0n39mEwnYS5vrkgnpcLte6JxBecx+9vlK/2SXx6LX4Z+xZCRTTM+PNZ5eX22Om5nzA1HWKQrWDvHvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827487; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=4tITLmLRB2Der99Uk6aC4p26mO3coBuLohkCgXJw5HA=; b=OWPTdg5WwY7bCumV+X0kjetC8kMCRb7dmoPQ20TUi7G5pheSSxhpR2Gy2TdwemMeLHQDn8S/IhfSLC3qfSkPAZc+sWqAUNv2XmNfLYT4FUGdNDyxefGBRvuDGlKKf53H3Fe++Z/te1amSN6UMl7IX48q7gLVmSp+kAhEMVslAeE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827487750848.6320735646516; Thu, 1 Feb 2024 14:44:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm5-0006E4-PW; Thu, 01 Feb 2024 17:43:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflu-00069S-8b for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflp-0006aS-Mm for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:00 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-670-D7Z2oQ5CMoCxm4P4NVIFBA-1; Thu, 01 Feb 2024 17:42:52 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CB315811E81; Thu, 1 Feb 2024 22:42:51 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F6032166B33; Thu, 1 Feb 2024 22:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4tITLmLRB2Der99Uk6aC4p26mO3coBuLohkCgXJw5HA=; b=aKNYOBtGHyPT1BbkzTGigllq5kxnPHd0J7rAZRQ8nCexiFYHC5sVK0hXSQ/Ts1IFUjIzvk OiVAD/uuQtz2EDZtGoGIXEXzTx88HrMENuFqgwfDyDaZCJYfx2c+pBlWDiPkHPsIDEX4Zo wBepMuS0xZjzbbwJQ5M04bjQHUxhNiE= X-MC-Unique: D7Z2oQ5CMoCxm4P4NVIFBA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 05/20] qapi/schema: declare type for QAPISchemaArrayType.element_type Date: Thu, 1 Feb 2024 17:42:31 -0500 Message-ID: <20240201224246.39480-6-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827488272100003 Content-Type: text/plain; charset="utf-8" A QAPISchemaArrayType's element type gets resolved only during .check(). We have QAPISchemaArrayType.__init__() initialize self.element_type =3D None, and .check() assign the actual type. Using .element_type before .check() is wrong, and hopefully crashes due to the value being None. Works. However, it makes for awkward typing. With .element_type: Optional[QAPISchemaType], mypy is of course unable to see that it's None before .check(), and a QAPISchemaType after. To help it over the hump, we'd have to assert self.element_type is not None before all the (valid) uses. The assertion catches invalid uses, but only at run time; mypy can't flag them. Instead, declare .element_type in .__init__() as QAPISchemaType *without* initializing it. Using .element_type before .check() now certainly crashes, which is an improvement. Mypy still can't flag invalid uses, but that's okay. Signed-off-by: John Snow --- scripts/qapi/schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 74a32656249..ac34e2781de 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -389,7 +389,7 @@ def __init__(self, name, info, element_type): super().__init__(name, info, None) assert isinstance(element_type, str) self._element_type_name =3D element_type - self.element_type =3D None + self.element_type: QAPISchemaType =20 def need_has_if_optional(self): # When FOO is an array, we still need has_FOO to distinguish --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827558; cv=none; d=zohomail.com; s=zohoarc; b=fk1WrJMk2bZgEyeJLlYkQdZtYELR8attOq+FVNGD8OHqHLaCQpUu088omrwO71ZKhpWwIC0JF+Q85/Fja6zSPY+J7gRNW3ohyVb0/erAJFYSq6Yen4S8BQMv0ZIQ0G1LJbZAl2/KdkFUGUs9WB88WPgRmb8oK47dL6L1Sho43qo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827558; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VO6Tg5Bm7WbLg6VzQBIxawZaW/wjLRsVQZdk4LDa/CY=; b=BCPs6CnrDe7BIxt14Nx5Ak7Z+Cd6IKGHXuw5GI8U7mdTbsnQQVTkZWnDTpEaCNDv2VZ2IiSxlM8RDdwTa+pq3XuBheo08N1JGOUNOOpx0EmYi4YrmG66iChD0EKRI0f1tB4jNyJeNdfFIs+RytMGQWwFF+B0T5M2uJMAO1CohHo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827558908863.2789899573897; Thu, 1 Feb 2024 14:45:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm3-0006Dw-Ey; Thu, 01 Feb 2024 17:43:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflx-0006Bz-2Q for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflr-0006aL-J2 for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:04 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-416-W6gyoZvFMlexXHbjCr-rgw-1; Thu, 01 Feb 2024 17:42:52 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0CF6D85A589; Thu, 1 Feb 2024 22:42:52 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id D555B2166B33; Thu, 1 Feb 2024 22:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VO6Tg5Bm7WbLg6VzQBIxawZaW/wjLRsVQZdk4LDa/CY=; b=RqghsHFMQ1YCLxwexYZJqfOFa3/aVuqfRZFNrMDUnjkvT8yb9K5rh/NHyOFrUrV+SAQ0Y/ 6lytl3UFwkoPGFUqp+dDswsx3P/U1+C918H7d2YNOvGkZO4jwASeLwb3dLgr4N9iIDbFFz 3KIJI9CZJS4h7ogSImcQkYI4wex6uwE= X-MC-Unique: W6gyoZvFMlexXHbjCr-rgw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 06/20] qapi/schema: make c_type() and json_type() abstract methods Date: Thu, 1 Feb 2024 17:42:32 -0500 Message-ID: <20240201224246.39480-7-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827560441100003 Content-Type: text/plain; charset="utf-8" These methods should always return a str, it's only the default abstract implementation that doesn't. They can be marked "abstract", which requires subclasses to override the method with the proper return type. Signed-off-by: John Snow --- scripts/qapi/schema.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index ac34e2781de..8abcd4a86cb 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -16,6 +16,7 @@ =20 # TODO catching name collisions in generated code would be nice =20 +from abc import ABC, abstractmethod from collections import OrderedDict import os import re @@ -253,9 +254,10 @@ def visit(self, visitor): visitor.visit_include(self._sub_module.name, self.info) =20 =20 -class QAPISchemaType(QAPISchemaDefinition): +class QAPISchemaType(QAPISchemaDefinition, ABC): # Return the C type for common use. # For the types we commonly box, this is a pointer type. + @abstractmethod def c_type(self): pass =20 @@ -267,6 +269,7 @@ def c_param_type(self): def c_unboxed_type(self): return self.c_type() =20 + @abstractmethod def json_type(self): pass =20 --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827629; cv=none; d=zohomail.com; s=zohoarc; b=JbRH2u2EoQu4Kr+fTWXQC2RPd6JW0xddJ6e7iey8WXOBv0hJ9Vtx0Jsk/xyUGSmKtMtSt/fyeHUo6bQTr+r588E+wVV/o2GA/H8DLdsR5vxzOVKbzHRqDPnEmSX/MUSCNN8yk7Szqt0ep/bSICW5PPy+qZ1edW5i7rfFcpjSuVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827629; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BvaF0NFJiLgcm31471Fs/mRMWI2eNa6Nj/Apjh1gmI4=; b=CB81qI99rZiJcLOOxQ6AAHkGICtXiZh9MANzdHVCPLRETPVnkYDAwgPhCGPYObmVzGs7IPZN/e0JLix7ES8YA/yOzR+d+LA2Pc5QAXM7jOh8Ol54KBzFUwXE8/+tMCSXW/ZR740nJ13y3r7+DsK6gWer1T+RaMj/IPtMKfYE9hk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827629586365.14483726123274; Thu, 1 Feb 2024 14:47:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm2-0006Dc-Mn; Thu, 01 Feb 2024 17:43:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflv-00069Y-1m for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflp-0006b3-P4 for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:02 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-295-OPlEZh1TO1WObDyT8m16KA-1; Thu, 01 Feb 2024 17:42:52 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 436751C0CCA5; Thu, 1 Feb 2024 22:42:52 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 178CF2166B33; Thu, 1 Feb 2024 22:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BvaF0NFJiLgcm31471Fs/mRMWI2eNa6Nj/Apjh1gmI4=; b=g/xnN7PAHCB+Om+wd8sFxgyFopARzc8HOqzLvPqyCqL/yNtzbL8vdo73izlehMjZjb49zM na/dslvkBo1dsAvrKeOglJncmLKectgTPgLwiRFs2N3rpHzwb5Iej+E2o/tsLL65d8jY8y khOG51hFvMYDEUZYwr6NuoKKKeeDfj0= X-MC-Unique: OPlEZh1TO1WObDyT8m16KA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 07/20] qapi/schema: adjust type narrowing for mypy's benefit Date: Thu, 1 Feb 2024 17:42:33 -0500 Message-ID: <20240201224246.39480-8-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827630620100001 Content-Type: text/plain; charset="utf-8" We already take care to perform some type narrowing for arg_type and ret_type, but not in a way where mypy can utilize the result once we add type hints, e.g.: qapi/schema.py:833: error: Incompatible types in assignment (expression has type "QAPISchemaType", variable has type "Optional[QAPISchemaObjectType]") [assignment] qapi/schema.py:893: error: Incompatible types in assignment (expression has type "QAPISchemaType", variable has type "Optional[QAPISchemaObjectType]") [assignment] A simple change to use a temporary variable helps the medicine go down. Signed-off-by: John Snow --- scripts/qapi/schema.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 8abcd4a86cb..043ee7556e6 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -851,13 +851,14 @@ def __init__(self, name, info, doc, ifcond, features, def check(self, schema): super().check(schema) if self._arg_type_name: - self.arg_type =3D schema.resolve_type( + arg_type =3D schema.resolve_type( self._arg_type_name, self.info, "command's 'data'") - if not isinstance(self.arg_type, QAPISchemaObjectType): + if not isinstance(arg_type, QAPISchemaObjectType): raise QAPISemError( self.info, "command's 'data' cannot take %s" - % self.arg_type.describe()) + % arg_type.describe()) + self.arg_type =3D arg_type if self.arg_type.variants and not self.boxed: raise QAPISemError( self.info, @@ -874,8 +875,8 @@ def check(self, schema): if self.name not in self.info.pragma.command_returns_exception= s: typ =3D self.ret_type if isinstance(typ, QAPISchemaArrayType): - typ =3D self.ret_type.element_type assert typ + typ =3D typ.element_type if not isinstance(typ, QAPISchemaObjectType): raise QAPISemError( self.info, @@ -911,13 +912,14 @@ def __init__(self, name, info, doc, ifcond, features,= arg_type, boxed): def check(self, schema): super().check(schema) if self._arg_type_name: - self.arg_type =3D schema.resolve_type( + typ =3D schema.resolve_type( self._arg_type_name, self.info, "event's 'data'") - if not isinstance(self.arg_type, QAPISchemaObjectType): + if not isinstance(typ, QAPISchemaObjectType): raise QAPISemError( self.info, "event's 'data' cannot take %s" - % self.arg_type.describe()) + % typ.describe()) + self.arg_type =3D typ if self.arg_type.variants and not self.boxed: raise QAPISemError( self.info, --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827467; cv=none; d=zohomail.com; s=zohoarc; b=Mz0BNjKrJAKGgM4E3sQRrIF5mUcfbhu35EGmO6z4Dfit95eXdUrZc/3wa9SEvcjLHGvrkSBB6RraBCEO3p/i0ijBEz48DBfuULgG+Ak3gXHNJaAp7qjLW9bf9G3fXrIv7oNyyZjrE2XkNO7qutZ6W3Fhm89ttn/1xyhVY0WMgJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827467; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CNLCpTMs7KFb/Jtm7ps4rTnq4JhQ04QZAbq+ZtIAvj4=; b=EtOcI++munI9eId7wKVnwXrNNtltWyqn5wMcejBVR2uAuUWH2XRrjNv2YCI4MhQhcRtA/Q2BWckt3og1rXPE3Tjn+ypMmu+DDp4QwQ2ITQOIuCr5YOrv3Eu4aouOTiczA+H7RpIOIFR5I4wcofvDSpJ+gJkVIE40D+LmoiA9N8w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827467620719.4676982698411; Thu, 1 Feb 2024 14:44:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfmB-0006Il-Gn; Thu, 01 Feb 2024 17:43:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfm2-0006DZ-9c for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflt-0006be-VP for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:10 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-462-1u3U5G-uO9GHop_JNjyVZA-1; Thu, 01 Feb 2024 17:42:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7971D3C025B1; Thu, 1 Feb 2024 22:42:52 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E0402166B33; Thu, 1 Feb 2024 22:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CNLCpTMs7KFb/Jtm7ps4rTnq4JhQ04QZAbq+ZtIAvj4=; b=RTaFCtQad1I4tRwOaQr91o2RrtUAn6JNis2A/WHpEr6elSNEY3Ll54aYD+/B5ADURRqkZc fiDA1X4cIPh+9zipzXCB4+YcHx+oMj1zjHFNGDx5zk7r+0MIvRGdPnPtR2BkyyX37LR6Da W4qYLxDFh4fMf4gbI5p6/h6nDwSh3Ws= X-MC-Unique: 1u3U5G-uO9GHop_JNjyVZA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 08/20] qapi/schema: add type narrowing to lookup_type() Date: Thu, 1 Feb 2024 17:42:34 -0500 Message-ID: <20240201224246.39480-9-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827468214100001 Content-Type: text/plain; charset="utf-8" This function is a bit hard to type as-is; mypy needs some assertions to assist with the type narrowing. Signed-off-by: John Snow --- scripts/qapi/schema.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 043ee7556e6..e617abb03af 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -997,7 +997,9 @@ def lookup_entity(self, name, typ=3DNone): return ent =20 def lookup_type(self, name): - return self.lookup_entity(name, QAPISchemaType) + typ =3D self.lookup_entity(name, QAPISchemaType) + assert typ is None or isinstance(typ, QAPISchemaType) + return typ =20 def resolve_type(self, name, info, what): typ =3D self.lookup_type(name) --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827421; cv=none; d=zohomail.com; s=zohoarc; b=iBqT1xaWMOsNGV5u/8PhV7q6yodPwfRY2571gLelCX3/H0C8xFV6DDn/x/TZCKk4XvnFX6LmO+heWtGrNQcj/y6axV9au8xLyYIacaR1/QlwhbUbU2cHRrIpni8XNLKA8qORCPSXxll1MiliTF9N0kZqaZl5h3pH/kPt7oRrlTA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827421; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Laxz//13Fow5ms+2ff1VxYJP+RtEZ6U88gSorUMTHSE=; b=VHrd2+xiS1MGGsfUkXDQWRS9TOKKUsq9pGzg2YsEKByj9wKM8O1FpEiffFllbWEi7kufWao2SqG5F0MoriDrZ43938qIKhNp1nFsRmqwrrm2OduHg0sXTV7EgndpQP3TEPOgIfId7slxzfWB4lktAhwx78tDJirIL23Fl0oIDkI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827421685437.7004028308986; Thu, 1 Feb 2024 14:43:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm0-0006Cd-LN; Thu, 01 Feb 2024 17:43:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflu-00069R-7o for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflp-0006aj-E4 for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:42:59 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-327-WjCoRC78MR2O1IYj4309Lg-1; Thu, 01 Feb 2024 17:42:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF2578352A3; Thu, 1 Feb 2024 22:42:52 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83E982166B33; Thu, 1 Feb 2024 22:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Laxz//13Fow5ms+2ff1VxYJP+RtEZ6U88gSorUMTHSE=; b=cQF1GwqRqvisMrAzNNiSzuMqE0z3xHBw3u/EBrReKJBHEyAiruFFMezWKaKAgTPFaFftv4 v/K/AkApcshW3rBuLewUJRxmlYT/z+R+hLBK63HxcwoemsHefLuG5DWVMn0kqEIxz30QZR bDM9a8/PfxDPlzToUHJiNq8rqYWR0fw= X-MC-Unique: WjCoRC78MR2O1IYj4309Lg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 09/20] qapi/schema: assert resolve_type has 'info' and 'what' args on error Date: Thu, 1 Feb 2024 17:42:35 -0500 Message-ID: <20240201224246.39480-10-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827422333100001 Content-Type: text/plain; charset="utf-8" resolve_type() is generally used to resolve configuration-provided type names into type objects, and generally requires valid 'info' and 'what' parameters. In some cases, such as with QAPISchemaArrayType.check(), resolve_type may be used to resolve built-in types and as such will not have an 'info' argument, but also must not fail in this scenario. Use an assertion to sate mypy that we will indeed have 'info' and 'what' parameters for the error pathway in resolve_type. Note: there are only three callsites to resolve_type at present where "info" is perceived to be possibly None: 1) QAPISchemaArrayType.check() 2) QAPISchemaObjectTypeMember.check() 3) QAPISchemaEvent.check() Of those three, only the first actually ever passes None; the other two are limited by their base class initializers which accept info=3DNone, = but neither subclass actually use a None value in practice, currently. Signed-off-by: John Snow --- scripts/qapi/schema.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index e617abb03af..573be7275a6 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -1004,6 +1004,7 @@ def lookup_type(self, name): def resolve_type(self, name, info, what): typ =3D self.lookup_type(name) if not typ: + assert info and what # built-in types must not fail lookup if callable(what): what =3D what(info) raise QAPISemError( --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827430; cv=none; d=zohomail.com; s=zohoarc; b=TcWAoiU5LjprIBEsXzL2yPRD+AYqBNIs0ONblK4pEcXl3TkJTNPIgsJOF3DiVkaiEWr7QQQpN7kIdJrE2bjCCWwqUQ6Qr4gWok3mTXbSYYOckAbnkuw4Q2bsgAg8ZdPiqrTMuDYhGEULXFTx2ZwFNyw1oePog4TNkcoLxSmuBQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827430; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HJcoAJeVLSOkxB/xamweiKZEQzBNZbCwzH5v7YJ2UGc=; b=a+JOQ6vhCC7x4TWdglDKZzLXg2uy7ynl88b3KeVY2/0Y9pN5AsSvtLyzXNg6Rmm1kEyNeDjNhYCl7y4VTPlONnFVPdzagRIrUS0hznEDsIPULFz3IrjWvNbWouh85AV5HymszFEdGQuZElrxG4aPuZvjRYj9LRse9l47nIC/F8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827430915758.7149016799161; Thu, 1 Feb 2024 14:43:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfmC-0006JT-4M; Thu, 01 Feb 2024 17:43:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfm8-0006Gf-Iw for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflr-0006aV-Ey for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:16 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-207-7IUUejz4NFOYq0U4tPDA4w-1; Thu, 01 Feb 2024 17:42:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E472E88D588; Thu, 1 Feb 2024 22:42:52 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id B924A2166B35; Thu, 1 Feb 2024 22:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827374; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HJcoAJeVLSOkxB/xamweiKZEQzBNZbCwzH5v7YJ2UGc=; b=Fcn8LMuwjrRvURGzsd+tEg9VFr1+FYYSMosUICibNK9uOPiqQN6IUUz6baBQeu+HQCFwKD fNJFfPbGsHxd6F2NECkaP1F6+2zvfvi7bNpErahjAJdf9b5nfCL+DMq8BoUaWLhISOHHrv CzZrXKAtbpQyTrReEppVfuacpMHUMek= X-MC-Unique: 7IUUejz4NFOYq0U4tPDA4w-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 10/20] qapi: use schema.resolve_type instead of schema.lookup_type Date: Thu, 1 Feb 2024 17:42:36 -0500 Message-ID: <20240201224246.39480-11-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827432081100002 Content-Type: text/plain; charset="utf-8" the function lookup_type() is capable of returning None, but some callers aren't prepared for that and assume it will always succeed. For static type analysis purposes, this creates problems at those callsites. Modify resolve_type() - which already cannot ever return None - to allow 'info' and 'what' parameters to be elided, which infers that the type lookup is a built-in type lookup. Change several callsites to use the new form of resolve_type to avoid the more laborious strictly-typed error-checking scaffolding: ret =3D lookup_type("foo") assert ret is not None typ: QAPISchemaType =3D ret which can be replaced with the simpler: typ =3D resolve_type("foo") Signed-off-by: John Snow --- scripts/qapi/introspect.py | 4 ++-- scripts/qapi/schema.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 67c7d89aae0..c38df61a6d5 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -227,10 +227,10 @@ def _use_type(self, typ: QAPISchemaType) -> str: =20 # Map the various integer types to plain int if typ.json_type() =3D=3D 'int': - typ =3D self._schema.lookup_type('int') + typ =3D self._schema.resolve_type('int') elif (isinstance(typ, QAPISchemaArrayType) and typ.element_type.json_type() =3D=3D 'int'): - typ =3D self._schema.lookup_type('intList') + typ =3D self._schema.resolve_type('intList') # Add type to work queue if new if typ not in self._used_types: self._used_types.append(typ) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 573be7275a6..074897ee4fb 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -650,8 +650,7 @@ def check(self, schema, seen): "discriminator '%s' is not a member of %s" % (self._tag_name, base)) # Here we do: - base_type =3D schema.lookup_type(self.tag_member.defined_in) - assert base_type + base_type =3D schema.resolve_type(self.tag_member.defined_in) if not base_type.is_implicit(): base =3D "base type '%s'" % self.tag_member.defined_in if not isinstance(self.tag_member.type, QAPISchemaEnumType): @@ -1001,7 +1000,7 @@ def lookup_type(self, name): assert typ is None or isinstance(typ, QAPISchemaType) return typ =20 - def resolve_type(self, name, info, what): + def resolve_type(self, name, info=3DNone, what=3DNone): typ =3D self.lookup_type(name) if not typ: assert info and what # built-in types must not fail lookup --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827486; cv=none; d=zohomail.com; s=zohoarc; b=PjGLu4NZ/noOfUrMUE2Ap5wpuBHVtpKq3RQZj0OntTz6fBwDKVsKxnuJ5lJ4ZWHr3SSv/AAjYKtS6z0lbRePLgNL98huSNXm4K3ByFH8xfgIi5LUd+8zSvsnRSzfSFbV16itgYPI1LFW4uAhZDMM/+3Cjyh41vNf3oI2dEqETGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827486; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DVFoZ/Rsyf1nthjiaWDGV3YhhUd/pqd4dL0Tcw9dEzE=; b=ANRV1w6Ith9kgoFRqgE6my2vKAXPps2QhV28yUxwpbG3+samSeX+KO9UzjGdONfF+8ltbMsbTiq2hAIaPahdjwP/FEksQKlZKWRpfKA6zSzczb2S7XNOuxt6Ugk9Hdpq3ik2rf+mI3KFZDvM3EClOABjvTz30UH1KoFrJPxvdaA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827486281513.4939931486264; Thu, 1 Feb 2024 14:44:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfmB-0006JE-UN; Thu, 01 Feb 2024 17:43:20 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflv-0006Bw-TQ for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflr-0006bE-IQ for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:03 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-339-Pe8z7Z2jMiyvRkcxHxjQUQ-1; Thu, 01 Feb 2024 17:42:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 24AED3C00084; Thu, 1 Feb 2024 22:42:53 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED9692166B33; Thu, 1 Feb 2024 22:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DVFoZ/Rsyf1nthjiaWDGV3YhhUd/pqd4dL0Tcw9dEzE=; b=Cmdgi6RlOe8Z7H/hys3Dl/oPmCByUUDQa3e9MfCdezaQZH41sNVIY3rZxPTa7WX1zxCJja ux/S4FEiRtBqp8TI1ClmuW9ShQdp0IpPMktU+NUOIlWRSkpVMMkCSOfnivnOXU2kZ8Ph3q rK4O6qZ7aX+AtEsYJjYmDqSd077f5I8= X-MC-Unique: Pe8z7Z2jMiyvRkcxHxjQUQ-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 11/20] qapi/schema: fix QAPISchemaArrayType.check's call to resolve_type Date: Thu, 1 Feb 2024 17:42:37 -0500 Message-ID: <20240201224246.39480-12-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827488273100004 Content-Type: text/plain; charset="utf-8" Adjust the expression at the callsite to work around mypy's weak type introspection that believes this expression can resolve to QAPISourceInfo; it cannot. (Fundamentally: self.info only resolves to false in a boolean expression when it is None; therefore this expression may only ever produce Optional[str]. mypy does not know that 'info', when it is a QAPISourceInfo object, cannot ever be false.) Signed-off-by: John Snow --- scripts/qapi/schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 074897ee4fb..ae350f64a8f 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -403,7 +403,7 @@ def check(self, schema): super().check(schema) self.element_type =3D schema.resolve_type( self._element_type_name, self.info, - self.info and self.info.defn_meta) + self.info.defn_meta if self.info else None) assert not isinstance(self.element_type, QAPISchemaArrayType) =20 def set_module(self, schema): --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827430; cv=none; d=zohomail.com; s=zohoarc; b=iz+BaK9OWGhbOsDc0ETEVlWQYiXI+Md8KYFqqn7Jdj7YkkifucdXeM+e3UOrQ2vpkXyFAIj9DvPSF6zibVj46vdZZThfpK4FZBn+SiTwq1SREk6h6S2G/jpHifWRghu3oZ+If96+I2YNQsGAfEy5cLDhktt8uowOZ74IRmNe8ms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827430; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5+26PLIPvM3Oisqg4ogbTbDDIV6O7Q7VSuQek0MQVgo=; b=feDczM/BNT2rchhI9y91gPBpHcmkoPg5rlL3erlP+jZvJz9t/IYE4fELtl1TStrVdoBbMCcx/RZNRJH1nb3WJGX3+Bba29cq5x2jftg9I85lKH/N4/UBHi22y/+UqUgehZniF60zFIGXHf1TG1OPJV/PrunswpBlPpwFg04DdhM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170682743019566.31663173780419; Thu, 1 Feb 2024 14:43:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm3-0006Ds-AS; Thu, 01 Feb 2024 17:43:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflu-00069W-GE for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflp-0006ax-NV for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:02 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-680-NrAVeYnFO3Sy_URW33ziUA-1; Thu, 01 Feb 2024 17:42:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B19985A589; Thu, 1 Feb 2024 22:42:53 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F22C2166B33; Thu, 1 Feb 2024 22:42:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5+26PLIPvM3Oisqg4ogbTbDDIV6O7Q7VSuQek0MQVgo=; b=a17pTLN6m3xzS6hOd8I/4iBlGfXhfazLQOjLpHHbCPQsvc10ZErvgW1y+UuQkpeLn5gseG S1eOclvrINNPCgTVBnEiaYkZUYq6ILqieO+VY8Q3OteV9z52LtrGzRHNCNy7BGSOuPmv/m 6tmotpr6nvdu1TLlsZ6aYOeyHpufugw= X-MC-Unique: NrAVeYnFO3Sy_URW33ziUA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 12/20] qapi/schema: assert info is present when necessary Date: Thu, 1 Feb 2024 17:42:38 -0500 Message-ID: <20240201224246.39480-13-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827432070100001 Content-Type: text/plain; charset="utf-8" QAPISchemaInfo arguments can often be None because built-in definitions don't have such information. The type hint can only be Optional[QAPISchemaInfo] then. But, mypy gets upset about all the places where we exploit that it can't actually be None there. Add assertions that will help mypy over the hump, to enable adding type hints in a forthcoming commit. Signed-off-by: John Snow --- scripts/qapi/schema.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index ae350f64a8f..d4d3c3bbcee 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -758,6 +758,7 @@ def describe(self, info): else: assert False =20 + assert info is not None if defined_in !=3D info.defn_name: return "%s '%s' of %s '%s'" % (role, self.name, meta, defined_= in) return "%s '%s'" % (role, self.name) @@ -848,6 +849,7 @@ def __init__(self, name, info, doc, ifcond, features, self.coroutine =3D coroutine =20 def check(self, schema): + assert self.info is not None super().check(schema) if self._arg_type_name: arg_type =3D schema.resolve_type( --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827634; cv=none; d=zohomail.com; s=zohoarc; b=HfmgRy4YxmpDjKLeJQwXvjIlaQnAR0FtJ37129AzllOkc2miTwAwqGmwR/V2TnsoZTx2274RNy/ki99kZDE76HZRlQXLEHajICygxhAtOPhjnUP4d+Sh/cdd49xxqCjZo4azMp935tak5RQRrQ5eIQALM6z9Zg/Mw/AV+Vly5As= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827634; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QnWXIaPjKOxyGvU7S7UUbxwg4jiIYa4UF5NoEYreHt4=; b=mH7lscfsSXjmGqijI2wraIVIwdIcBX78+96xrozkyHWKy2mdI/MLBs3W6rnEnENZLU0J1/TKTalv5UBYUPknkBEJO5Up9doTx7CqJhgc8zSlMcfsb8AN6x4M4ZcevxNC/45YQUVyUxuxNsutFGOrqdy6y8n3zPFNZO8LIVCla0Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827634875989.9490474152714; Thu, 1 Feb 2024 14:47:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm7-0006G3-3y; Thu, 01 Feb 2024 17:43:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflw-0006Bx-4U for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflr-0006b6-JN for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:03 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-ORcPMbSbMkqKOhPcGpC98Q-1; Thu, 01 Feb 2024 17:42:53 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 92C053C025D3; Thu, 1 Feb 2024 22:42:53 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6701B2166B33; Thu, 1 Feb 2024 22:42:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827377; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QnWXIaPjKOxyGvU7S7UUbxwg4jiIYa4UF5NoEYreHt4=; b=ZY8WOEWahsr27dKO44GPZ7KCkjO0dTef8876J36pQL0YevdiGDR1VydxQTPi7aRr6hOLjH uwbZWfWf+vz4jZQ00Gsg6M5MXADLhwbR88WOVkRJi3s9SplSXHhDjvXF0niBsjMx/P/lW3 uvdGGY08NAmriS2y5mpxXOPR26G6BKw= X-MC-Unique: ORcPMbSbMkqKOhPcGpC98Q-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 13/20] qapi/schema: split "checked" field into "checking" and "checked" Date: Thu, 1 Feb 2024 17:42:39 -0500 Message-ID: <20240201224246.39480-14-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827636601100002 Content-Type: text/plain; charset="utf-8" Instead of using the None value for the members field, use a dedicated "checking" value to detect recursive misconfigurations. This is intended to assist with subsequent patches which will seek to remove the "None" value from the members field (which can never be set legally after the final call to check()) in order to simplify static typing of that field, by avoiding needing assertions littered at many callsites. Signed-off-by: John Snow --- scripts/qapi/schema.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index d4d3c3bbcee..a459016e148 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -458,19 +458,21 @@ def __init__(self, name, info, doc, ifcond, features, self.local_members =3D local_members self.variants =3D variants self.members =3D None + self._checking =3D False =20 def check(self, schema): # This calls another type T's .check() exactly when the C # struct emitted by gen_object() contains that T's C struct # (pointers don't count). - if self.members is not None: - # A previous .check() completed: nothing to do - return - if self._checked: + if self._checking: # Recursed: C struct contains itself raise QAPISemError(self.info, "object %s contains itself" % self.name) + if self._checked: + # A previous .check() completed: nothing to do + return =20 + self._checking =3D True super().check(schema) assert self._checked and self.members is None =20 @@ -495,7 +497,8 @@ def check(self, schema): self.variants.check(schema, seen) self.variants.check_clash(self.info, seen) =20 - self.members =3D members # mark completed + self.members =3D members + self._checking =3D False # mark completed =20 # Check that the members of this type do not cause duplicate JSON memb= ers, # and update seen to track the members seen so far. Report any errors --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827593; cv=none; d=zohomail.com; s=zohoarc; b=LRI0m9/4OSfbWAyXmHW7jblGTLmnEagrGUwwbC15TDxAH9q5IWioRWigyMmCzw1dHeie3TCAvSgcm1O619FRLGWE2DDXBXsKuaM/Sj+z77GyiDYLXKMRLhe6F5x1tzL+GZFhuiF+pMy+xgR16+nerNAJOFMJBnuCGOw3j8pHJEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827593; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uHv/vYuudgawFX8d3eCgkHFBI73VlOA6zxY7RrJbKII=; b=Nlvc1RcZwMEDFxAmo8xaGfv4+4Lk3UtbI1QyyP/rAWQ1arQzeaZNg0Qtws9aCi/eJe5hrADyrDKH51inDcgwGysIVtW4aWKuERBf62lRM0m7RTO2HK7n53Ktl35eVRZQSQSXxZPGpa3FLs83namQ9WjBbbb8qo4OKAFSx0mwups= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827593557427.35084619045494; Thu, 1 Feb 2024 14:46:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm3-0006Dt-9r; Thu, 01 Feb 2024 17:43:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflu-00069U-9K for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflp-0006aP-59 for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:00 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-68-Kv94m_YmNjumYsBJrhU-vQ-1; Thu, 01 Feb 2024 17:42:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C9009811E81; Thu, 1 Feb 2024 22:42:53 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D76E2166B36; Thu, 1 Feb 2024 22:42:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827375; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uHv/vYuudgawFX8d3eCgkHFBI73VlOA6zxY7RrJbKII=; b=dQymRHK2k/ZM4pePb/Qn3ZVt6P8BnamrgAtVs4ZygJAkaiFK3aMOFC6QdKh5DZ2Gc67IdA 7ByC3lTwCcYGVNx9J3qqFyQ/Cni/4baOgWSao4Wi5Nr9nD/IcSqS+pMiLYMX8eBUATgdd/ A1Z2OBTpW4+EZMIXECc77WxCqt8NkzA= X-MC-Unique: Kv94m_YmNjumYsBJrhU-vQ-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 14/20] qapi/schema: Don't initialize "members" with `None` Date: Thu, 1 Feb 2024 17:42:40 -0500 Message-ID: <20240201224246.39480-15-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827594508100005 Content-Type: text/plain; charset="utf-8" Declare, but don't initialize the "members" field with type List[QAPISchemaObjectTypeMember]. This simplifies the typing from what would otherwise be Optional[List[T]] to merely List[T]. This removes the need to add assertions to several callsites that this value is not None - which it never will be after the delayed initialization in check() anyway. The type declaration without initialization trick will cause accidental uses of this field prior to full initialization to raise an AttributeError. (Note that it is valid to have an empty members list, see the internal q_empty object as an example. For this reason, we cannot use the empty list as a replacement test for full initialization and instead rely on the _checked/_checking fields.) Signed-off-by: John Snow --- scripts/qapi/schema.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index a459016e148..947e7efb1a8 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -20,7 +20,7 @@ from collections import OrderedDict import os import re -from typing import List, Optional +from typing import List, Optional, cast =20 from .common import ( POINTER_SUFFIX, @@ -457,7 +457,7 @@ def __init__(self, name, info, doc, ifcond, features, self.base =3D None self.local_members =3D local_members self.variants =3D variants - self.members =3D None + self.members: List[QAPISchemaObjectTypeMember] self._checking =3D False =20 def check(self, schema): @@ -474,7 +474,7 @@ def check(self, schema): =20 self._checking =3D True super().check(schema) - assert self._checked and self.members is None + assert self._checked =20 seen =3D OrderedDict() if self._base_name: @@ -491,7 +491,10 @@ def check(self, schema): for m in self.local_members: m.check(schema) m.check_clash(self.info, seen) - members =3D seen.values() + + # check_clash is abstract, but local_members is asserted to be + # List[QAPISchemaObjectTypeMember]. Cast to the narrower type. + members =3D cast(List[QAPISchemaObjectTypeMember], list(seen.value= s())) =20 if self.variants: self.variants.check(schema, seen) @@ -524,11 +527,9 @@ def is_implicit(self): return self.name.startswith('q_') =20 def is_empty(self): - assert self.members is not None return not self.members and not self.variants =20 def has_conditional_members(self): - assert self.members is not None return any(m.ifcond.is_present() for m in self.members) =20 def c_name(self): --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827433; cv=none; d=zohomail.com; s=zohoarc; b=XM/521k1LUT8qSVuPgiHhAZ4U5Rtuf0AZEa+gvBQpHBs2+h6AFWKS3EGA2JKmrXCBrbhLfJwlloTvsywpUDaQSNTZAdI2tSxBXpreNozdKBJLJYzstB1arIY7c5jeMQ4iwxbGdJeWVj7rGgDi/sU2m/riJNqhdQAhIISLTGzeBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827433; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=G33ZbhEZs6vFXQJ45Lk/8MDmwSyA8rS/gd6nzUQhhXI=; b=L6192D75oehOhFhXnWglL8Gid+IaaYLjELv4OT1nsEAj+Gq18bi0NQni5QVRxlI7ri+VQ0TsdL9ffAaZvbgEaidf6Nn8+rP1sK2COf1lYMTyH9OQ91ikzDS5pIxWyKzQZTjr7o6Qo+0AQRft2XWValgW185SfUTFySMHvXyNhvY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 170682743345793.32582678502217; Thu, 1 Feb 2024 14:43:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfmD-0006KE-1j; Thu, 01 Feb 2024 17:43:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfm6-0006Ef-3l for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:14 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflt-0006bg-0i for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:13 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-417-JlktmaN-MCuzED6Fwk9Tqg-1; Thu, 01 Feb 2024 17:42:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A08E1C0CCAD; Thu, 1 Feb 2024 22:42:54 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id D214F2166B33; Thu, 1 Feb 2024 22:42:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827379; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G33ZbhEZs6vFXQJ45Lk/8MDmwSyA8rS/gd6nzUQhhXI=; b=TJCK0pS75BF6dtGu6norBw5jFSYnj9diACkOqLSG3mrTxt+5K+nXvmbTrfkfbxiUm4fEce EhvvZXwe/h+CWH2zwfCfY2VyoBS8+BXee11JnVTBAt7RCIfAUMnRGIdG/4s02ixPLwk/eM sN6vseIG7D180UKAiXWYFocv89/YM60= X-MC-Unique: JlktmaN-MCuzED6Fwk9Tqg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 15/20] qapi/schema: fix typing for QAPISchemaVariants.tag_member Date: Thu, 1 Feb 2024 17:42:41 -0500 Message-ID: <20240201224246.39480-16-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827434111100009 Content-Type: text/plain; charset="utf-8" There are two related changes here: (1) We need to perform type narrowing for resolving the type of tag_member during check(), and (2) tag_member is a delayed initialization field, but we can hide it behind a property that raises an Exception if it's called too early. This simplifies the typing in quite a few places and avoids needing to assert that the "tag_member is not None" at a dozen callsites, which can be confusing and suggest the wrong thing to a drive-by contributor. Signed-off-by: John Snow --- scripts/qapi/schema.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 947e7efb1a8..7508e3a4fa6 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -635,25 +635,39 @@ def __init__(self, tag_name, info, tag_member, varian= ts): assert isinstance(v, QAPISchemaVariant) self._tag_name =3D tag_name self.info =3D info - self.tag_member =3D tag_member + self._tag_member: Optional[QAPISchemaObjectTypeMember] =3D tag_mem= ber self.variants =3D variants =20 + @property + def tag_member(self) -> 'QAPISchemaObjectTypeMember': + if self._tag_member is None: + raise RuntimeError( + "QAPISchemaVariants has no tag_member property until " + "after check() has been run." + ) + return self._tag_member + def set_defined_in(self, name): for v in self.variants: v.set_defined_in(name) =20 def check(self, schema, seen): if self._tag_name: # union - self.tag_member =3D seen.get(c_name(self._tag_name)) + # We need to narrow the member type: + tmp =3D seen.get(c_name(self._tag_name)) + assert tmp is None or isinstance(tmp, QAPISchemaObjectTypeMemb= er) + self._tag_member =3D tmp + base =3D "'base'" # Pointing to the base type when not implicit would be # nice, but we don't know it here - if not self.tag_member or self._tag_name !=3D self.tag_member.= name: + if not self._tag_member or self._tag_name !=3D self._tag_membe= r.name: raise QAPISemError( self.info, "discriminator '%s' is not a member of %s" % (self._tag_name, base)) # Here we do: + assert self.tag_member.defined_in base_type =3D schema.resolve_type(self.tag_member.defined_in) if not base_type.is_implicit(): base =3D "base type '%s'" % self.tag_member.defined_in @@ -673,11 +687,13 @@ def check(self, schema, seen): "discriminator member '%s' of %s must not be condition= al" % (self._tag_name, base)) else: # alternate + assert self._tag_member assert isinstance(self.tag_member.type, QAPISchemaEnumType) assert not self.tag_member.optional assert not self.tag_member.ifcond.is_present() if self._tag_name: # union # branches that are not explicitly covered get an empty type + assert self.tag_member.defined_in cases =3D {v.name for v in self.variants} for m in self.tag_member.type.members: if m.name not in cases: --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827447; cv=none; d=zohomail.com; s=zohoarc; b=cjPWfzSl5Sg3T2vRoBk42Kq5ZG3hmWkG7wKjTSq/fmulHcuCgWrR2TyS2jfm3AUsPYPANd9cH0yE8anhbvN+ZkpXFBPzYWP/6+zSumKtjxXeVxFsfZ4QDyXAaOOWaaf63TnqRNBHjgC6iemLmr3MXRqgJJTb6npPcon0dDGPFZ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827447; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yeKXRKiD4PalKsdlG978MYIDpwSEmB0ibmF0/Q5BleM=; b=X7pZ9im2de6LmYDrmk9TJzkLwOb/SR0HAPeSDXZmJNsWajcyLaLxfx7RvWvPARjF3cFaKHcDGiknzdMxayDvuRW5fM09k1Sli++7lmIF6vJT05e7WduntAnrbPAVmwNBSmVZo005LMSYKr8Aftf2QLiqLrudTjW5q3Cc0+xQYR0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827447471449.0147932780368; Thu, 1 Feb 2024 14:44:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm9-0006Ge-67; Thu, 01 Feb 2024 17:43:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfly-0006C4-6O for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfls-0006ah-VN for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:05 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-4_5XSYHcMP6CYBhFTVeMlg-1; Thu, 01 Feb 2024 17:42:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F396185A780; Thu, 1 Feb 2024 22:42:54 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 133292166B33; Thu, 1 Feb 2024 22:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827376; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yeKXRKiD4PalKsdlG978MYIDpwSEmB0ibmF0/Q5BleM=; b=awpqS8VgS/iRbIWq4T6wChJM39dvX3GuYz2NpF3STloRt5ykdpT+9fUREtfRF7QphOstMy uYZ6UJQJj6v5K727FCu3TE5oxsQn1OHUXBYL9CZbdhYtS8k5o2WgHZGTG8qfwzZssyvBH8 aKT35RtRtklvoXaz3F9Sgue/sbp+xok= X-MC-Unique: 4_5XSYHcMP6CYBhFTVeMlg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 16/20] qapi/schema: assert inner type of QAPISchemaVariants in check_clash() Date: Thu, 1 Feb 2024 17:42:42 -0500 Message-ID: <20240201224246.39480-17-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827448087100001 Content-Type: text/plain; charset="utf-8" QAPISchemaVariant's "variants" field is typed as List[QAPISchemaVariant], where the typing for QAPISchemaVariant allows its type field to be any QAPISchemaType. However, QAPISchemaVariant expects that all of its variants contain the narrower QAPISchemaObjectType. This relationship is enforced at runtime in QAPISchemaVariants.check(). This relationship is not embedded in the type system though, so QAPISchemaVariants.check_clash() needs to re-assert this property in order to call QAPISchemaVariant.type.check_clash(). Signed-off-by: John Snow --- scripts/qapi/schema.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 7508e3a4fa6..4d153b216c0 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -723,7 +723,10 @@ def check(self, schema, seen): def check_clash(self, info, seen): for v in self.variants: # Reset seen map for each variant, since qapi names from one - # branch do not affect another branch + # branch do not affect another branch. + # + # v.type's typing is enforced in check() above. + assert isinstance(v.type, QAPISchemaObjectType) v.type.check_clash(info, dict(seen)) =20 =20 --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827421; cv=none; d=zohomail.com; s=zohoarc; b=IGNPQ3DxaSzcZ98c1TI/DPHOJMpib+kgnz/ZcXNFpczSeJc3KkExv2+VpfJcalgxVIKh0oPA1pfjtE76Rb08nTRSO5PlpdXo+qNV5/bXFk/k1EGQiGZhfaoJx12cQr5CLvjYzzDIbmXPp0jwPHjs+70IbGIuwnQzc9ObqH3IBmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827421; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ZHW/xfDxwGY+AJpPrRMEpErgXJjBncKG/H3QZa9pVW8=; b=a4qQ9AckM1OUji0fHo6XEDP0ASIpwzqyxecjA1KlF6c5tAf6VIfwaU+nEKZxcIppqixxGd6/0Axe+teN3s4KgujmfhwclEoR/vON81o0qJDZP/+qlJagshgO/blVNI/mq3FkGk37zsL0npXJbuuoyjSCqlAoO0GKnOwDtYbDU1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827421741872.6337960558161; Thu, 1 Feb 2024 14:43:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm9-0006I0-Pc; Thu, 01 Feb 2024 17:43:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflx-0006C0-EV for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:07 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfls-0006au-6X for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:05 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-p2e3tL9zMxqdQ4JmjPm_Mw-1; Thu, 01 Feb 2024 17:42:54 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 72E358352A0; Thu, 1 Feb 2024 22:42:54 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47F122166B33; Thu, 1 Feb 2024 22:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827376; 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=ZHW/xfDxwGY+AJpPrRMEpErgXJjBncKG/H3QZa9pVW8=; b=Hib6GWcOK8rSNKLsVZOL/8H3VYgK7HfpOjEv5uTBqerATo4OBlghDWuzFSKzepHRgM+LV2 dMuO/GeBnRW3uJRisRUrv9SKOkoBytnBRVi7bgnEDkccHgjNVtU20dOB21+cSnsrZWYTWK 9EiE7MojFvioh3uDHqe7N5/fZcLx6OI= X-MC-Unique: p2e3tL9zMxqdQ4JmjPm_Mw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 17/20] qapi/parser: demote QAPIExpression to Dict[str, Any] Date: Thu, 1 Feb 2024 17:42:43 -0500 Message-ID: <20240201224246.39480-18-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827422339100002 Dict[str, object] is a stricter type, but with the way that code is currently arranged, it is infeasible to enforce this strictness. In particular, although expr.py's entire raison d'=C3=AAtre is normalization and type-checking of QAPI Expressions, that type information is not "remembered" in any meaningful way by mypy because each individual expression is not downcast to a specific expression type that holds all the details of each expression's unique form. As a result, all of the code in schema.py that deals with actually creating type-safe specialized structures has no guarantee (myopically) that the data it is being passed is correct. There are two ways to solve this: (1) Re-assert that the incoming data is in the shape we expect it to be, or (2) Disable type checking for this data. (1) is appealing to my sense of strictness, but I gotta concede that it is asinine to re-check the shape of a QAPIExpression in schema.py when expr.py has just completed that work at length. The duplication of code and the nightmare thought of needing to update both locations if and when we change the shape of these structures makes me extremely reluctant to go down this route. (2) allows us the chance to miss updating types in the case that types are updated in expr.py, but it *is* an awful lot simpler and, importantly, gets us closer to type checking schema.py *at all*. Something is better than nothing, I'd argue. So, do the simpler dumber thing and worry about future strictness improvements later. Signed-off-by: John Snow --- scripts/qapi/parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 48cd55a38cc..422de616a35 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -19,6 +19,7 @@ import re from typing import ( TYPE_CHECKING, + Any, Dict, List, Mapping, @@ -43,7 +44,7 @@ _ExprValue =3D Union[List[object], Dict[str, object], str, bool] =20 =20 -class QAPIExpression(Dict[str, object]): +class QAPIExpression(Dict[str, Any]): # pylint: disable=3Dtoo-few-public-methods def __init__(self, data: Mapping[str, object], --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827421; cv=none; d=zohomail.com; s=zohoarc; b=MzAYAC+f89U/d230+G5/HqQRcCiE5BvkjMyPc1heCWI6mIew8SRbrTb1NiPa4kr5HT39b/l/WLZtrbGKIFrV1chdsLaBWC9uztbfLPhZNyTKNZY1sFCJRHgWSZE8gey3pBAbWRvTjoNm/mZ7A/hyX2cydPlbCYGN1LZOBa+NFm8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827421; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=On/SA9nFdE39K910ykxOHaLDTvlkGV6N8L/mQHdc9zc=; b=AweLcmFH40xOnpwWzntAzQM1fGRwk9Ad5zEw6XZHlLgRzpGqSD5Rd2t7n77n9+BcuED+cdpHiMxAEqGyXBO772npPRQnIWTh8ad1rYuHdM91LAykfELcJfoQZimtYMRzZp1zsqZcvNrxAWf2CL+bV26KkbNy7x+uJTLi5FtXqWY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827421850997.8782689547778; Thu, 1 Feb 2024 14:43:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfmB-0006Id-45; Thu, 01 Feb 2024 17:43:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfm1-0006D0-1G for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfls-0006bT-Vd for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:08 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-UkNVmA0QOS6kuFc0zoGiLA-1; Thu, 01 Feb 2024 17:42:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3EC51C0CCA5; Thu, 1 Feb 2024 22:42:54 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D9202166B33; Thu, 1 Feb 2024 22:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=On/SA9nFdE39K910ykxOHaLDTvlkGV6N8L/mQHdc9zc=; b=FRJxpYf1ujAOZf69D4I0cgivQNUpQRIhcxGU+5mI1cXYcO7Kwl/OZ+AgxcGRQGj2No9z9+ I1R4NzOWgnvw2B2J0I7BZ7SosxbNWLhmuaZBGQ2HDGc5LmiwEQgCduO1H6KlbiS0F+CWvm OlhN06dUfw7mzu2WlOAmMK47l0CRWpw= X-MC-Unique: UkNVmA0QOS6kuFc0zoGiLA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 18/20] qapi/schema: add type hints Date: Thu, 1 Feb 2024 17:42:44 -0500 Message-ID: <20240201224246.39480-19-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827424065100011 Content-Type: text/plain; charset="utf-8" This patch only adds type hints, which aren't utilized at runtime and don't change the behavior of this module in any way. In a scant few locations, type hints are removed where no longer necessary due to inference power from typing all of the rest of creation; and any type hints that no longer need string quotes are changed. Signed-off-by: John Snow --- scripts/qapi/schema.py | 572 ++++++++++++++++++++++++++++------------- 1 file changed, 398 insertions(+), 174 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 4d153b216c0..319c8475d21 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -16,11 +16,21 @@ =20 # TODO catching name collisions in generated code would be nice =20 +from __future__ import annotations + from abc import ABC, abstractmethod from collections import OrderedDict import os import re -from typing import List, Optional, cast +from typing import ( + Any, + Callable, + Dict, + List, + Optional, + Union, + cast, +) =20 from .common import ( POINTER_SUFFIX, @@ -32,26 +42,30 @@ ) from .error import QAPIError, QAPISemError, QAPISourceError from .expr import check_exprs -from .parser import QAPIExpression, QAPISchemaParser +from .parser import QAPIDoc, QAPIExpression, QAPISchemaParser +from .source import QAPISourceInfo =20 =20 class QAPISchemaIfCond: - def __init__(self, ifcond=3DNone): + def __init__( + self, + ifcond: Optional[Union[str, Dict[str, object]]] =3D None, + ) -> None: self.ifcond =3D ifcond =20 - def _cgen(self): + def _cgen(self) -> str: return cgen_ifcond(self.ifcond) =20 - def gen_if(self): + def gen_if(self) -> str: return gen_if(self._cgen()) =20 - def gen_endif(self): + def gen_endif(self) -> str: return gen_endif(self._cgen()) =20 - def docgen(self): + def docgen(self) -> str: return docgen_ifcond(self.ifcond) =20 - def is_present(self): + def is_present(self) -> bool: return bool(self.ifcond) =20 =20 @@ -62,8 +76,8 @@ class QAPISchemaEntity: This is either a directive, such as include, or a definition. The latter uses sub-class `QAPISchemaDefinition`. """ - def __init__(self, info): - self._module =3D None + def __init__(self, info: Optional[QAPISourceInfo]): + self._module: Optional[QAPISchemaModule] =3D None # For explicitly defined entities, info points to the (explicit) # definition. For builtins (and their arrays), info is None. # For implicitly defined entities, info points to a place that @@ -72,37 +86,46 @@ def __init__(self, info): self.info =3D info self._checked =3D False =20 - def __repr__(self): + def __repr__(self) -> str: return "<%s at 0x%x>" % (type(self).__name__, id(self)) =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: # pylint: disable=3Dunused-argument self._checked =3D True =20 - def connect_doc(self, doc=3DNone): + def connect_doc(self, doc: Optional[QAPIDoc] =3D None) -> None: pass =20 - def check_doc(self): + def check_doc(self) -> None: pass =20 - def _set_module(self, schema, info): + def _set_module( + self, schema: QAPISchema, info: Optional[QAPISourceInfo] + ) -> None: assert self._checked fname =3D info.fname if info else QAPISchemaModule.BUILTIN_MODULE_= NAME self._module =3D schema.module_by_fname(fname) self._module.add_entity(self) =20 - def set_module(self, schema): + def set_module(self, schema: QAPISchema) -> None: self._set_module(schema, self.info) =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: # pylint: disable=3Dunused-argument assert self._checked =20 =20 class QAPISchemaDefinition(QAPISchemaEntity): - meta: Optional[str] =3D None + meta: str =20 - def __init__(self, name: str, info, doc, ifcond=3DNone, features=3DNon= e): + def __init__( + self, + name: str, + info: Optional[QAPISourceInfo], + doc: Optional[QAPIDoc], + ifcond: Optional[QAPISchemaIfCond] =3D None, + features: Optional[List[QAPISchemaFeature]] =3D None, + ): assert isinstance(name, str) super().__init__(info) for f in features or []: @@ -113,89 +136,147 @@ def __init__(self, name: str, info, doc, ifcond=3DNo= ne, features=3DNone): self._ifcond =3D ifcond or QAPISchemaIfCond() self.features =3D features or [] =20 - def __repr__(self): + def __repr__(self) -> str: return "<%s:%s at 0x%x>" % (type(self).__name__, self.name, id(self)) =20 - def c_name(self): + def c_name(self) -> str: return c_name(self.name) =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: assert not self._checked super().check(schema) - seen =3D {} + seen: Dict[str, QAPISchemaMember] =3D {} for f in self.features: f.check_clash(self.info, seen) =20 - def connect_doc(self, doc=3DNone): + def connect_doc(self, doc: Optional[QAPIDoc] =3D None) -> None: super().connect_doc(doc) doc =3D doc or self.doc if doc: for f in self.features: doc.connect_feature(f) =20 - def check_doc(self): + def check_doc(self) -> None: super().check_doc() if self.doc: self.doc.check() =20 @property - def ifcond(self): + def ifcond(self) -> QAPISchemaIfCond: assert self._checked return self._ifcond =20 - def is_implicit(self): + def is_implicit(self) -> bool: return not self.info =20 - def describe(self): + def describe(self) -> str: assert self.meta return "%s '%s'" % (self.meta, self.name) =20 =20 class QAPISchemaVisitor: - def visit_begin(self, schema): + def visit_begin(self, schema: QAPISchema) -> None: pass =20 - def visit_end(self): + def visit_end(self) -> None: pass =20 - def visit_module(self, name): + def visit_module(self, name: str) -> None: pass =20 - def visit_needed(self, entity): + def visit_needed(self, entity: QAPISchemaEntity) -> bool: # pylint: disable=3Dunused-argument # Default to visiting everything return True =20 - def visit_include(self, name, info): + def visit_include(self, name: str, info: Optional[QAPISourceInfo]) -> = None: pass =20 - def visit_builtin_type(self, name, info, json_type): + def visit_builtin_type( + self, name: str, info: Optional[QAPISourceInfo], json_type: str + ) -> None: pass =20 - def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): + def visit_enum_type( + self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + members: List[QAPISchemaEnumMember], + prefix: Optional[str], + ) -> None: pass =20 - def visit_array_type(self, name, info, ifcond, element_type): + def visit_array_type( + self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + element_type: QAPISchemaType, + ) -> None: pass =20 - def visit_object_type(self, name, info, ifcond, features, - base, members, variants): + def visit_object_type( + self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants], + ) -> None: pass =20 - def visit_object_type_flat(self, name, info, ifcond, features, - members, variants): + def visit_object_type_flat( + self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants], + ) -> None: pass =20 - def visit_alternate_type(self, name, info, ifcond, features, variants): + def visit_alternate_type( + self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + variants: QAPISchemaVariants, + ) -> None: pass =20 - def visit_command(self, name, info, ifcond, features, - arg_type, ret_type, gen, success_response, boxed, - allow_oob, allow_preconfig, coroutine): + def visit_command( + self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + 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: pass =20 - def visit_event(self, name, info, ifcond, features, arg_type, boxed): + def visit_event( + self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + arg_type: Optional[QAPISchemaObjectType], + boxed: bool, + ) -> None: pass =20 =20 @@ -203,9 +284,9 @@ class QAPISchemaModule: =20 BUILTIN_MODULE_NAME =3D './builtin' =20 - def __init__(self, name): + def __init__(self, name: str): self.name =3D name - self._entity_list =3D [] + self._entity_list: List[QAPISchemaEntity] =3D [] =20 @staticmethod def is_system_module(name: str) -> bool: @@ -234,10 +315,10 @@ def is_builtin_module(cls, name: str) -> bool: """ return name =3D=3D cls.BUILTIN_MODULE_NAME =20 - def add_entity(self, ent): + def add_entity(self, ent: QAPISchemaEntity) -> None: self._entity_list.append(ent) =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: visitor.visit_module(self.name) for entity in self._entity_list: if visitor.visit_needed(entity): @@ -245,11 +326,11 @@ def visit(self, visitor): =20 =20 class QAPISchemaInclude(QAPISchemaEntity): - def __init__(self, sub_module, info): + def __init__(self, sub_module: QAPISchemaModule, info: QAPISourceInfo): super().__init__(info) self._sub_module =3D sub_module =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: super().visit(visitor) visitor.visit_include(self._sub_module.name, self.info) =20 @@ -258,22 +339,22 @@ class QAPISchemaType(QAPISchemaDefinition, ABC): # Return the C type for common use. # For the types we commonly box, this is a pointer type. @abstractmethod - def c_type(self): + def c_type(self) -> str: pass =20 # Return the C type to be used in a parameter list. - def c_param_type(self): + def c_param_type(self) -> str: return self.c_type() =20 # Return the C type to be used where we suppress boxing. - def c_unboxed_type(self): + def c_unboxed_type(self) -> str: return self.c_type() =20 @abstractmethod - def json_type(self): + def json_type(self) -> str: pass =20 - def alternate_qtype(self): + def alternate_qtype(self) -> Optional[str]: json2qtype =3D { 'null': 'QTYPE_QNULL', 'string': 'QTYPE_QSTRING', @@ -285,17 +366,17 @@ def alternate_qtype(self): } return json2qtype.get(self.json_type()) =20 - def doc_type(self): + def doc_type(self) -> Optional[str]: if self.is_implicit(): return None return self.name =20 - def need_has_if_optional(self): + def need_has_if_optional(self) -> bool: # When FOO is a pointer, has_FOO =3D=3D !!FOO, i.e. has_FOO is red= undant. # Except for arrays; see QAPISchemaArrayType.need_has_if_optional(= ). return not self.c_type().endswith(POINTER_SUFFIX) =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: super().check(schema) for feat in self.features: if feat.is_special(): @@ -303,7 +384,7 @@ def check(self, schema): self.info, f"feature '{feat.name}' is not supported for types") =20 - def describe(self): + def describe(self) -> str: assert self.meta return "%s type '%s'" % (self.meta, self.name) =20 @@ -311,7 +392,7 @@ def describe(self): class QAPISchemaBuiltinType(QAPISchemaType): meta =3D 'built-in' =20 - def __init__(self, name, json_type, c_type): + def __init__(self, name: str, json_type: str, c_type: str): super().__init__(name, None, None) assert not c_type or isinstance(c_type, str) assert json_type in ('string', 'number', 'int', 'boolean', 'null', @@ -319,24 +400,24 @@ def __init__(self, name, json_type, c_type): self._json_type_name =3D json_type self._c_type_name =3D c_type =20 - def c_name(self): + def c_name(self) -> str: return self.name =20 - def c_type(self): + def c_type(self) -> str: return self._c_type_name =20 - def c_param_type(self): + def c_param_type(self) -> str: if self.name =3D=3D 'str': return 'const ' + self._c_type_name return self._c_type_name =20 - def json_type(self): + def json_type(self) -> str: return self._json_type_name =20 - def doc_type(self): + def doc_type(self) -> str: return self.json_type() =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: super().visit(visitor) visitor.visit_builtin_type(self.name, self.info, self.json_type()) =20 @@ -344,7 +425,16 @@ def visit(self, visitor): class QAPISchemaEnumType(QAPISchemaType): meta =3D 'enum' =20 - def __init__(self, name, info, doc, ifcond, features, members, prefix): + def __init__( + self, + name: str, + info: Optional[QAPISourceInfo], + doc: Optional[QAPIDoc], + ifcond: Optional[QAPISchemaIfCond], + features: Optional[List[QAPISchemaFeature]], + members: List[QAPISchemaEnumMember], + prefix: Optional[str], + ): super().__init__(name, info, doc, ifcond, features) for m in members: assert isinstance(m, QAPISchemaEnumMember) @@ -353,32 +443,32 @@ def __init__(self, name, info, doc, ifcond, features,= members, prefix): self.members =3D members self.prefix =3D prefix =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: super().check(schema) - seen =3D {} + seen: Dict[str, QAPISchemaMember] =3D {} for m in self.members: m.check_clash(self.info, seen) =20 - def connect_doc(self, doc=3DNone): + def connect_doc(self, doc: Optional[QAPIDoc] =3D None) -> None: super().connect_doc(doc) doc =3D doc or self.doc for m in self.members: m.connect_doc(doc) =20 - def is_implicit(self): + def is_implicit(self) -> bool: # See QAPISchema._def_predefineds() return self.name =3D=3D 'QType' =20 - def c_type(self): + def c_type(self) -> str: return c_name(self.name) =20 - def member_names(self): + def member_names(self) -> List[str]: return [m.name for m in self.members] =20 - def json_type(self): + def json_type(self) -> str: return 'string' =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: super().visit(visitor) visitor.visit_enum_type( self.name, self.info, self.ifcond, self.features, @@ -388,60 +478,71 @@ def visit(self, visitor): class QAPISchemaArrayType(QAPISchemaType): meta =3D 'array' =20 - def __init__(self, name, info, element_type): + def __init__( + self, name: str, info: Optional[QAPISourceInfo], element_type: str + ): super().__init__(name, info, None) assert isinstance(element_type, str) self._element_type_name =3D element_type self.element_type: QAPISchemaType =20 - def need_has_if_optional(self): + def need_has_if_optional(self) -> bool: # When FOO is an array, we still need has_FOO to distinguish # absent (!has_FOO) from present and empty (has_FOO && !FOO). return True =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: super().check(schema) self.element_type =3D schema.resolve_type( self._element_type_name, self.info, self.info.defn_meta if self.info else None) assert not isinstance(self.element_type, QAPISchemaArrayType) =20 - def set_module(self, schema): + def set_module(self, schema: QAPISchema) -> None: self._set_module(schema, self.element_type.info) =20 @property - def ifcond(self): + def ifcond(self) -> QAPISchemaIfCond: assert self._checked return self.element_type.ifcond =20 - def is_implicit(self): + def is_implicit(self) -> bool: return True =20 - def c_type(self): + def c_type(self) -> str: return c_name(self.name) + POINTER_SUFFIX =20 - def json_type(self): + def json_type(self) -> str: return 'array' =20 - def doc_type(self): + def doc_type(self) -> Optional[str]: elt_doc_type =3D self.element_type.doc_type() if not elt_doc_type: return None return 'array of ' + elt_doc_type =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: super().visit(visitor) visitor.visit_array_type(self.name, self.info, self.ifcond, self.element_type) =20 - def describe(self): + def describe(self) -> str: assert self.meta return "%s type ['%s']" % (self.meta, self._element_type_name) =20 =20 class QAPISchemaObjectType(QAPISchemaType): - def __init__(self, name, info, doc, ifcond, features, - base, local_members, variants): + def __init__( + self, + name: str, + info: Optional[QAPISourceInfo], + doc: Optional[QAPIDoc], + ifcond: Optional[QAPISchemaIfCond], + features: Optional[List[QAPISchemaFeature]], + base: Optional[str], + local_members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants], + ): # struct has local_members, optional base, and no variants # union has base, variants, and no local_members super().__init__(name, info, doc, ifcond, features) @@ -460,7 +561,7 @@ def __init__(self, name, info, doc, ifcond, features, self.members: List[QAPISchemaObjectTypeMember] self._checking =3D False =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: # This calls another type T's .check() exactly when the C # struct emitted by gen_object() contains that T's C struct # (pointers don't count). @@ -506,14 +607,18 @@ def check(self, schema): # Check that the members of this type do not cause duplicate JSON memb= ers, # and update seen to track the members seen so far. Report any errors # on behalf of info, which is not necessarily self.info - def check_clash(self, info, seen): + def check_clash( + self, + info: Optional[QAPISourceInfo], + seen: Dict[str, QAPISchemaMember], + ) -> None: assert self._checked for m in self.members: m.check_clash(info, seen) if self.variants: self.variants.check_clash(info, seen) =20 - def connect_doc(self, doc=3DNone): + def connect_doc(self, doc: Optional[QAPIDoc] =3D None) -> None: super().connect_doc(doc) doc =3D doc or self.doc if self.base and self.base.is_implicit(): @@ -521,32 +626,32 @@ def connect_doc(self, doc=3DNone): for m in self.local_members: m.connect_doc(doc) =20 - def is_implicit(self): + def is_implicit(self) -> bool: # See QAPISchema._make_implicit_object_type(), as well as # _def_predefineds() return self.name.startswith('q_') =20 - def is_empty(self): + def is_empty(self) -> bool: return not self.members and not self.variants =20 - def has_conditional_members(self): + def has_conditional_members(self) -> bool: return any(m.ifcond.is_present() for m in self.members) =20 - def c_name(self): + def c_name(self) -> str: assert self.name !=3D 'q_empty' return super().c_name() =20 - def c_type(self): + def c_type(self) -> str: assert not self.is_implicit() return c_name(self.name) + POINTER_SUFFIX =20 - def c_unboxed_type(self): + def c_unboxed_type(self) -> str: return c_name(self.name) =20 - def json_type(self): + def json_type(self) -> str: return 'object' =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: super().visit(visitor) visitor.visit_object_type( self.name, self.info, self.ifcond, self.features, @@ -559,7 +664,15 @@ def visit(self, visitor): class QAPISchemaAlternateType(QAPISchemaType): meta =3D 'alternate' =20 - def __init__(self, name, info, doc, ifcond, features, variants): + def __init__( + self, + name: str, + info: QAPISourceInfo, + doc: Optional[QAPIDoc], + ifcond: Optional[QAPISchemaIfCond], + features: List[QAPISchemaFeature], + variants: QAPISchemaVariants, + ): super().__init__(name, info, doc, ifcond, features) assert isinstance(variants, QAPISchemaVariants) assert variants.tag_member @@ -567,7 +680,7 @@ def __init__(self, name, info, doc, ifcond, features, v= ariants): variants.tag_member.set_defined_in(self.name) self.variants =3D variants =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: super().check(schema) self.variants.tag_member.check(schema) # Not calling self.variants.check_clash(), because there's nothing @@ -575,8 +688,8 @@ def check(self, schema): self.variants.check(schema, {}) # Alternate branch names have no relation to the tag enum values; # so we have to check for potential name collisions ourselves. - seen =3D {} - types_seen =3D {} + seen: Dict[str, QAPISchemaMember] =3D {} + types_seen: Dict[str, str] =3D {} for v in self.variants.variants: v.check_clash(self.info, seen) qtype =3D v.type.alternate_qtype() @@ -605,26 +718,32 @@ def check(self, schema): % (v.describe(self.info), types_seen[qt])) types_seen[qt] =3D v.name =20 - def connect_doc(self, doc=3DNone): + def connect_doc(self, doc: Optional[QAPIDoc] =3D None) -> None: super().connect_doc(doc) doc =3D doc or self.doc for v in self.variants.variants: v.connect_doc(doc) =20 - def c_type(self): + def c_type(self) -> str: return c_name(self.name) + POINTER_SUFFIX =20 - def json_type(self): + def json_type(self) -> str: return 'value' =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: super().visit(visitor) visitor.visit_alternate_type( self.name, self.info, self.ifcond, self.features, self.variant= s) =20 =20 class QAPISchemaVariants: - def __init__(self, tag_name, info, tag_member, variants): + def __init__( + self, + tag_name: Optional[str], + info: QAPISourceInfo, + tag_member: Optional[QAPISchemaObjectTypeMember], + variants: List[QAPISchemaVariant], + ): # Unions pass tag_name but not tag_member. # Alternates pass tag_member but not tag_name. # After check(), tag_member is always set. @@ -635,11 +754,11 @@ def __init__(self, tag_name, info, tag_member, varian= ts): assert isinstance(v, QAPISchemaVariant) self._tag_name =3D tag_name self.info =3D info - self._tag_member: Optional[QAPISchemaObjectTypeMember] =3D tag_mem= ber + self._tag_member =3D tag_member self.variants =3D variants =20 @property - def tag_member(self) -> 'QAPISchemaObjectTypeMember': + def tag_member(self) -> QAPISchemaObjectTypeMember: if self._tag_member is None: raise RuntimeError( "QAPISchemaVariants has no tag_member property until " @@ -647,11 +766,13 @@ def tag_member(self) -> 'QAPISchemaObjectTypeMember': ) return self._tag_member =20 - def set_defined_in(self, name): + def set_defined_in(self, name: str) -> None: for v in self.variants: v.set_defined_in(name) =20 - def check(self, schema, seen): + def check( + self, schema: QAPISchema, seen: Dict[str, QAPISchemaMember] + ) -> None: if self._tag_name: # union # We need to narrow the member type: tmp =3D seen.get(c_name(self._tag_name)) @@ -720,7 +841,11 @@ def check(self, schema, seen): % (v.describe(self.info), v.type.describe())) v.type.check(schema) =20 - def check_clash(self, info, seen): + def check_clash( + self, + info: Optional[QAPISourceInfo], + seen: Dict[str, QAPISchemaMember], + ) -> None: for v in self.variants: # Reset seen map for each variant, since qapi names from one # branch do not affect another branch. @@ -734,18 +859,27 @@ class QAPISchemaMember: """ Represents object members, enum members and features """ role =3D 'member' =20 - def __init__(self, name, info, ifcond=3DNone): + def __init__( + self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: Optional[QAPISchemaIfCond] =3D None, + ): assert isinstance(name, str) self.name =3D name self.info =3D info self.ifcond =3D ifcond or QAPISchemaIfCond() - self.defined_in =3D None + self.defined_in: Optional[str] =3D None =20 - def set_defined_in(self, name): + def set_defined_in(self, name: str) -> None: assert not self.defined_in self.defined_in =3D name =20 - def check_clash(self, info, seen): + def check_clash( + self, + info: Optional[QAPISourceInfo], + seen: Dict[str, QAPISchemaMember], + ) -> None: cname =3D c_name(self.name) if cname in seen: raise QAPISemError( @@ -754,11 +888,11 @@ def check_clash(self, info, seen): % (self.describe(info), seen[cname].describe(info))) seen[cname] =3D self =20 - def connect_doc(self, doc): + def connect_doc(self, doc: Optional[QAPIDoc]) -> None: if doc: doc.connect_member(self) =20 - def describe(self, info): + def describe(self, info: Optional[QAPISourceInfo]) -> str: role =3D self.role meta =3D 'type' defined_in =3D self.defined_in @@ -790,14 +924,20 @@ def describe(self, info): class QAPISchemaEnumMember(QAPISchemaMember): role =3D 'value' =20 - def __init__(self, name, info, ifcond=3DNone, features=3DNone): + def __init__( + self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: Optional[QAPISchemaIfCond] =3D None, + features: Optional[List[QAPISchemaFeature]] =3D None, + ): super().__init__(name, info, ifcond) for f in features or []: assert isinstance(f, QAPISchemaFeature) f.set_defined_in(name) self.features =3D features or [] =20 - def connect_doc(self, doc): + def connect_doc(self, doc: Optional[QAPIDoc]) -> None: super().connect_doc(doc) if doc: for f in self.features: @@ -807,12 +947,20 @@ def connect_doc(self, doc): class QAPISchemaFeature(QAPISchemaMember): role =3D 'feature' =20 - def is_special(self): + def is_special(self) -> bool: return self.name in ('deprecated', 'unstable') =20 =20 class QAPISchemaObjectTypeMember(QAPISchemaMember): - def __init__(self, name, info, typ, optional, ifcond=3DNone, features= =3DNone): + def __init__( + self, + name: str, + info: QAPISourceInfo, + typ: str, + optional: bool, + ifcond: Optional[QAPISchemaIfCond] =3D None, + features: Optional[List[QAPISchemaFeature]] =3D None, + ): super().__init__(name, info, ifcond) assert isinstance(typ, str) assert isinstance(optional, bool) @@ -824,19 +972,19 @@ def __init__(self, name, info, typ, optional, ifcond= =3DNone, features=3DNone): self.optional =3D optional self.features =3D features or [] =20 - def need_has(self): + def need_has(self) -> bool: assert self.type return self.optional and self.type.need_has_if_optional() =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: assert self.defined_in self.type =3D schema.resolve_type(self._type_name, self.info, self.describe) - seen =3D {} + seen: Dict[str, QAPISchemaMember] =3D {} for f in self.features: f.check_clash(self.info, seen) =20 - def connect_doc(self, doc): + def connect_doc(self, doc: Optional[QAPIDoc]) -> None: super().connect_doc(doc) if doc: for f in self.features: @@ -846,24 +994,42 @@ def connect_doc(self, doc): class QAPISchemaVariant(QAPISchemaObjectTypeMember): role =3D 'branch' =20 - def __init__(self, name, info, typ, ifcond=3DNone): + def __init__( + self, + name: str, + info: QAPISourceInfo, + typ: str, + ifcond: QAPISchemaIfCond, + ): super().__init__(name, info, typ, False, ifcond) =20 =20 class QAPISchemaCommand(QAPISchemaDefinition): meta =3D 'command' =20 - def __init__(self, name, info, doc, ifcond, features, - arg_type, ret_type, - gen, success_response, boxed, allow_oob, allow_preconfig, - coroutine): + def __init__( + self, + name: str, + info: QAPISourceInfo, + doc: Optional[QAPIDoc], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + arg_type: Optional[str], + ret_type: Optional[str], + gen: bool, + success_response: bool, + boxed: bool, + allow_oob: bool, + allow_preconfig: bool, + coroutine: bool, + ): super().__init__(name, info, doc, ifcond, features) assert not arg_type or isinstance(arg_type, str) assert not ret_type or isinstance(ret_type, str) self._arg_type_name =3D arg_type - self.arg_type =3D None + self.arg_type: Optional[QAPISchemaObjectType] =3D None self._ret_type_name =3D ret_type - self.ret_type =3D None + self.ret_type: Optional[QAPISchemaType] =3D None self.gen =3D gen self.success_response =3D success_response self.boxed =3D boxed @@ -871,7 +1037,7 @@ def __init__(self, name, info, doc, ifcond, features, self.allow_preconfig =3D allow_preconfig self.coroutine =3D coroutine =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: assert self.info is not None super().check(schema) if self._arg_type_name: @@ -907,14 +1073,14 @@ def check(self, schema): "command's 'returns' cannot take %s" % self.ret_type.describe()) =20 - def connect_doc(self, doc=3DNone): + def connect_doc(self, doc: Optional[QAPIDoc] =3D None) -> None: super().connect_doc(doc) doc =3D doc or self.doc if doc: if self.arg_type and self.arg_type.is_implicit(): self.arg_type.connect_doc(doc) =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: super().visit(visitor) visitor.visit_command( self.name, self.info, self.ifcond, self.features, @@ -926,14 +1092,23 @@ def visit(self, visitor): class QAPISchemaEvent(QAPISchemaDefinition): meta =3D 'event' =20 - def __init__(self, name, info, doc, ifcond, features, arg_type, boxed): + def __init__( + self, + name: str, + info: QAPISourceInfo, + doc: Optional[QAPIDoc], + ifcond: QAPISchemaIfCond, + features: List[QAPISchemaFeature], + arg_type: Optional[str], + boxed: bool, + ): super().__init__(name, info, doc, ifcond, features) assert not arg_type or isinstance(arg_type, str) self._arg_type_name =3D arg_type - self.arg_type =3D None + self.arg_type: Optional[QAPISchemaObjectType] =3D None self.boxed =3D boxed =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: super().check(schema) if self._arg_type_name: typ =3D schema.resolve_type( @@ -955,14 +1130,14 @@ def check(self, schema): self.info, "conditional event arguments require 'boxed': true") =20 - def connect_doc(self, doc=3DNone): + def connect_doc(self, doc: Optional[QAPIDoc] =3D None) -> None: super().connect_doc(doc) doc =3D doc or self.doc if doc: if self.arg_type and self.arg_type.is_implicit(): self.arg_type.connect_doc(doc) =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: super().visit(visitor) visitor.visit_event( self.name, self.info, self.ifcond, self.features, @@ -970,7 +1145,7 @@ def visit(self, visitor): =20 =20 class QAPISchema: - def __init__(self, fname): + def __init__(self, fname: str): self.fname =3D fname =20 try: @@ -982,9 +1157,9 @@ def __init__(self, fname): =20 exprs =3D check_exprs(parser.exprs) self.docs =3D parser.docs - self._entity_list =3D [] - self._entity_dict =3D {} - self._module_dict =3D OrderedDict() + self._entity_list: List[QAPISchemaEntity] =3D [] + self._entity_dict: Dict[str, QAPISchemaDefinition] =3D {} + self._module_dict: Dict[str, QAPISchemaModule] =3D OrderedDict() self._schema_dir =3D os.path.dirname(fname) self._make_module(QAPISchemaModule.BUILTIN_MODULE_NAME) self._make_module(fname) @@ -994,10 +1169,10 @@ def __init__(self, fname): self._def_exprs(exprs) self.check() =20 - def _def_entity(self, ent): + def _def_entity(self, ent: QAPISchemaEntity) -> None: self._entity_list.append(ent) =20 - def _def_definition(self, defn): + def _def_definition(self, defn: QAPISchemaDefinition) -> None: # Only the predefined types are allowed to not have info assert defn.info or self._predefining self._def_entity(defn) @@ -1014,18 +1189,27 @@ def _def_definition(self, defn): defn.info, "%s is already defined" % other_defn.describe()) self._entity_dict[defn.name] =3D defn =20 - def lookup_entity(self, name, typ=3DNone): + def lookup_entity( + self, + name: str, + typ: Optional[type] =3D None, + ) -> Optional[QAPISchemaEntity]: ent =3D self._entity_dict.get(name) if typ and not isinstance(ent, typ): return None return ent =20 - def lookup_type(self, name): + def lookup_type(self, name: str) -> Optional[QAPISchemaType]: typ =3D self.lookup_entity(name, QAPISchemaType) assert typ is None or isinstance(typ, QAPISchemaType) return typ =20 - def resolve_type(self, name, info=3DNone, what=3DNone): + def resolve_type( + self, + name: str, + info: Optional[QAPISourceInfo] =3D None, + what: Union[None, str, Callable[[QAPISourceInfo], str]] =3D None, + ) -> QAPISchemaType: typ =3D self.lookup_type(name) if not typ: assert info and what # built-in types must not fail lookup @@ -1040,23 +1224,25 @@ def _module_name(self, fname: str) -> str: return fname return os.path.relpath(fname, self._schema_dir) =20 - def _make_module(self, fname): + def _make_module(self, fname: str) -> QAPISchemaModule: name =3D self._module_name(fname) if name not in self._module_dict: self._module_dict[name] =3D QAPISchemaModule(name) return self._module_dict[name] =20 - def module_by_fname(self, fname): + def module_by_fname(self, fname: str) -> QAPISchemaModule: name =3D self._module_name(fname) return self._module_dict[name] =20 - def _def_include(self, expr: QAPIExpression): + def _def_include(self, expr: QAPIExpression) -> None: include =3D expr['include'] assert expr.doc is None self._def_entity( QAPISchemaInclude(self._make_module(include), expr.info)) =20 - def _def_builtin_type(self, name, json_type, c_type): + def _def_builtin_type( + self, name: str, json_type: str, c_type: str + ) -> None: self._def_definition(QAPISchemaBuiltinType(name, json_type, c_type= )) # Instantiating only the arrays that are actually used would # be nice, but we can't as long as their generated code @@ -1064,7 +1250,7 @@ def _def_builtin_type(self, name, json_type, c_type): # schema. self._make_array_type(name, None) =20 - def _def_predefineds(self): + def _def_predefineds(self) -> None: for t in [('str', 'string', 'char' + POINTER_SUFFIX), ('number', 'number', 'double'), ('int', 'int', 'int64_t'), @@ -1093,31 +1279,52 @@ def _def_predefineds(self): self._def_definition(QAPISchemaEnumType( 'QType', None, None, None, None, qtype_values, 'QTYPE')) =20 - def _make_features(self, features, info): + def _make_features( + self, + features: Optional[List[Dict[str, Any]]], + info: Optional[QAPISourceInfo], + ) -> List[QAPISchemaFeature]: if features is None: return [] return [QAPISchemaFeature(f['name'], info, QAPISchemaIfCond(f.get('if'))) for f in features] =20 - def _make_enum_member(self, name, ifcond, features, info): + def _make_enum_member( + self, + name: str, + ifcond: Optional[Union[str, Dict[str, Any]]], + features: Optional[List[Dict[str, Any]]], + info: Optional[QAPISourceInfo], + ) -> QAPISchemaEnumMember: return QAPISchemaEnumMember(name, info, QAPISchemaIfCond(ifcond), self._make_features(features, info)) =20 - def _make_enum_members(self, values, info): + def _make_enum_members( + self, values: List[Dict[str, Any]], info: Optional[QAPISourceInfo] + ) -> List[QAPISchemaEnumMember]: return [self._make_enum_member(v['name'], v.get('if'), v.get('features'), info) for v in values] =20 - def _make_array_type(self, element_type, info): + def _make_array_type( + self, element_type: str, info: Optional[QAPISourceInfo] + ) -> str: name =3D element_type + 'List' # reserved by check_defn_name_st= r() if not self.lookup_type(name): self._def_definition(QAPISchemaArrayType( name, info, element_type)) return name =20 - def _make_implicit_object_type(self, name, info, ifcond, role, members= ): + def _make_implicit_object_type( + self, + name: str, + info: QAPISourceInfo, + ifcond: QAPISchemaIfCond, + role: str, + members: List[QAPISchemaObjectTypeMember], + ) -> Optional[str]: if not members: return None # See also QAPISchemaObjectTypeMember.describe() @@ -1133,7 +1340,7 @@ def _make_implicit_object_type(self, name, info, ifco= nd, role, members): name, info, None, ifcond, None, None, members, None)) return name =20 - def _def_enum_type(self, expr: QAPIExpression): + def _def_enum_type(self, expr: QAPIExpression) -> None: name =3D expr['enum'] data =3D expr['data'] prefix =3D expr.get('prefix') @@ -1144,7 +1351,14 @@ def _def_enum_type(self, expr: QAPIExpression): name, info, expr.doc, ifcond, features, self._make_enum_members(data, info), prefix)) =20 - def _make_member(self, name, typ, ifcond, features, info): + def _make_member( + self, + name: str, + typ: Union[List[str], str], + ifcond: QAPISchemaIfCond, + features: Optional[List[Dict[str, Any]]], + info: QAPISourceInfo, + ) -> QAPISchemaObjectTypeMember: optional =3D False if name.startswith('*'): name =3D name[1:] @@ -1155,13 +1369,17 @@ def _make_member(self, name, typ, ifcond, features,= info): return QAPISchemaObjectTypeMember(name, info, typ, optional, ifcon= d, self._make_features(features, in= fo)) =20 - def _make_members(self, data, info): + def _make_members( + self, + data: Dict[str, Any], + info: QAPISourceInfo, + ) -> List[QAPISchemaObjectTypeMember]: return [self._make_member(key, value['type'], QAPISchemaIfCond(value.get('if')), value.get('features'), info) for (key, value) in data.items()] =20 - def _def_struct_type(self, expr: QAPIExpression): + def _def_struct_type(self, expr: QAPIExpression) -> None: name =3D expr['struct'] base =3D expr.get('base') data =3D expr['data'] @@ -1173,13 +1391,19 @@ def _def_struct_type(self, expr: QAPIExpression): self._make_members(data, info), None)) =20 - def _make_variant(self, case, typ, ifcond, info): + def _make_variant( + self, + case: str, + typ: str, + ifcond: QAPISchemaIfCond, + info: QAPISourceInfo, + ) -> QAPISchemaVariant: if isinstance(typ, list): assert len(typ) =3D=3D 1 typ =3D self._make_array_type(typ[0], info) return QAPISchemaVariant(case, info, typ, ifcond) =20 - def _def_union_type(self, expr: QAPIExpression): + def _def_union_type(self, expr: QAPIExpression) -> None: name =3D expr['union'] base =3D expr['base'] tag_name =3D expr['discriminator'] @@ -1204,7 +1428,7 @@ def _def_union_type(self, expr: QAPIExpression): QAPISchemaVariants( tag_name, info, None, variants))) =20 - def _def_alternate_type(self, expr: QAPIExpression): + def _def_alternate_type(self, expr: QAPIExpression) -> None: name =3D expr['alternate'] data =3D expr['data'] assert isinstance(data, dict) @@ -1222,7 +1446,7 @@ def _def_alternate_type(self, expr: QAPIExpression): name, info, expr.doc, ifcond, features, QAPISchemaVariants(None, info, tag_member, variants))) =20 - def _def_command(self, expr: QAPIExpression): + def _def_command(self, expr: QAPIExpression) -> None: name =3D expr['command'] data =3D expr.get('data') rets =3D expr.get('returns') @@ -1247,7 +1471,7 @@ def _def_command(self, expr: QAPIExpression): rets, gen, success_response, boxed, allow_oo= b, allow_preconfig, coroutine)) =20 - def _def_event(self, expr: QAPIExpression): + def _def_event(self, expr: QAPIExpression) -> None: name =3D expr['event'] data =3D expr.get('data') boxed =3D expr.get('boxed', False) @@ -1261,7 +1485,7 @@ def _def_event(self, expr: QAPIExpression): self._def_definition(QAPISchemaEvent(name, info, expr.doc, ifcond, features, data, boxed)) =20 - def _def_exprs(self, exprs): + def _def_exprs(self, exprs: List[QAPIExpression]) -> None: for expr in exprs: if 'enum' in expr: self._def_enum_type(expr) @@ -1280,7 +1504,7 @@ def _def_exprs(self, exprs): else: assert False =20 - def check(self): + def check(self) -> None: for ent in self._entity_list: ent.check(self) ent.connect_doc() @@ -1288,7 +1512,7 @@ def check(self): for ent in self._entity_list: ent.set_module(self) =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: visitor.visit_begin(self) for mod in self._module_dict.values(): mod.visit(visitor) --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827437; cv=none; d=zohomail.com; s=zohoarc; b=K+IGm7MEReKA2a7CZXLm5eAIj4I6whl8pXxAy/J+2Z8/YpFzoZnjNDJ7OSxVuvUh0/vbuzehO5ZQO9ij4jOl3jjKoPzc0wYlZmoAhcJsjeHMw7daO07CyQvOjH8kTPjWCVZ+0YqSiirsGQh/A9VdUXfr2fqBGXc4iCFrY5Euva8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827437; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=n6DrBFzsG9tuqowYat1SKwrOUO/n6CWb/c7mC6GUZBs=; b=eWGki1D/UjYrXJGEE7QUcgzyqBVQ1HOD4MyXD8HbfMJjmSboH8/bcB51F5O3gO6L7QyWt+eGedba0PiUXHe11SywXtkTTP++ncMBi+xIrFijPPbKglXvi9NochPqmfBsYtqGcquK8LSvGxD5psFAJULS9+v+0pcBXdSbTMRSz3w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827437577162.74640985210294; Thu, 1 Feb 2024 14:43:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfmA-0006IX-E7; Thu, 01 Feb 2024 17:43:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfm0-0006CD-8V for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfls-0006bR-Vm for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:07 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-483-04DCXoSrOMqAAQZqT-oe-g-1; Thu, 01 Feb 2024 17:42:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7FFB84AC63; Thu, 1 Feb 2024 22:42:54 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD2C12166B34; Thu, 1 Feb 2024 22:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=n6DrBFzsG9tuqowYat1SKwrOUO/n6CWb/c7mC6GUZBs=; b=SkzlBDwgXpb+eBUPWHijnGV+B6qDqG+I1nl0em7pLWsw9XEAmQK+2cixiO+2wK1Gvc4Yj9 TTW1OS5rI0BS+PP/lthj2MHFhUR4a7Sp89etBBUYoiP17zPjwjRkigyOEnS8IS3g0dmEHj Zh6Oxez3PEQmWibOZyjT0foPSAcx7Go= X-MC-Unique: 04DCXoSrOMqAAQZqT-oe-g-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 19/20] qapi/schema: turn on mypy strictness Date: Thu, 1 Feb 2024 17:42:45 -0500 Message-ID: <20240201224246.39480-20-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827438043100001 Content-Type: text/plain; charset="utf-8" This patch can be rolled in with the previous one once the series is ready for merge, but for work-in-progress' sake, it's separate here. Signed-off-by: John Snow --- scripts/qapi/mypy.ini | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 56e0dfb1327..8109470a031 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -2,8 +2,3 @@ strict =3D True disallow_untyped_calls =3D False python_version =3D 3.8 - -[mypy-qapi.schema] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False --=20 2.43.0 From nobody Tue May 14 04:06:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1706827467; cv=none; d=zohomail.com; s=zohoarc; b=VM8dHxrbjT0vYWBiiw7jo7rlBK8NDhdl9hivESkzi+7xtYK5DMEICrXbwotxbOKWB3xNiFYeuYf27u/CvB1wtHRHvfghN5mqJ9TsdCh1lhxEUu25fr6rww55tGQip7UxlO5pWqDnsv0PVrqzLNMCxkh365JH6Z2HljOBtMKvi1k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706827467; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KsECITj15TACBp2Fp9ZkIZ9wo/qVpoauC9bxdheuxzQ=; b=LCAf1xU998VhmbM3GfFxGq6rVZtekKlmWDKVsinZSKUAcQpA1niHTsUa5xXZxBf5a92TzIXM4hXS10Du7jEanorjT+QFVi8cesQ4KkHPnXKMvORqadk3BeJhQerwjIFBkDUkZh/WvVI6vwGGjgiZHVtM8njVFxjB4RVx2heG07M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1706827467341459.54469623555644; Thu, 1 Feb 2024 14:44:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfm5-0006EJ-Up; Thu, 01 Feb 2024 17:43:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfm0-0006Cz-PD for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflt-0006bV-0F for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:08 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-694-WMz44NUjNmmruqRVOPa9eA-1; Thu, 01 Feb 2024 17:42:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B79588D581; Thu, 1 Feb 2024 22:42:55 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2C702166B33; Thu, 1 Feb 2024 22:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827378; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KsECITj15TACBp2Fp9ZkIZ9wo/qVpoauC9bxdheuxzQ=; b=AmqaOEqPu5HGnNeJJYIxxFfr3k+5ltwlDC/U6G02M8mp8MOTSXDuVS8Tr2LXTqog829yz9 uLtz9xGvcQdnhraB3rKlAPrVqkw5TJjN0o4xxzVhMuHm/Ts8aAqDaAJ3VrauhIgjzlv9Lg blDCiq9pfoX54+jgTVYvPzBsZfzrI/w= X-MC-Unique: WMz44NUjNmmruqRVOPa9eA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 20/20] qapi/schema: remove unnecessary asserts Date: Thu, 1 Feb 2024 17:42:46 -0500 Message-ID: <20240201224246.39480-21-jsnow@redhat.com> In-Reply-To: <20240201224246.39480-1-jsnow@redhat.com> References: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1706827468236100002 Content-Type: text/plain; charset="utf-8" With strict typing enabled, these runtime statements aren't necessary anymore; we can prove them statically. Signed-off-by: John Snow --- scripts/qapi/schema.py | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 319c8475d21..fb0c5d6e2c6 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -126,10 +126,8 @@ def __init__( ifcond: Optional[QAPISchemaIfCond] =3D None, features: Optional[List[QAPISchemaFeature]] =3D None, ): - assert isinstance(name, str) super().__init__(info) for f in features or []: - assert isinstance(f, QAPISchemaFeature) f.set_defined_in(name) self.name =3D name self.doc =3D doc @@ -171,7 +169,6 @@ def is_implicit(self) -> bool: return not self.info =20 def describe(self) -> str: - assert self.meta return "%s '%s'" % (self.meta, self.name) =20 =20 @@ -385,7 +382,6 @@ def check(self, schema: QAPISchema) -> None: f"feature '{feat.name}' is not supported for types") =20 def describe(self) -> str: - assert self.meta return "%s type '%s'" % (self.meta, self.name) =20 =20 @@ -394,7 +390,6 @@ class QAPISchemaBuiltinType(QAPISchemaType): =20 def __init__(self, name: str, json_type: str, c_type: str): super().__init__(name, None, None) - assert not c_type or isinstance(c_type, str) assert json_type in ('string', 'number', 'int', 'boolean', 'null', 'value') self._json_type_name =3D json_type @@ -437,9 +432,7 @@ def __init__( ): super().__init__(name, info, doc, ifcond, features) for m in members: - assert isinstance(m, QAPISchemaEnumMember) m.set_defined_in(name) - assert prefix is None or isinstance(prefix, str) self.members =3D members self.prefix =3D prefix =20 @@ -482,7 +475,6 @@ def __init__( self, name: str, info: Optional[QAPISourceInfo], element_type: str ): super().__init__(name, info, None) - assert isinstance(element_type, str) self._element_type_name =3D element_type self.element_type: QAPISchemaType =20 @@ -527,7 +519,6 @@ def visit(self, visitor: QAPISchemaVisitor) -> None: self.element_type) =20 def describe(self) -> str: - assert self.meta return "%s type ['%s']" % (self.meta, self._element_type_name) =20 =20 @@ -547,12 +538,9 @@ def __init__( # union has base, variants, and no local_members super().__init__(name, info, doc, ifcond, features) self.meta =3D 'union' if variants else 'struct' - assert base is None or isinstance(base, str) for m in local_members: - assert isinstance(m, QAPISchemaObjectTypeMember) m.set_defined_in(name) if variants is not None: - assert isinstance(variants, QAPISchemaVariants) variants.set_defined_in(name) self._base_name =3D base self.base =3D None @@ -674,7 +662,6 @@ def __init__( variants: QAPISchemaVariants, ): super().__init__(name, info, doc, ifcond, features) - assert isinstance(variants, QAPISchemaVariants) assert variants.tag_member variants.set_defined_in(name) variants.tag_member.set_defined_in(self.name) @@ -750,8 +737,6 @@ def __init__( assert bool(tag_member) !=3D bool(tag_name) assert (isinstance(tag_name, str) or isinstance(tag_member, QAPISchemaObjectTypeMember)) - for v in variants: - assert isinstance(v, QAPISchemaVariant) self._tag_name =3D tag_name self.info =3D info self._tag_member =3D tag_member @@ -865,7 +850,6 @@ def __init__( info: Optional[QAPISourceInfo], ifcond: Optional[QAPISchemaIfCond] =3D None, ): - assert isinstance(name, str) self.name =3D name self.info =3D info self.ifcond =3D ifcond or QAPISchemaIfCond() @@ -933,7 +917,6 @@ def __init__( ): super().__init__(name, info, ifcond) for f in features or []: - assert isinstance(f, QAPISchemaFeature) f.set_defined_in(name) self.features =3D features or [] =20 @@ -962,10 +945,7 @@ def __init__( features: Optional[List[QAPISchemaFeature]] =3D None, ): super().__init__(name, info, ifcond) - assert isinstance(typ, str) - assert isinstance(optional, bool) for f in features or []: - assert isinstance(f, QAPISchemaFeature) f.set_defined_in(name) self._type_name =3D typ self.type: QAPISchemaType # set during check() @@ -973,7 +953,6 @@ def __init__( self.features =3D features or [] =20 def need_has(self) -> bool: - assert self.type return self.optional and self.type.need_has_if_optional() =20 def check(self, schema: QAPISchema) -> None: @@ -1024,8 +1003,6 @@ def __init__( coroutine: bool, ): super().__init__(name, info, doc, ifcond, features) - assert not arg_type or isinstance(arg_type, str) - assert not ret_type or isinstance(ret_type, str) self._arg_type_name =3D arg_type self.arg_type: Optional[QAPISchemaObjectType] =3D None self._ret_type_name =3D ret_type @@ -1065,7 +1042,6 @@ def check(self, schema: QAPISchema) -> None: if self.name not in self.info.pragma.command_returns_exception= s: typ =3D self.ret_type if isinstance(typ, QAPISchemaArrayType): - assert typ typ =3D typ.element_type if not isinstance(typ, QAPISchemaObjectType): raise QAPISemError( @@ -1103,7 +1079,6 @@ def __init__( boxed: bool, ): super().__init__(name, info, doc, ifcond, features) - assert not arg_type or isinstance(arg_type, str) self._arg_type_name =3D arg_type self.arg_type: Optional[QAPISchemaObjectType] =3D None self.boxed =3D boxed --=20 2.43.0