From nobody Mon May 13 15:28:44 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=1676419341; cv=none; d=zohomail.com; s=zohoarc; b=l4trZ6hUSLHde/Jr1InP6S75af1aEKztYHZIN7ZCGFm2jj4zhedrv4okIqHZ6oBZfigkGp4dJn4f1ZBRdVGU/BilFuXGr5iP55pRje43BBdKVWX2HSUFHYISvUfMvak7KJWoXxZSvOMnrQL9wFYM+JmphsX9DTJFwfAA/2TwvoQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676419341; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5+7UXsrf4cGn/AKncq9h/Ji9PUl0xijDSmu0t81Ejo4=; b=PBpi1Ao1DMueZU1usEIGm9JduNSy+K5SNS9KL/H+Fl4TWt3ABfe+FGL+PGGBno+i3w08sW/xM2pcI8fMwPT0vNnCvzyNV8ezVH6JDXNbDMDBHVh1Sw9nGUFahQ6j2gGWgqm4xv2565ANsJX6XLYlQWNeCPxdt/sU1zDr1bb1sgw= 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 1676419341737153.60583130002317; Tue, 14 Feb 2023 16:02:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS5Dy-0006F5-1j; Tue, 14 Feb 2023 19:00:38 -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 1pS5De-0006Be-2G for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:18 -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 1pS5Da-000768-SQ for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:17 -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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-609-Uvv-u4AMPJiScJKAHx8uIw-1; Tue, 14 Feb 2023 19:00:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EBE83857F43; Wed, 15 Feb 2023 00:00:11 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF3AE2166B26; Wed, 15 Feb 2023 00:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676419213; 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+7UXsrf4cGn/AKncq9h/Ji9PUl0xijDSmu0t81Ejo4=; b=UB81y30DeeDy6oEFGm0rJRpfhOYG2Raw+DZFMqYBo2EuCSeUWqvSoimjAGaj2jEK71ZHVd qxfjXrOjHQVo4aovRXCbLWHruiOqTa/fpUwGSx4A+mwG3X+6wqNQdIOyrkeA39MoVCk366 aJDbugvh5XavQ+pZkQrSVOCLNDh2fOE= X-MC-Unique: Uvv-u4AMPJiScJKAHx8uIw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , John Snow Subject: [PATCH v4 1/6] qapi: Update flake8 config Date: Tue, 14 Feb 2023 19:00:06 -0500 Message-Id: <20230215000011.1725012-2-jsnow@redhat.com> In-Reply-To: <20230215000011.1725012-1-jsnow@redhat.com> References: <20230215000011.1725012-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1676419343394100003 Content-Type: text/plain; charset="utf-8" New versions of flake8 don't like same-line comments. (It's a version newer than what fc37 ships, but it still makes my life easier to fix it now.) Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/.flake8 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/.flake8 b/scripts/qapi/.flake8 index 6b158c68b84..a873ff67309 100644 --- a/scripts/qapi/.flake8 +++ b/scripts/qapi/.flake8 @@ -1,2 +1,3 @@ [flake8] -extend-ignore =3D E722 # Prefer pylint's bare-except checks to flake8's +# Prefer pylint's bare-except checks to flake8's +extend-ignore =3D E722 --=20 2.39.0 From nobody Mon May 13 15:28:44 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=1676419260; cv=none; d=zohomail.com; s=zohoarc; b=g5tWRN/8yS4/qYrAeZoGZBEG9fwXudT6vV/RV3Ueq8fkmS8OyX7jnNDq4krg76ixWW6CUmL5w51NsqBtyvLwMaLIMFR8p9eLfyTESh1vmNP/SoH0Oqjz51l2V5k/bbmIZkmp7TDLguO+6VlmUGl0AK93q2OMuJYOOC2Ni4mAjtc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676419260; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xHmFj3MrllEaw4U4G5YhOZVicHZFP4J7v6YVMN6Hq9g=; b=b6QmlaI+/8NsrtnZoC0Icbd5EXIRBmk576JFM35PPbiCx7FN1t95StYKullfQcAjvA/smEz7Ir0Myu9TlkhIcP2xuFeZwrlA5wtxUi6PwfF/4OChVrg3Xw5cRnsUkwPKc42V5XyX1x57HJ3SsCgF9HEyOlIgPdqSgWUONoZtd1Y= 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 1676419260649712.672655249023; Tue, 14 Feb 2023 16:01:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS5Df-0006By-DF; Tue, 14 Feb 2023 19:00: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 1pS5Dc-0006BP-P3 for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:16 -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 1pS5Da-00076A-Qw for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:16 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-31-7zzGIlG_Pdmx7fZOmWQR6g-1; Tue, 14 Feb 2023 19:00:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 334F3384798D; Wed, 15 Feb 2023 00:00:12 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0736F2166B26; Wed, 15 Feb 2023 00:00:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676419214; 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=xHmFj3MrllEaw4U4G5YhOZVicHZFP4J7v6YVMN6Hq9g=; b=O+yE/CB60uLASPadsmQun0YxpVDs1lG/ZSdULjmzS4lo4iOC4UQAnhWPtyoE3X6FHjlAgT I/cSEavrpTzmHLt5gm/L0HGT3cUpfWi1/VaQ1OFgsltBGr79OwpNnqvv8Nrim2XPXUoJEt 9uHkhGld1j01hZp/6j6lEyfW8kJr3mE= X-MC-Unique: 7zzGIlG_Pdmx7fZOmWQR6g-1 From: John Snow To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , John Snow Subject: [PATCH v4 2/6] qapi: update pylint configuration Date: Tue, 14 Feb 2023 19:00:07 -0500 Message-Id: <20230215000011.1725012-3-jsnow@redhat.com> In-Reply-To: <20230215000011.1725012-1-jsnow@redhat.com> References: <20230215000011.1725012-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1676419261404100002 Content-Type: text/plain; charset="utf-8" Newer versions of pylint disable the "no-self-use" message by default. Older versions don't, though. If we leave the suppressions in, pylint yelps about useless options. Just tell pylint to shush. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/pylintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index a7246282030..90546df5345 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -23,6 +23,7 @@ disable=3Dfixme, too-many-statements, too-many-instance-attributes, consider-using-f-string, + useless-option-value, =20 [REPORTS] =20 --=20 2.39.0 From nobody Mon May 13 15:28:44 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=1676419325; cv=none; d=zohomail.com; s=zohoarc; b=dg/vkUhP1rdOHG+39XsZ9mlYH972jXsyedo8eXC337lbA5n08A+CJDgTlCCtm7eIFIHPQ0Wp5Q3jPGK97zFxbkJpyfMEXPpfJCsEpkSUc45djgnL47cMZcAVTbY5ZWJQQv/DrDX7jPX/gT784A1QG8hoHR13kPVHPkYZ0uM99vY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676419325; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CG7Jd9irv5mfHFW1vJoqmAQGxlo39EUymhFyZQg6FpE=; b=SOeV7E0rT4JHJG80PBaYbggF4stQB2sgznZ7FAqMqwfrZaz07zjtCl0MkkFgvLBa0/6oe+Al+h2PQJ3oRDeqXxq+z1c9VMBfaYJLVN5nBn2Nsc1q6GXr0ROuGJ53VaUV1q5TOEyZ372xhxafO213vlcwYmR1tlS+24Sjwv3pegc= 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 1676419325742907.9031718013678; Tue, 14 Feb 2023 16:02:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS5E2-0006G2-29; Tue, 14 Feb 2023 19:00:42 -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 1pS5Dg-0006CQ-IF for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:23 -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 1pS5Da-00076D-TZ for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:20 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-F1Wz1JPcN9-6iN3topP7Ew-1; Tue, 14 Feb 2023 19:00:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6D10D1C068CA; Wed, 15 Feb 2023 00:00:12 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 404812166B26; Wed, 15 Feb 2023 00:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676419214; 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=CG7Jd9irv5mfHFW1vJoqmAQGxlo39EUymhFyZQg6FpE=; b=RhuSzAfR65J+caXjS51ClnBNOb5Kr7ApTTrtIldRzlsWL0A1BaUaFB/4uwJKMlcnRd/c51 l870jcBCHqzWjHF/NMEbtPCrLTSqOhIGnUW0TMKzzXaNnU1e5dC8btNkEygQ/IeoqaAnCf u0Y8TOK9E6UwXQ2BLclADQXZU5BgG1o= X-MC-Unique: F1Wz1JPcN9-6iN3topP7Ew-1 From: John Snow To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , John Snow Subject: [PATCH v4 3/6] qapi: Add minor typing workaround for 3.6 Date: Tue, 14 Feb 2023 19:00:08 -0500 Message-Id: <20230215000011.1725012-4-jsnow@redhat.com> In-Reply-To: <20230215000011.1725012-1-jsnow@redhat.com> References: <20230215000011.1725012-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1676419327265100003 Content-Type: text/plain; charset="utf-8" Pylint under 3.6 does not believe that Collection is subscriptable at runtime. It is, making this a Pylint bug. https://github.com/PyCQA/pylint/issues/2377 They closed it as fixed, but that doesn't seem to be true as of Pylint 2.13.9, the latest version you can install under Python 3.6. 2.13.9 was released 2022-05-13, about seven months after the bug was closed. The least-annoying fix here is to just use the more specific type Sequence, only because it seems to work in 3.6. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/expr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 5a1782b57ea..8701351fdfc 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -33,11 +33,11 @@ =20 import re from typing import ( - Collection, Dict, Iterable, List, Optional, + Sequence, Union, cast, ) @@ -195,8 +195,8 @@ def check_defn_name_str(name: str, info: QAPISourceInfo= , meta: str) -> None: def check_keys(value: _JSONObject, info: QAPISourceInfo, source: str, - required: Collection[str], - optional: Collection[str]) -> None: + required: Sequence[str], + optional: Sequence[str]) -> None: """ Ensure that a dict has a specific set of keys. =20 --=20 2.39.0 From nobody Mon May 13 15:28:44 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=1676419309; cv=none; d=zohomail.com; s=zohoarc; b=YsSGq8sNo3gcZjyvKV0uLGpQVChtWuvThXurOsRe4quhJCq92ucE4Mx72doHCXooBPu83PpSzaapHLUeqEoxzOt6gr9QWSqBzhfn2yewoqugyCsBsYQuT4VLAc98NK0XXfAYxgncKnf63CGtWSCFbFlXW/+ypR3YDGOGu6FLFro= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676419309; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0BvufUAiNyyK3834U46+RtsFxOz8QKELDD8EBmrANxw=; b=LKS7p1x+/HUuncxVezRXOxFsDO3h1cUFU9gQXaTTs5csnFumDCrXoBKsDK9+KOGgw0wBkn034bulxfC1EWJRia4XcEe/6xxBo9MPVnRHld8AQVZyMxTcLhbg5lM8X79olod+IA7PcfkHklptyNosGmeAu2NtTj98x+NErX7Nr04= 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 1676419309419265.74760092900567; Tue, 14 Feb 2023 16:01:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS5E1-0006FX-1x; Tue, 14 Feb 2023 19:00:41 -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 1pS5Dg-0006CR-KB for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:23 -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 1pS5Dd-00076Y-5I for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:20 -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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-gH5Gx4eVN1miI8DWaTyb5Q-1; Tue, 14 Feb 2023 19:00:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AE28785C70F; Wed, 15 Feb 2023 00:00:12 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79E662166B26; Wed, 15 Feb 2023 00:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676419216; 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=0BvufUAiNyyK3834U46+RtsFxOz8QKELDD8EBmrANxw=; b=NmcgzWqIqmvNuWHUVIqv7QpbqoqBhm7ypb9fgKNcExPVzNjPxCqCvgcEoKFnm9jaqe1SW7 lkAAQ1PeU0rzLCBIU0X1DV/UdRjICCh2sb7c0EcRHoOr1GNRUWv3/hIyF5xHuVsH9xx6tt PhMMsUsTNNoSQ+0zXoXlqY/VQNs9MN0= X-MC-Unique: gH5Gx4eVN1miI8DWaTyb5Q-1 From: John Snow To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , John Snow Subject: [PATCH v4 4/6] qapi/parser: add QAPIExpression type Date: Tue, 14 Feb 2023 19:00:09 -0500 Message-Id: <20230215000011.1725012-5-jsnow@redhat.com> In-Reply-To: <20230215000011.1725012-1-jsnow@redhat.com> References: <20230215000011.1725012-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1676419311247100003 Content-Type: text/plain; charset="utf-8" This patch creates a new type, QAPIExpression, which represents a parsed expression complete with QAPIDoc and QAPISourceInfo. This patch turns parser.exprs into a list of QAPIExpression instead, and adjusts expr.py to match. This allows the types we specify in parser.py to be "remembered" all the way through expr.py and into schema.py. Several assertions around packing and unpacking this data can be removed as a result. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/expr.py | 82 +++++++++++++++++------------------------- scripts/qapi/parser.py | 46 ++++++++++++++---------- scripts/qapi/schema.py | 72 ++++++++++++++++++++----------------- 3 files changed, 100 insertions(+), 100 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 8701351fdfc..52153a2eec5 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -44,7 +44,7 @@ =20 from .common import c_name from .error import QAPISemError -from .parser import QAPIDoc +from .parser import QAPIExpression from .source import QAPISourceInfo =20 =20 @@ -229,12 +229,11 @@ def pprint(elems: Iterable[str]) -> str: pprint(unknown), pprint(allowed))) =20 =20 -def check_flags(expr: _JSONObject, info: QAPISourceInfo) -> None: +def check_flags(expr: QAPIExpression) -> None: """ Ensure flag members (if present) have valid values. =20 :param expr: The expression to validate. - :param info: QAPI schema source file information. =20 :raise QAPISemError: When certain flags have an invalid value, or when @@ -243,18 +242,18 @@ def check_flags(expr: _JSONObject, info: QAPISourceIn= fo) -> None: for key in ('gen', 'success-response'): if key in expr and expr[key] is not False: raise QAPISemError( - info, "flag '%s' may only use false value" % key) + expr.info, "flag '%s' may only use false value" % key) for key in ('boxed', 'allow-oob', 'allow-preconfig', 'coroutine'): if key in expr and expr[key] is not True: raise QAPISemError( - info, "flag '%s' may only use true value" % key) + expr.info, "flag '%s' may only use true value" % key) if 'allow-oob' in expr and 'coroutine' in expr: # This is not necessarily a fundamental incompatibility, but # we don't have a use case and the desired semantics isn't # obvious. The simplest solution is to forbid it until we get # a use case for it. - raise QAPISemError(info, "flags 'allow-oob' and 'coroutine' " - "are incompatible") + raise QAPISemError( + expr.info, "flags 'allow-oob' and 'coroutine' are incompatible= ") =20 =20 def check_if(expr: _JSONObject, info: QAPISourceInfo, source: str) -> None: @@ -447,12 +446,11 @@ def check_features(features: Optional[object], check_if(feat, info, source) =20 =20 -def check_enum(expr: _JSONObject, info: QAPISourceInfo) -> None: +def check_enum(expr: QAPIExpression) -> None: """ Normalize and validate this expression as an ``enum`` definition. =20 :param expr: The expression to validate. - :param info: QAPI schema source file information. =20 :raise QAPISemError: When ``expr`` is not a valid ``enum``. :return: None, ``expr`` is normalized in-place as needed. @@ -460,6 +458,7 @@ def check_enum(expr: _JSONObject, info: QAPISourceInfo)= -> None: name =3D expr['enum'] members =3D expr['data'] prefix =3D expr.get('prefix') + info =3D expr.info =20 if not isinstance(members, list): raise QAPISemError(info, "'data' must be an array") @@ -486,12 +485,11 @@ def check_enum(expr: _JSONObject, info: QAPISourceInf= o) -> None: check_features(member.get('features'), info) =20 =20 -def check_struct(expr: _JSONObject, info: QAPISourceInfo) -> None: +def check_struct(expr: QAPIExpression) -> None: """ Normalize and validate this expression as a ``struct`` definition. =20 :param expr: The expression to validate. - :param info: QAPI schema source file information. =20 :raise QAPISemError: When ``expr`` is not a valid ``struct``. :return: None, ``expr`` is normalized in-place as needed. @@ -499,16 +497,15 @@ def check_struct(expr: _JSONObject, info: QAPISourceI= nfo) -> None: name =3D cast(str, expr['struct']) # Checked in check_exprs members =3D expr['data'] =20 - check_type(members, info, "'data'", allow_dict=3Dname) - check_type(expr.get('base'), info, "'base'") + check_type(members, expr.info, "'data'", allow_dict=3Dname) + check_type(expr.get('base'), expr.info, "'base'") =20 =20 -def check_union(expr: _JSONObject, info: QAPISourceInfo) -> None: +def check_union(expr: QAPIExpression) -> None: """ Normalize and validate this expression as a ``union`` definition. =20 :param expr: The expression to validate. - :param info: QAPI schema source file information. =20 :raise QAPISemError: when ``expr`` is not a valid ``union``. :return: None, ``expr`` is normalized in-place as needed. @@ -517,6 +514,7 @@ def check_union(expr: _JSONObject, info: QAPISourceInfo= ) -> None: base =3D expr['base'] discriminator =3D expr['discriminator'] members =3D expr['data'] + info =3D expr.info =20 check_type(base, info, "'base'", allow_dict=3Dname) check_name_is_str(discriminator, info, "'discriminator'") @@ -531,17 +529,17 @@ def check_union(expr: _JSONObject, info: QAPISourceIn= fo) -> None: check_type(value['type'], info, source, allow_array=3Dnot base) =20 =20 -def check_alternate(expr: _JSONObject, info: QAPISourceInfo) -> None: +def check_alternate(expr: QAPIExpression) -> None: """ Normalize and validate this expression as an ``alternate`` definition. =20 :param expr: The expression to validate. - :param info: QAPI schema source file information. =20 :raise QAPISemError: When ``expr`` is not a valid ``alternate``. :return: None, ``expr`` is normalized in-place as needed. """ members =3D expr['data'] + info =3D expr.info =20 if not members: raise QAPISemError(info, "'data' must not be empty") @@ -557,12 +555,11 @@ def check_alternate(expr: _JSONObject, info: QAPISour= ceInfo) -> None: check_type(value['type'], info, source, allow_array=3DTrue) =20 =20 -def check_command(expr: _JSONObject, info: QAPISourceInfo) -> None: +def check_command(expr: QAPIExpression) -> None: """ Normalize and validate this expression as a ``command`` definition. =20 :param expr: The expression to validate. - :param info: QAPI schema source file information. =20 :raise QAPISemError: When ``expr`` is not a valid ``command``. :return: None, ``expr`` is normalized in-place as needed. @@ -572,17 +569,16 @@ def check_command(expr: _JSONObject, info: QAPISource= Info) -> None: boxed =3D expr.get('boxed', False) =20 if boxed and args is None: - raise QAPISemError(info, "'boxed': true requires 'data'") - check_type(args, info, "'data'", allow_dict=3Dnot boxed) - check_type(rets, info, "'returns'", allow_array=3DTrue) + raise QAPISemError(expr.info, "'boxed': true requires 'data'") + check_type(args, expr.info, "'data'", allow_dict=3Dnot boxed) + check_type(rets, expr.info, "'returns'", allow_array=3DTrue) =20 =20 -def check_event(expr: _JSONObject, info: QAPISourceInfo) -> None: +def check_event(expr: QAPIExpression) -> None: """ Normalize and validate this expression as an ``event`` definition. =20 :param expr: The expression to validate. - :param info: QAPI schema source file information. =20 :raise QAPISemError: When ``expr`` is not a valid ``event``. :return: None, ``expr`` is normalized in-place as needed. @@ -591,11 +587,11 @@ def check_event(expr: _JSONObject, info: QAPISourceIn= fo) -> None: boxed =3D expr.get('boxed', False) =20 if boxed and args is None: - raise QAPISemError(info, "'boxed': true requires 'data'") - check_type(args, info, "'data'", allow_dict=3Dnot boxed) + raise QAPISemError(expr.info, "'boxed': true requires 'data'") + check_type(args, expr.info, "'data'", allow_dict=3Dnot boxed) =20 =20 -def check_exprs(exprs: List[_JSONObject]) -> List[_JSONObject]: +def check_exprs(exprs: List[QAPIExpression]) -> List[QAPIExpression]: """ Validate and normalize a list of parsed QAPI schema expressions. =20 @@ -607,21 +603,9 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JSO= NObject]: :raise QAPISemError: When any expression fails validation. :return: The same list of expressions (now modified). """ - for expr_elem in exprs: - # Expression - assert isinstance(expr_elem['expr'], dict) - for key in expr_elem['expr'].keys(): - assert isinstance(key, str) - expr: _JSONObject =3D expr_elem['expr'] - - # QAPISourceInfo - assert isinstance(expr_elem['info'], QAPISourceInfo) - info: QAPISourceInfo =3D expr_elem['info'] - - # Optional[QAPIDoc] - tmp =3D expr_elem.get('doc') - assert tmp is None or isinstance(tmp, QAPIDoc) - doc: Optional[QAPIDoc] =3D tmp + for expr in exprs: + info =3D expr.info + doc =3D expr.doc =20 if 'include' in expr: continue @@ -653,24 +637,24 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JS= ONObject]: if meta =3D=3D 'enum': check_keys(expr, info, meta, ['enum', 'data'], ['if', 'features', 'prefix']) - check_enum(expr, info) + check_enum(expr) elif meta =3D=3D 'union': check_keys(expr, info, meta, ['union', 'base', 'discriminator', 'data'], ['if', 'features']) normalize_members(expr.get('base')) normalize_members(expr['data']) - check_union(expr, info) + check_union(expr) elif meta =3D=3D 'alternate': check_keys(expr, info, meta, ['alternate', 'data'], ['if', 'features']) normalize_members(expr['data']) - check_alternate(expr, info) + check_alternate(expr) elif meta =3D=3D 'struct': check_keys(expr, info, meta, ['struct', 'data'], ['base', 'if', 'features']) normalize_members(expr['data']) - check_struct(expr, info) + check_struct(expr) elif meta =3D=3D 'command': check_keys(expr, info, meta, ['command'], @@ -678,17 +662,17 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JS= ONObject]: 'gen', 'success-response', 'allow-oob', 'allow-preconfig', 'coroutine']) normalize_members(expr.get('data')) - check_command(expr, info) + check_command(expr) elif meta =3D=3D 'event': check_keys(expr, info, meta, ['event'], ['data', 'boxed', 'if', 'features']) normalize_members(expr.get('data')) - check_event(expr, info) + check_event(expr) else: assert False, 'unexpected meta type' =20 check_if(expr, info, meta) check_features(expr.get('features'), info) - check_flags(expr, info) + check_flags(expr) =20 return exprs diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 1b006cdc133..50906e27d49 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -21,6 +21,7 @@ TYPE_CHECKING, Dict, List, + Mapping, Optional, Set, Union, @@ -37,15 +38,24 @@ from .schema import QAPISchemaFeature, QAPISchemaMember =20 =20 -#: Represents a single Top Level QAPI schema expression. -TopLevelExpr =3D Dict[str, object] - # Return value alias for get_expr(). _ExprValue =3D Union[List[object], Dict[str, object], str, bool] =20 -# FIXME: Consolidate and centralize definitions for TopLevelExpr, -# _ExprValue, _JSONValue, and _JSONObject; currently scattered across -# several modules. + +# FIXME: Consolidate and centralize definitions for _ExprValue, +# JSONValue, and _JSONObject; currently scattered across several +# modules. + + +class QAPIExpression(Dict[str, object]): + # pylint: disable=3Dtoo-few-public-methods + def __init__(self, + data: Mapping[str, object], + info: QAPISourceInfo, + doc: Optional['QAPIDoc'] =3D None): + super().__init__(data) + self.info =3D info + self.doc: Optional['QAPIDoc'] =3D doc =20 =20 class QAPIParseError(QAPISourceError): @@ -100,7 +110,7 @@ def __init__(self, self.line_pos =3D 0 =20 # Parser output: - self.exprs: List[Dict[str, object]] =3D [] + self.exprs: List[QAPIExpression] =3D [] self.docs: List[QAPIDoc] =3D [] =20 # Showtime! @@ -147,8 +157,7 @@ def _parse(self) -> None: "value of 'include' must be a strin= g") incl_fname =3D os.path.join(os.path.dirname(self._fname), include) - self.exprs.append({'expr': {'include': incl_fname}, - 'info': info}) + self._add_expr(OrderedDict({'include': incl_fname}), info) exprs_include =3D self._include(include, info, incl_fname, self._included) if exprs_include: @@ -165,17 +174,18 @@ def _parse(self) -> None: for name, value in pragma.items(): self._pragma(name, value, info) else: - expr_elem =3D {'expr': expr, - 'info': info} - if cur_doc: - if not cur_doc.symbol: - raise QAPISemError( - cur_doc.info, "definition documentation requir= ed") - expr_elem['doc'] =3D cur_doc - self.exprs.append(expr_elem) + if cur_doc and not cur_doc.symbol: + raise QAPISemError( + cur_doc.info, "definition documentation required") + self._add_expr(expr, info, cur_doc) cur_doc =3D None self.reject_expr_doc(cur_doc) =20 + def _add_expr(self, expr: Mapping[str, object], + info: QAPISourceInfo, + doc: Optional['QAPIDoc'] =3D None) -> None: + self.exprs.append(QAPIExpression(expr, info, doc)) + @staticmethod def reject_expr_doc(doc: Optional['QAPIDoc']) -> None: if doc and doc.symbol: @@ -784,7 +794,7 @@ def connect_feature(self, feature: 'QAPISchemaFeature')= -> None: % feature.name) self.features[feature.name].connect(feature) =20 - def check_expr(self, expr: TopLevelExpr) -> None: + def check_expr(self, expr: QAPIExpression) -> None: if self.has_section('Returns') and 'command' not in expr: raise QAPISemError(self.info, "'Returns:' is only valid for commands") diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index cd8661125cd..207e4d71f39 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -17,7 +17,7 @@ from collections import OrderedDict import os import re -from typing import Optional +from typing import List, Optional =20 from .common import ( POINTER_SUFFIX, @@ -29,7 +29,7 @@ ) from .error import QAPIError, QAPISemError, QAPISourceError from .expr import check_exprs -from .parser import QAPISchemaParser +from .parser import QAPIExpression, QAPISchemaParser =20 =20 class QAPISchemaIfCond: @@ -964,10 +964,11 @@ def module_by_fname(self, fname): name =3D self._module_name(fname) return self._module_dict[name] =20 - def _def_include(self, expr, info, doc): + def _def_include(self, expr: QAPIExpression): include =3D expr['include'] - assert doc is None - self._def_entity(QAPISchemaInclude(self._make_module(include), inf= o)) + 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): self._def_entity(QAPISchemaBuiltinType(name, json_type, c_type)) @@ -1045,14 +1046,15 @@ def _make_implicit_object_type(self, name, info, if= cond, role, members): name, info, None, ifcond, None, None, members, None)) return name =20 - def _def_enum_type(self, expr, info, doc): + def _def_enum_type(self, expr: QAPIExpression): name =3D expr['enum'] data =3D expr['data'] prefix =3D expr.get('prefix') ifcond =3D QAPISchemaIfCond(expr.get('if')) + info =3D expr.info features =3D self._make_features(expr.get('features'), info) self._def_entity(QAPISchemaEnumType( - name, info, doc, ifcond, features, + name, info, expr.doc, ifcond, features, self._make_enum_members(data, info), prefix)) =20 def _make_member(self, name, typ, ifcond, features, info): @@ -1072,14 +1074,15 @@ def _make_members(self, data, info): value.get('features'), info) for (key, value) in data.items()] =20 - def _def_struct_type(self, expr, info, doc): + def _def_struct_type(self, expr: QAPIExpression): name =3D expr['struct'] base =3D expr.get('base') data =3D expr['data'] + info =3D expr.info ifcond =3D QAPISchemaIfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) self._def_entity(QAPISchemaObjectType( - name, info, doc, ifcond, features, base, + name, info, expr.doc, ifcond, features, base, self._make_members(data, info), None)) =20 @@ -1089,11 +1092,13 @@ def _make_variant(self, case, typ, ifcond, info): typ =3D self._make_array_type(typ[0], info) return QAPISchemaVariant(case, info, typ, ifcond) =20 - def _def_union_type(self, expr, info, doc): + def _def_union_type(self, expr: QAPIExpression): name =3D expr['union'] base =3D expr['base'] tag_name =3D expr['discriminator'] data =3D expr['data'] + assert isinstance(data, dict) + info =3D expr.info ifcond =3D QAPISchemaIfCond(expr.get('if')) features =3D self._make_features(expr.get('features'), info) if isinstance(base, dict): @@ -1105,17 +1110,19 @@ def _def_union_type(self, expr, info, doc): QAPISchemaIfCond(value.get('if')), info) for (key, value) in data.items()] - members =3D [] + members: List[QAPISchemaObjectTypeMember] =3D [] self._def_entity( - QAPISchemaObjectType(name, info, doc, ifcond, features, + QAPISchemaObjectType(name, info, expr.doc, ifcond, features, base, members, QAPISchemaVariants( tag_name, info, None, variants))) =20 - def _def_alternate_type(self, expr, info, doc): + def _def_alternate_type(self, expr: QAPIExpression): name =3D expr['alternate'] data =3D expr['data'] + assert isinstance(data, dict) ifcond =3D QAPISchemaIfCond(expr.get('if')) + info =3D expr.info features =3D self._make_features(expr.get('features'), info) variants =3D [ self._make_variant(key, value['type'], @@ -1124,11 +1131,11 @@ def _def_alternate_type(self, expr, info, doc): for (key, value) in data.items()] tag_member =3D QAPISchemaObjectTypeMember('type', info, 'QType', F= alse) self._def_entity( - QAPISchemaAlternateType(name, info, doc, ifcond, features, - QAPISchemaVariants( - None, info, tag_member, variants))) + QAPISchemaAlternateType( + name, info, expr.doc, ifcond, features, + QAPISchemaVariants(None, info, tag_member, variants))) =20 - def _def_command(self, expr, info, doc): + def _def_command(self, expr: QAPIExpression): name =3D expr['command'] data =3D expr.get('data') rets =3D expr.get('returns') @@ -1139,6 +1146,7 @@ def _def_command(self, expr, info, doc): allow_preconfig =3D expr.get('allow-preconfig', False) coroutine =3D expr.get('coroutine', False) ifcond =3D QAPISchemaIfCond(expr.get('if')) + info =3D expr.info features =3D self._make_features(expr.get('features'), info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( @@ -1147,44 +1155,42 @@ def _def_command(self, expr, info, doc): 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, doc, ifcond, featur= es, - data, rets, + self._def_entity(QAPISchemaCommand(name, info, expr.doc, ifcond, + features, data, rets, gen, success_response, boxed, allow_oob, allow_preconf= ig, coroutine)) =20 - def _def_event(self, expr, info, doc): + def _def_event(self, expr: QAPIExpression): name =3D expr['event'] data =3D expr.get('data') boxed =3D expr.get('boxed', False) ifcond =3D QAPISchemaIfCond(expr.get('if')) + info =3D expr.info features =3D self._make_features(expr.get('features'), info) if isinstance(data, OrderedDict): data =3D self._make_implicit_object_type( name, info, ifcond, 'arg', self._make_members(data, info)) - self._def_entity(QAPISchemaEvent(name, info, doc, ifcond, features, - data, boxed)) + self._def_entity(QAPISchemaEvent(name, info, expr.doc, ifcond, + features, data, boxed)) =20 def _def_exprs(self, exprs): - for expr_elem in exprs: - expr =3D expr_elem['expr'] - info =3D expr_elem['info'] - doc =3D expr_elem.get('doc') + for expr in exprs: if 'enum' in expr: - self._def_enum_type(expr, info, doc) + self._def_enum_type(expr) elif 'struct' in expr: - self._def_struct_type(expr, info, doc) + self._def_struct_type(expr) elif 'union' in expr: - self._def_union_type(expr, info, doc) + self._def_union_type(expr) elif 'alternate' in expr: - self._def_alternate_type(expr, info, doc) + self._def_alternate_type(expr) elif 'command' in expr: - self._def_command(expr, info, doc) + self._def_command(expr) elif 'event' in expr: - self._def_event(expr, info, doc) + self._def_event(expr) elif 'include' in expr: - self._def_include(expr, info, doc) + self._def_include(expr) else: assert False =20 --=20 2.39.0 From nobody Mon May 13 15:28:44 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=1676419316; cv=none; d=zohomail.com; s=zohoarc; b=H4DbzDrGBncI7NVRADC8wbEbceMlE1g089VVnsDazm9hbh3yROonqI8lb80p0vwVJ5KE2qBInqlRvfkKtMPgYxOE9j8loMmQUI6f9Nl7rtb7U7QtR29YA47E0lfefg8PjYGJIfMsQKXrhy4RRyrZRrqkwQ3N0TUxcJbb47JX44c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676419316; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=HU1jeQLkV0DEsvjcwUl8N0bkBEMQ1Qv9AWQ1zKgfnzo=; b=aa7bKzmpnV9mw+rrVemNUf4t+mMmMhVGNFdasO0gQpR+BHhQ2t3Dbdx1/c/uTp0JyetTU+IhLDMCzrgn4QmcpzLuGAPcukR4MHM8k9fzKpHA5nWmMRTlLUxA/erghLKHOsR2g0RucOTYM8nZ1niDaD9Qz6QefIRQxMcGZEzHZzU= 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 1676419316698105.48839825006633; Tue, 14 Feb 2023 16:01:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS5E0-0006FU-2O; Tue, 14 Feb 2023 19:00:40 -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 1pS5Df-0006CE-9A for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:19 -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 1pS5Dd-00076U-4T for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:18 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-675-o4VyHOg1N5qCFFE1580Fgw-1; Tue, 14 Feb 2023 19:00:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E70CD3C0E463; Wed, 15 Feb 2023 00:00:12 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA54B2166B26; Wed, 15 Feb 2023 00:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676419216; 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=HU1jeQLkV0DEsvjcwUl8N0bkBEMQ1Qv9AWQ1zKgfnzo=; b=ZeHvU+9bpnE9ProVBR4GAFCy0t8HvX6hGwCGx4iyNUFdmpAx+lUbR0vDHAu4ZEhjS9phRw rHu8Rz02s7lQW64P/8YEaGerccr4r7a9ICY4IxVSmOc/ZSDsfcCuEis6Bh4BhOgIJ1UqTv qTRw0Yb1Npp3BAgTqgB0z0SVu3+tOyw= X-MC-Unique: o4VyHOg1N5qCFFE1580Fgw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , John Snow Subject: [PATCH v4 5/6] qapi: remove _JSONObject Date: Tue, 14 Feb 2023 19:00:10 -0500 Message-Id: <20230215000011.1725012-6-jsnow@redhat.com> In-Reply-To: <20230215000011.1725012-1-jsnow@redhat.com> References: <20230215000011.1725012-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1676419317246100001 Content-Type: text/plain; charset="utf-8" We can remove this alias as it only has two usages now, and no longer pays for the confusion of "yet another type". Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/expr.py | 13 +++---------- scripts/qapi/parser.py | 5 ++--- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 52153a2eec5..fc4defecc8e 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -48,14 +48,6 @@ from .source import QAPISourceInfo =20 =20 -# Deserialized JSON objects as returned by the parser. -# The values of this mapping are not necessary to exhaustively type -# here (and also not practical as long as mypy lacks recursive -# types), because the purpose of this module is to interrogate that -# type. -_JSONObject =3D Dict[str, object] - - # See check_name_str(), below. valid_name =3D re.compile(r'(__[a-z0-9.-]+_)?' r'(x-)?' @@ -192,7 +184,7 @@ def check_defn_name_str(name: str, info: QAPISourceInfo= , meta: str) -> None: info, "%s name should not end in 'List'" % meta) =20 =20 -def check_keys(value: _JSONObject, +def check_keys(value: Dict[str, object], info: QAPISourceInfo, source: str, required: Sequence[str], @@ -256,7 +248,8 @@ def check_flags(expr: QAPIExpression) -> None: expr.info, "flags 'allow-oob' and 'coroutine' are incompatible= ") =20 =20 -def check_if(expr: _JSONObject, info: QAPISourceInfo, source: str) -> None: +def check_if(expr: Dict[str, object], + info: QAPISourceInfo, source: str) -> None: """ Validate the ``if`` member of an object. =20 diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 50906e27d49..d570086e1a9 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -42,9 +42,8 @@ _ExprValue =3D Union[List[object], Dict[str, object], str, bool] =20 =20 -# FIXME: Consolidate and centralize definitions for _ExprValue, -# JSONValue, and _JSONObject; currently scattered across several -# modules. +# FIXME: Consolidate and centralize definitions for _ExprValue and +# JSONValue; currently scattered across several modules. =20 =20 class QAPIExpression(Dict[str, object]): --=20 2.39.0 From nobody Mon May 13 15:28:44 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=1676419337; cv=none; d=zohomail.com; s=zohoarc; b=ngUigdJp+UNSLSsIX0esDJghTM51yX+Z2Y/PuqBMfU7I2WVd4shXIP0A6HVVPD8yEOq54wG6uwJ7eiO41QjtH1/0+IVKw54UNBKyy38aVfQwI1YBG6zsqea4z85e+hqHU2uXO5+24sGt9IZzW+EYKsusI0ToUgd1Z9EpGD2sP6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676419337; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=N40NwdF5Z8+PQXRDXauPh68Gz03aMdoMhNH7nNaCZ98=; b=Rgcnj2wZROGY2RMwMvCrpUh6Hg6SHnlo7CkltXB4X0dhejbwRvz2VSnvG2wQTkajX/2SceVikpqFYnh8hXrVRzk3ln3kwRPOAglFaf+PC77dh0ZNOCuJs4ZaVaHpBz3m4x1LX+ZD3UUb/ZEPhRIdt0IuAmm7r2CUcykQOMpO7Is= 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 1676419337199654.669219116822; Tue, 14 Feb 2023 16:02:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pS5E0-0006FV-Qg; Tue, 14 Feb 2023 19:00:40 -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 1pS5De-0006Bx-Px for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:19 -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 1pS5Dd-00076P-06 for qemu-devel@nongnu.org; Tue, 14 Feb 2023 19:00:18 -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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-320-HAYsPphIO7SZ3bdU6xbY8w-1; Tue, 14 Feb 2023 19:00:13 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B22080006E; Wed, 15 Feb 2023 00:00:13 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id F33B72166B26; Wed, 15 Feb 2023 00:00:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676419216; 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=N40NwdF5Z8+PQXRDXauPh68Gz03aMdoMhNH7nNaCZ98=; b=B1vokbj3JH2XcrvqZgVxPNgcvCkhITyh/5Qy9yVueSB1sOXjfVmuD3luq7nadLNzvi+xgj 3YGZBY8v4FpOudp04LjCM64LyFS12e4glEVA2m2bvYk9qfdPII9bMetiIUeaxATmXCXHOQ EsfW8VyTCLFZgzyCr+FALy1cIUlpmy8= X-MC-Unique: HAYsPphIO7SZ3bdU6xbY8w-1 From: John Snow To: qemu-devel@nongnu.org Cc: Markus Armbruster , Michael Roth , John Snow Subject: [PATCH v4 6/6] qapi: remove JSON value FIXME Date: Tue, 14 Feb 2023 19:00:11 -0500 Message-Id: <20230215000011.1725012-7-jsnow@redhat.com> In-Reply-To: <20230215000011.1725012-1-jsnow@redhat.com> References: <20230215000011.1725012-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1676419339315100003 Content-Type: text/plain; charset="utf-8" With the two major JSON-ish type hierarchies clarified for distinct purposes; QAPIExpression for parsed expressions and JSONValue for introspection data, remove this FIXME as no longer an action item. A third JSON-y data type, _ExprValue, is not meant to represent JSON in the abstract but rather only the possible legal return values from a single function, get_expr(). It isn't appropriate to attempt to merge it with either of the above two types. In theory, it may be possible to define a completely agnostic one-size-fits-all JSON type hierarchy that any other user could borrow - in practice, it's tough to wrangle the differences between invariant, covariant and contravariant types: input and output parameters demand different properties of such a structure. However, QAPIExpression serves to authoritatively type user input to the QAPI parser, while JSONValue serves to authoritatively type qapi generator *output* to be served back to client users at runtime via QMP. The AST for these two types are different and cannot be wholly merged into a unified syntax. They could, in theory, share some JSON primitive definitions. In practice, this is currently more trouble than it's worth with mypy's current expressive power. As such, declare this "done enough for now". Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/parser.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index d570086e1a9..878f90b4583 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -42,10 +42,6 @@ _ExprValue =3D Union[List[object], Dict[str, object], str, bool] =20 =20 -# FIXME: Consolidate and centralize definitions for _ExprValue and -# JSONValue; currently scattered across several modules. - - class QAPIExpression(Dict[str, object]): # pylint: disable=3Dtoo-few-public-methods def __init__(self, --=20 2.39.0