From nobody Mon May 13 09:21:40 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=1710304956; cv=none; d=zohomail.com; s=zohoarc; b=D+AxvDoNhqIr1jnq8If/u/OlMjvu3BvaUWJK6SgIjrmYjLnqXmn9aYta+k7hrpqyQyNnEtLVMX+W0JUsdzOJcq91EyeBcQ2lVSje5WLJCV/Mlr8c1Igjf6kvhDw9MpAcJY4STPoucrCTslxIjQQmAUNbqaK52fuxXbbjH9TjBAc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710304956; 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=YeRWVTYVdxZfZMBUmyZyPFTed+a91MZgf4HIikaNmuc=; b=DBgBVkfjlNSVr1TsSPq1P0UJYyfIncbVO3mC5qfOCyDoBXlJd2zfGVeqNHqx6qnauYFokKx59KeuukU+RzArvbfatV2GNy3udWEMLz4poT3goXnnrccQ/PriT9fmPmQsj75kze3xnKuqYRn6tq9R8d95HEapUnJBeea07xQPsIQ= 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 1710304956628377.20779108503245; Tue, 12 Mar 2024 21:42:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGQs-0007tB-UF; Wed, 13 Mar 2024 00:41:38 -0400 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 1rkGQp-0007sq-Vg for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:36 -0400 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 1rkGQo-0001q3-6Z for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:35 -0400 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-546-9sTQaJ1YPWiwynqrKekcYw-1; Wed, 13 Mar 2024 00:41:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 3D4961C0514E; Wed, 13 Mar 2024 04:41:29 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0381810F53; Wed, 13 Mar 2024 04:41:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304891; 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=YeRWVTYVdxZfZMBUmyZyPFTed+a91MZgf4HIikaNmuc=; b=A4kcPG1OX9f2bHhF5PY7yGAZAvw1VGVJoTTrlVUj3y4/GSeTq812AUya4Re1bTc+ToIvXk OOVRzje3eKZeQ9XT3dHIc2Z6gmXldgbuxecmT0TVYlJew3SjCRKuer6nrqdvaimoagkwdJ 8nyKyZBYxTpPb2ufvy/BO6DcR2f5f4A= X-MC-Unique: 9sTQaJ1YPWiwynqrKekcYw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 01/23] qapi/parser: fix typo - self.returns.info => self.errors.info Date: Wed, 13 Mar 2024 00:41:05 -0400 Message-ID: <20240313044127.49089-2-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710304957853100001 Content-Type: text/plain; charset="utf-8" Small copy-pasto. The correct info field to use in this conditional block is self.errors.info. Fixes: 3a025d3d1ffa Signed-off-by: John Snow Reported-by: Markus Armbruster Reviewed-by: Markus Armbruster --- scripts/qapi/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index d8f76060b8c..fed88e9074d 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -733,7 +733,7 @@ def check_expr(self, expr: QAPIExpression) -> None: "'Returns' section is only valid for commands") if self.errors: raise QAPISemError( - self.returns.info, + self.errors.info, "'Errors' section is only valid for commands") =20 def check(self) -> None: --=20 2.44.0 From nobody Mon May 13 09:21:40 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=1710305132; cv=none; d=zohomail.com; s=zohoarc; b=eoLVpBNw6N90/eMA3rEEDkTWg/xFRJIs3euHJSZ7nxtQqrdz6G4PQvhLzgOV+0sE2j1V391aC2rC7TKHrP+sjHShh1kZcO+BRuydROATMrxzyngO7FNeeAJEYDsDzBF17d9inajyllTEdxudEswc+QjM5qYwF3cjDaNLQJTohpc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305132; 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=jl+/PXdZSIMoFk2LhZs0qSmqMQ04aZ9V2d7vx+JK//4=; b=fX5Rz+6so/A4xqJw0NWQP8dNt/CViHSKCSw3oPSbzq4rpq/kfHMsZgEUPXHdLSAA9Fpz3jRY/8k1UvEKqi5hB4K68PdC+AOyZLE0wYLiUS4xOPC/B3ciNdyrJtxc01jg51HtQ9/a7wHD7l07zEzqhuYfZknS5MOtdDEwMdwlOkk= 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 1710305132971131.29799020877522; Tue, 12 Mar 2024 21:45:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRD-0007zV-Jt; Wed, 13 Mar 2024 00:41:59 -0400 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 1rkGQq-0007t9-TZ for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:36 -0400 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 1rkGQo-0001qH-Po for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:36 -0400 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-528-2CN9-NzNOtSvTqR0Hv03VA-1; Wed, 13 Mar 2024 00:41:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 85C568007A2; Wed, 13 Mar 2024 04:41:29 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4BCEB10E4B; Wed, 13 Mar 2024 04:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304893; 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=jl+/PXdZSIMoFk2LhZs0qSmqMQ04aZ9V2d7vx+JK//4=; b=Hgvam/I7Dcv18S0PC4+6zsiGDfGXmYGyWfR7j01sPbj5A3TwqftiEtNiIthuNkyPQmS1qd l5tm3z2oGAJBiXL9I1P3Qr81EroRMMQE/7sL6kjlptIy3stUeUm/RUkvbMIL7Mk46Fyq83 1Y7jp/na2ZTvSO86yme1teBa5DKSYxs= X-MC-Unique: 2CN9-NzNOtSvTqR0Hv03VA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 02/23] qapi/parser: shush up pylint Date: Wed, 13 Mar 2024 00:41:06 -0400 Message-ID: <20240313044127.49089-3-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710305133930100005 Content-Type: text/plain; charset="utf-8" Shhh! Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index fed88e9074d..ec4ebef4e33 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -607,6 +607,7 @@ class QAPIDoc: """ =20 class Section: + # pylint: disable=3Dtoo-few-public-methods def __init__(self, info: QAPISourceInfo, tag: Optional[str] =3D None): # section source info, i.e. where it begins --=20 2.44.0 From nobody Mon May 13 09:21:40 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=1710304966; cv=none; d=zohomail.com; s=zohoarc; b=aVdxZH4sXfO5z6CdVybUcd8G86+KMwn3Moakt1KdWHXODFTQcIMz0/CsLJ6zw1xUy8dKyla4uvdIecYM9b7oWUOxd/VIJj31o58dbzWIinnVdXtaTYRPRJy+c++gk5fwB4GSCLrQAei/DrAeP+WslBORjkkfyeAYfYSeUYiQywg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710304966; 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=ryGN4lbiG6Fyff0Wb/1i6oiiIncHJoiXUcw4b1/swQc=; b=RFJd1sJm2jtnYO9TlofEEwdR3K6UUfZKg8rpu5L5D9XKCZByOtotTWl4YBXcZmT1rjvnyhoYO1mO5Fi+alh2cafvi9Dgd8oWutT1uIjdPO/lxqmYVhgNmZov54tXH7B4NU9kafDpU70UjxKeBj0zhNTbxBysGTD4Krx3RdyIlpw= 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 1710304966755251.7833061568724; Tue, 12 Mar 2024 21:42:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGR9-0007xs-Bu; Wed, 13 Mar 2024 00:41:56 -0400 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 1rkGQq-0007ss-3S for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:36 -0400 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 1rkGQn-0001q6-Uj for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:35 -0400 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-649-82BSl_NyMbaWpaR4FYK6hQ-1; Wed, 13 Mar 2024 00:41:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 D28D580F7E3; Wed, 13 Mar 2024 04:41:29 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 975D510F53; Wed, 13 Mar 2024 04:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304892; 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=ryGN4lbiG6Fyff0Wb/1i6oiiIncHJoiXUcw4b1/swQc=; b=bTIClCB/oG6JnMS+XbTTJ8mtPuYdOTQbhLxrUMf5BPeJG+PcyLWyPCpfyD+6qHteGKAM8N 6vIq1hB5vN3YTaVo3mtpxcLHgOE2sZnmtF8xEVH3nc0ztLTBioHShX01rpsUKHAfa8jAPb K0RoAz1OxHVomZvOlBwgAKakC0AGJVk= X-MC-Unique: 82BSl_NyMbaWpaR4FYK6hQ-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 03/23] qapi: sort pylint suppressions Date: Wed, 13 Mar 2024 00:41:07 -0400 Message-ID: <20240313044127.49089-4-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710304967548100001 Content-Type: text/plain; charset="utf-8" Suggested-by: Markus Armbruster Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- 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.44.0 From nobody Mon May 13 09:21:40 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=1710305116; cv=none; d=zohomail.com; s=zohoarc; b=bdkHZLkpv/OGd1DTwAiSMFaY3Z6/kXg+7V7jolVhnp4ii806C+e3nsOkJ7pBgDomw/El1Y9I7ZDay907R5+NABnv+dDrHtgxxV2dBeq11TkJT/dHAfUtrPUD4ACM5OUs/Sl68ELFjLXPb8yNbLNq0NrzLOcwpejoQdqSujLXorg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305116; 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=ZaWfQ1rC9x4SKVgGa0KB8I8w8nJlBnOhw3104wyGhp8=; b=O1MNJCGh4xJi/eQ14r36f+xew25hnKiYyTv+SfjaFtwewkeKyFPO7xhKJMFra67nVWRXpLp8xyGVF0gEskvtgUCDr0/geviCtT+BpkX7bGpjaIx727soqe3sZu6IeH7xWVTSaXluGtO/n8Zojrxb/tzLWCVWtiItTSDzQjYbask= 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 1710305116084799.5365560783258; Tue, 12 Mar 2024 21:45:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRC-0007yt-8x; Wed, 13 Mar 2024 00:41:58 -0400 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 1rkGQu-0007uH-E7 for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:42 -0400 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 1rkGQo-0001qM-Rk for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:40 -0400 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-187-s2BFxgcmOoKpn6vnTl3K2w-1; Wed, 13 Mar 2024 00:41:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 2B913185A786; Wed, 13 Mar 2024 04:41:30 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id E0C9410E4B; Wed, 13 Mar 2024 04:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304894; 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=ZaWfQ1rC9x4SKVgGa0KB8I8w8nJlBnOhw3104wyGhp8=; b=iU1wv55HSftj4AV2L6wlkzwoUDK1BB9fw/m4jVFFz34EiihnBCmHbBPcphWBl1qXQvXxwB WAVH1S7imENp3HRbAPOc5omehMpIfjf+MVoO9siIu9Ai85qojwufX8m6dA/RavD+2ZNOio 41UtmATdC/yZoU5Zfp3GzHQHHD850jg= X-MC-Unique: s2BFxgcmOoKpn6vnTl3K2w-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 04/23] qapi/schema: add pylint suppressions Date: Wed, 13 Mar 2024 00:41:08 -0400 Message-ID: <20240313044127.49089-5-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710305117882100001 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 8ba5665bc68..117f0f78f0c 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: @@ -113,6 +116,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): @@ -131,6 +135,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.44.0 From nobody Mon May 13 09:21:40 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=1710305040; cv=none; d=zohomail.com; s=zohoarc; b=mn1i22FQbwDlT4QwVa/s+Upq4ir3oxcvU0dA1hqJbm21f6CrdGs2V8ibsvnSYuwchlh3LnCbWOqInVmbZu0aRUEpPliL/OKEbOwbKsAvKBKwtYHs2QG8siCTeh8VRNc0yod6yL1sp+xQbcQ+TLTSgiYHpW4Z39Fq4e5BZnkHSWc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305040; 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=C7yl0AfgHSgGLP6aV670HgQPmRa9Lqoz8sQ3s8sdUw0=; b=H2JkUb3Tuzx+WabNoO/YIpTPeqk2iAN/wCskAiokT4KglMsukZOHU+WmQcIr6AxxMJFG4gfXjpGB+C95zNkIgHdBqtlfiYC/JsD+9HT9XshDjrdntJHNNA0hP0hpuycPOEoBD0bPYSrBiEvmmcayE/u6SBGdkTTX3GY4E4EVaN8= 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 1710305040635111.50119285496726; Tue, 12 Mar 2024 21:44:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGR8-0007xW-A3; Wed, 13 Mar 2024 00:41:55 -0400 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 1rkGQt-0007uC-81 for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:40 -0400 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 1rkGQp-0001qe-8L for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:38 -0400 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-79-kQT3tL9dO_6oJLqVSSeyMw-1; Wed, 13 Mar 2024 00:41:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 7778585A58C; Wed, 13 Mar 2024 04:41:30 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B77F10F53; Wed, 13 Mar 2024 04:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304894; 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=C7yl0AfgHSgGLP6aV670HgQPmRa9Lqoz8sQ3s8sdUw0=; b=EJbC7/hMXS2s/tYjJukFILOz8l9XnSdxFJLP5fWrVbzChH6M8KX+1UEUpEqCOi0O/EWRtm k+u4vQyvV6TyDatihUyvEw40bc7gzgQpr1tUpFMyCzY+CfjfaXaOGRsRqGlNw9omJO41+/ QENEwIVmhhLHEE0f4K446Y2/tEu7TMg= X-MC-Unique: kQT3tL9dO_6oJLqVSSeyMw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 05/23] qapi: create QAPISchemaDefinition Date: Wed, 13 Mar 2024 00:41:09 -0400 Message-ID: <20240313044127.49089-6-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710305041643100002 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 Reviewed-by: Markus Armbruster --- scripts/qapi/schema.py | 144 +++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 62 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 117f0f78f0c..da273c1649d 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,33 +69,17 @@ 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 _set_module(self, schema, info): assert self._checked @@ -107,6 +90,46 @@ 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 + seen =3D {} + for f in self.features: + f.check_clash(self.info, seen) + super().check(schema) + + 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) + @property def ifcond(self): assert self._checked @@ -115,10 +138,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) @@ -218,7 +237,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): @@ -226,7 +245,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): @@ -797,7 +816,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, @@ -868,7 +887,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): @@ -939,23 +958,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) @@ -997,7 +1017,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 @@ -1023,15 +1043,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: @@ -1053,7 +1073,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= ): @@ -1068,7 +1089,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 @@ -1079,7 +1100,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 @@ -1107,7 +1128,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)) @@ -1137,7 +1158,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( @@ -1156,7 +1177,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))) @@ -1181,11 +1202,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'] @@ -1198,8 +1218,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.44.0 From nobody Mon May 13 09:21:40 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=1710305039; cv=none; d=zohomail.com; s=zohoarc; b=QHOd/5p06x87fMs9DgLztVAm5OwtXaPeK59IpQgPzqwkmmDAo37ZRp21ryDNFKVXWjww+POJSQ4v44KrHbH9mk78s4B8W3GO/XxHD0GK++BsZ0WJVGDXELmlfVRHUP4cNlMSiwmf9qe+Kfc4zIxFQSPZtpcuXPnsf2j9CjwwFlc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305039; 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=hb6845/ptUoZFt78sZpGJBHgkujHu+y0IDSvNrviRUw=; b=TcwptPzXAf3cGB/yE6usinreRIpi6GG8O9UkL9K/T6gT91yFIqo97Ydy4fLga55ByAC8jcYRlI/wnjcLVmA57TSJG+Pez7o9W7xzpt3i+/KAOR0kdMX+NG0mjXX2mR4X7xg10fvGaMXeeKmVFYKPF1x28M3lHFSFRlJp2w/kYsc= 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 1710305039839280.2859275292868; Tue, 12 Mar 2024 21:43:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRJ-00084R-AQ; Wed, 13 Mar 2024 00:42:05 -0400 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 1rkGQr-0007tD-An for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:38 -0400 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 1rkGQo-0001qI-S7 for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:37 -0400 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-651-XI8_zFdYP22GWwf_lE8-JA-1; Wed, 13 Mar 2024 00:41:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 158688007A2; Wed, 13 Mar 2024 04:41:31 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84BD110E4B; Wed, 13 Mar 2024 04:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304894; 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=hb6845/ptUoZFt78sZpGJBHgkujHu+y0IDSvNrviRUw=; b=elcgw3ZdKy41LfvK6la0sO1Q4/d8gED7Esug9iK/CsJWZeOrxuy6/vDxTLEvy99MphDoVa rz327/ULMh0q3xLy9p8lgC4/xmoXPfOXty72ttFhJ3KzN2nWzAOCARpOnReYv5S3PsmkvW 6cqEnBaQKMxe3J0AQPGkrI3irUG75bA= X-MC-Unique: XI8_zFdYP22GWwf_lE8-JA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 06/23] qapi/schema: declare type for QAPISchemaObjectTypeMember.type Date: Wed, 13 Mar 2024 00:41:10 -0400 Message-ID: <20240313044127.49089-7-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710305041604100001 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 Reviewed-by: Markus Armbruster --- 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 da273c1649d..8440a7243d8 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -786,7 +786,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.44.0 From nobody Mon May 13 09:21:40 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=1710305059; cv=none; d=zohomail.com; s=zohoarc; b=AEc0KKdwrhi7qqAw2MbsWdVAUCYmxIsCAZjBZ5XdJw8iyKIxhws1ModQK4JaIr9LgZXUqN/abTk8LwbSMnFjZrVU97lkgJ2qEKPte3znERwfxzyo5OTm/GSmr3Wl5EwGzLw+SlBARUffzpqUBqZlF9ICdd2AGT+2sjshFcaHruA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305059; 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=nmE9ahkr205qFik1K8btaIxpo/2jE6pdxITtjDV4o6o=; b=lDu4DR/X1PomO3iXc6Ep7WAZ5CLsrqsVoOLKy9abl7WZOCsEhQvp2IcA39m+N76549WXraAJ0aey23+4aI5VM7B4I5VeBOOCnE9PXcvtFZlJTx3Ym1o8IJevVju59VwcmoJWr5I561UCfHXKlppvacMrPLNgGcHm8w0miqwO2ag= 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 1710305059645812.5608074288634; Tue, 12 Mar 2024 21:44:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGR8-0007xQ-7R; Wed, 13 Mar 2024 00:41:54 -0400 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 1rkGQt-0007uE-MP for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:40 -0400 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 1rkGQq-0001rE-Kt for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:39 -0400 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-530-RzS_5vf1PFmRzfeyRIuFUA-1; Wed, 13 Mar 2024 00:41:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 6197C29AB3EF; Wed, 13 Mar 2024 04:41:31 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2419710F53; Wed, 13 Mar 2024 04:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304896; 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=nmE9ahkr205qFik1K8btaIxpo/2jE6pdxITtjDV4o6o=; b=CssBRUDDWrw7c+zNU6dQK9ssZUIOJlOWRwO4ypi5YZD7VuGBTXWzBqYC+omFiC+XwgjUK3 fVMSlqBPky2V7bhDARfrg+UqUYBwTVB7Ifu8VBRAYfR4ZqUIhzM+GCJbKOGZ9t3EVbNULI qX3OOLzLY4KAOyECcvMyM3MkWhk3ie0= X-MC-Unique: RzS_5vf1PFmRzfeyRIuFUA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 07/23] qapi/schema: declare type for QAPISchemaArrayType.element_type Date: Wed, 13 Mar 2024 00:41:11 -0400 Message-ID: <20240313044127.49089-8-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710305061676100009 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 Reviewed-by: Markus Armbruster --- 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 8440a7243d8..c549a4e3bd0 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -381,7 +381,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.44.0 From nobody Mon May 13 09:21:40 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=1710305031; cv=none; d=zohomail.com; s=zohoarc; b=VrAFLxdxPOCkNmITmZFeKfyCf40WSDzIUbAI7DdWFv3AJWOv7UeJ/38ydvlr6Z5EOAq2D/PVIW78upmbS8TOyN6OOiT8qoW2WZ2FyzpPC5roY9PAjIR72rd31nB/YKtR1fZfFQ7p9TbLCcWKFRGBdrO52aE3fjpj8iT7ZhfZKhU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305031; 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=Nwi1PGS3inlBc0HsQP+/+WWdThZFkOacbyB9odUZxNc=; b=aYkaypW+jC5G4ilsDNXD3FWYWec2mq2UtBbHcewDMWf3lXHn4ns7a6pEYJybxIFLNtQz3dS4MVZPeUEyEGgy5aWt22LNNg+/oKfnLWBeWude+jgOxcf6Uqml36xITaMqMIQwu2xcquCV0op8LZCuBwhOK+rE0tmiYXA2g4o+UV4= 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 1710305031615716.0379443514964; Tue, 12 Mar 2024 21:43:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRI-00084Q-MT; Wed, 13 Mar 2024 00:42:04 -0400 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 1rkGQs-0007tO-ON for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:38 -0400 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 1rkGQp-0001qO-1o for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:37 -0400 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-532-NlxeUEr_OvaLeJjetaQXNA-1; Wed, 13 Mar 2024 00:41:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 A8C3080F7E9; Wed, 13 Mar 2024 04:41:31 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FEB510E4B; Wed, 13 Mar 2024 04:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304894; 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=Nwi1PGS3inlBc0HsQP+/+WWdThZFkOacbyB9odUZxNc=; b=R3ryTRxutj02P6XyFnqBLKAYesTrc6tY7p0UaLTlK0VTFXOaExEBov7GzRmxcWZmlTiJuV pvvGJd+ajTENFxZjGEy0jRDVPUFVx/Ty54dMdjsk4WiVME8otR0rQR9wEEpZHIi3rfCLOQ QxEsW/DY/jV5QUDkiOhUvenYKlEPBTY= X-MC-Unique: NlxeUEr_OvaLeJjetaQXNA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 08/23] qapi/schema: make c_type() and json_type() abstract methods Date: Wed, 13 Mar 2024 00:41:12 -0400 Message-ID: <20240313044127.49089-9-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710305033573100003 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 Reviewed-by: Markus Armbruster --- 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 c549a4e3bd0..c316660adda 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 @@ -245,9 +246,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 @@ -259,6 +261,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.44.0 From nobody Mon May 13 09:21:40 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=1710305132; cv=none; d=zohomail.com; s=zohoarc; b=ad3RdQf86fCQhIWOI8dTEWelr0fbPCRYfTQwN7Zk+zQ/WKkAzfFfEy8Tdp5kPjYyx3giHw/GL1TYYFbmFfEWhK6Y8NCkwuBie0plXdedjvvr5V+hwufcgTHe0pl91Pzb2NNM8p7GWppMshD7/nxvjV6m2uSajKe+99kWSK6sKig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305132; 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=VNp64yiB83mW3/bjUVB4FpSDYTbHzpAyGn3E33Htr4U=; b=c7hWxe8OHc03ehqqMuTmpz4sV+QnAZPSvgEBTzNo08SuQpTv2HzJKEq8W6DpRw+KyAtt+H9e9MwxE4TfSgJXtt1XSYUkOeVE3vwYDKm+c64Cq/uRYP7AO+44KQ92nnkjAGdHxlpLg0psQ8uRWJXKp5h+WhSemk6GmMOztyy8Bdw= 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 1710305132499439.46761624090925; Tue, 12 Mar 2024 21:45:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRC-0007zH-LF; Wed, 13 Mar 2024 00:41:58 -0400 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 1rkGQr-0007tE-Eh for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:38 -0400 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 1rkGQo-0001qQ-Sn for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:37 -0400 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-554-qRtbDzT7O6-D_o5SfY8aWw-1; Wed, 13 Mar 2024 00:41:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 F19A7185A784; Wed, 13 Mar 2024 04:41:31 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id B70FA10F53; Wed, 13 Mar 2024 04:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304894; 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=VNp64yiB83mW3/bjUVB4FpSDYTbHzpAyGn3E33Htr4U=; b=GzuMwbMZJN7kTsR+8vbg71GYi/Ouvc1/ZGzpx3d/95fVyRTsvndzrlOeWy94F1GbsMhttV EYAFhh22tg+Lq7Xo5FKCn+y98xMCrloihUOQZX03QPt4b/nchTwiCqvw7/mUkI9k/tfjkm JlRjou7cx3mR01kBA1ztfqA3DRJvRwI= X-MC-Unique: qRtbDzT7O6-D_o5SfY8aWw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 09/23] qapi/schema: adjust type narrowing for mypy's benefit Date: Wed, 13 Mar 2024 00:41:13 -0400 Message-ID: <20240313044127.49089-10-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710305133946100006 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 Reviewed-by: Markus Armbruster --- 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 c316660adda..eeecdda1b58 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -843,13 +843,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, @@ -866,8 +867,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, @@ -903,13 +904,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.44.0 From nobody Mon May 13 09:21:40 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=1710305100; cv=none; d=zohomail.com; s=zohoarc; b=SftpjFsltNqoc/OQXdYo7x8su1k7/82lYmattHUDVrL8Fq3KIIWa4r7v4QXnp2HLgWRV9bYi6CXwTmvIjN2gEUsqjAjggDLOuaa/VmgTf5Ovz76/o2IMceiGpjLtzsxsR7vVedpt+16VMt0PXbB1eP1R9g4bEUmhI9GtwaE8mAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305100; 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=gcayLVk8OX4YVEhOTTxIGtEI0+5vRuh3Yy5xESbEliM=; b=X2emHPFBUGWYvfzQYvvrnM9SI5nklPU4RkoaPBpBwOayRSOiYcci92S3AOeki6XbD/4QgEZb2nu64ZaU3tzwy8wyxikic+P6SZ5EftXoQi95xjh9lIBvcbW59+pNHclfLGX9v3r22xav9xAz1BJy3N43Hce/5f9blQRM5tVgLpU= 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 1710305100693866.9092999465093; Tue, 12 Mar 2024 21:45:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRL-00086F-Ji; Wed, 13 Mar 2024 00:42:07 -0400 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 1rkGQs-0007tP-Os for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:38 -0400 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 1rkGQp-0001qj-4l for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:38 -0400 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-610-ds3-wlmPN8qH65eYpn-wow-1; Wed, 13 Mar 2024 00:41:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 46D36185A786; Wed, 13 Mar 2024 04:41:32 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BEF1111E5; Wed, 13 Mar 2024 04:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304894; 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=gcayLVk8OX4YVEhOTTxIGtEI0+5vRuh3Yy5xESbEliM=; b=ULeiJVP7j6GgTwAaqo5zJPUIHLQdP++ZP53Xp57dWS9oxLCJtOoUI1L5NUK37C2m5EYWHb ui4vvxp6tAKjwwZaFeYd9lbCG0XB7hMuP2BqKarsboRO2XdXTyEcjo5EiugGdmGvDukiza tX16+a6qJfZVQpd9+kP1LmqZj1Dava8= X-MC-Unique: ds3-wlmPN8qH65eYpn-wow-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 10/23] qapi/schema: add type narrowing to lookup_type() Date: Wed, 13 Mar 2024 00:41:14 -0400 Message-ID: <20240313044127.49089-11-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710305101803100001 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 Reviewed-by: Markus Armbruster --- 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 eeecdda1b58..b157a3b2bd8 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -989,7 +989,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.44.0 From nobody Mon May 13 09:21:40 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=1710305124; cv=none; d=zohomail.com; s=zohoarc; b=NqU3pXoZtwU/qpnTzggurOsSiHzaMOYgwNX1yddS1Y/lbhPA2wS5He2CW/ZJ+0eeb6BJePVrHdDvPUY6GS/D50vhZfEIQlciKP0TuhQ5c4cOQ7m9ye/rzFhNJNBiE6jGnsMg0pUVeCUWccHLKWUE7S0oZPzIm2QnpV6e0bAhtew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305124; 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=2I5t1vA5twX5O+nB7fme1OJngjl4AglH3dg6yYkL/Yk=; b=NsML/MaunAmxc7VtSQ1ViVPqZojUOgqkma0DHqAw5+12TkcD5zblSDpr5qIZAPH1V5DfeBtrcbBGM8OlcN01N7muqvKPFdyXRNS/hap3S/lVVj7Mc8AMhXmysY0lbcxDQVtRPdFqa0kIc+h89uZsEVH8eJr6u2FPQpmx2drcSiI= 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 1710305124163252.6710485841544; Tue, 12 Mar 2024 21:45:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRK-00084S-HT; Wed, 13 Mar 2024 00:42:06 -0400 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 1rkGQs-0007tQ-Qb for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:38 -0400 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 1rkGQp-0001qg-BA for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:38 -0400 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-643-SJ4GzRf-OHqWOasp9VzgvA-1; Wed, 13 Mar 2024 00:41:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 9048980F7E3; Wed, 13 Mar 2024 04:41:32 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54EEC10E4B; Wed, 13 Mar 2024 04:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304894; 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=2I5t1vA5twX5O+nB7fme1OJngjl4AglH3dg6yYkL/Yk=; b=SwhnGDRqT6ge3Ar1LwGZsScUts8LsDfA9SUyCm9ySs4Et9ZaZ/NYgH8Ics+94Aj8fI+Xc5 Z3GXqFxcbBsYeg7kMME+KkN26R1UmdacWBNETXKmtcaEpvIztH+/HoFC8LSV1c7tXcYXae V5tGKGPnjnAgzMXm79eNf3IRU8yjqc8= X-MC-Unique: SJ4GzRf-OHqWOasp9VzgvA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 11/23] qapi/schema: assert resolve_type has 'info' and 'what' args on error Date: Wed, 13 Mar 2024 00:41:15 -0400 Message-ID: <20240313044127.49089-12-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710305125951100001 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 by mypy 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 Reviewed-by: Markus Armbruster --- scripts/qapi/schema.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index b157a3b2bd8..f5c7789d98f 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -996,6 +996,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.44.0 From nobody Mon May 13 09:21:40 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=1710305116; cv=none; d=zohomail.com; s=zohoarc; b=OgvzRAX0PsQ7kWpQrD23YjeISyo8lhpC/Jj6KCTUbEd6eeJGXY/3Chhq+6wA/0FE8JXNz7eRGGBmpPtoEmhMnlXe5KP1Q4cnwe3RSYRNQ5yEmKL0Ns0vPRhyGhzy0lBHmbge0oLY/4jS4TMzGqhmH3MSyAcJVTD1kWwWEXVvafs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305116; 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=DTqB3WylAX51wzc5p0slRGOvWwmV6qQdPyDe8eBkKg4=; b=lQMWDnKUkDOEXaT2TUDAQej8N17tZHZqzGg/ehqFDWcloijblv+xhISWBxqI0nEAmXMt0fH9jpcMMQHJBj9tAR58oUMlzW4v0XOyj1qvmoeqdXunnot1ogFxpFe26aXIj2PTaozjkYnQCzik6lYCUhcDtZtodLETT035/xlRclU= 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 1710305116124890.5164500848521; Tue, 12 Mar 2024 21:45:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRD-0007zY-MI; Wed, 13 Mar 2024 00:41:59 -0400 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 1rkGQt-0007uD-E3 for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:40 -0400 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 1rkGQp-0001qv-Rt for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:39 -0400 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-556-xgqYwJTBM_iGsyW_s6Fegg-1; Wed, 13 Mar 2024 00:41:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 DE4043C0C885; Wed, 13 Mar 2024 04:41:32 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F1EB111E5; Wed, 13 Mar 2024 04:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304895; 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=DTqB3WylAX51wzc5p0slRGOvWwmV6qQdPyDe8eBkKg4=; b=Gb5OPDFQ8JXoCVgegAjdB3Eftxaa3mW//1CLYQpDqucAaVhIvIrM0GStfyF5kCcRRFCpCU KcsnTtUkeR4eQdjEt4TfckfSzcTWdW4rtm3WN3BpVkW0A2ZLF7cudpEvr15+OzzzABRvjg NZ5QMt4GZhfAuAD4tp0+6E1gZMhJ/So= X-MC-Unique: xgqYwJTBM_iGsyW_s6Fegg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 12/23] qapi: use schema.resolve_type instead of schema.lookup_type Date: Wed, 13 Mar 2024 00:41:16 -0400 Message-ID: <20240313044127.49089-13-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710305117892100002 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 Reviewed-by: Markus Armbruster --- 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 f5c7789d98f..58ec3a7c41c 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -642,8 +642,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): @@ -993,7 +992,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.44.0 From nobody Mon May 13 09:21:40 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=1710305204; cv=none; d=zohomail.com; s=zohoarc; b=nGygSY2Ncwt+g8EH5CXaPpWZ1gm/h/9m1mbqeqjtz2awOHiW+WgAopQocPTt0eHY3STCMK2TcQ/0PSomD24Fhfl0Vh99YJENLfEOVkcymZgkYT3affbDd/EsF8NOnijYiWsDdLGhxJOf9uqEAY/lIUI0kBBSH9afQtO2ACNaYoI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305204; 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=CCH8WZGnetuLi/Vjg7rgK5VnHrrnv6sYVRCoQHjt66c=; b=QopNVFzgeBJBR5MTWtxecL9jgN3uqxnQlw6CHatmP9QSfLFvxca9C3Anm5Bs3Uzs+3FakHu7AVMyirCsvYf7tWyWjTpWIOfJKFf7IRBsxuWrSDYIzFOX+8JQDP68p/5Jt51EoCXMXEr5VD3y4Z27c+Se6fUKYm9CGNVyaTwG3Fk= 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 1710305204756288.30842936409977; Tue, 12 Mar 2024 21:46:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRD-0007zZ-Rr; Wed, 13 Mar 2024 00:41:59 -0400 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 1rkGQw-0007vD-W5 for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:44 -0400 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 1rkGQt-0001sf-QJ for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:41 -0400 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-556-smsHN-FMMhydcYG1RCVh0A-1; Wed, 13 Mar 2024 00:41:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 3340729AB3F6; Wed, 13 Mar 2024 04:41:33 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA47610E4B; Wed, 13 Mar 2024 04:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304899; 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=CCH8WZGnetuLi/Vjg7rgK5VnHrrnv6sYVRCoQHjt66c=; b=CuAHQO9DPtV1PFGY2XsLnU0wpq5iw6jAQ8yITTjF5vv4vvioKdrJP4SnMs6/V1GGtctSot VCaQ7WAsE0b1YkwY+Zus+xYFw+UF1FMqJ0SbrpFtMh29GSgq9oaKVn0LGhmQbfKUxMBsxJ 8uQ15yYjH2n8sy8RNo/Z54lZjXiIDaI= X-MC-Unique: smsHN-FMMhydcYG1RCVh0A-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 13/23] qapi/schema: fix QAPISchemaArrayType.check's call to resolve_type Date: Wed, 13 Mar 2024 00:41:17 -0400 Message-ID: <20240313044127.49089-14-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710305206146100002 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 Reviewed-by: Markus Armbruster --- 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 58ec3a7c41c..22e065fc13d 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -395,7 +395,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.44.0 From nobody Mon May 13 09:21:40 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=1710305141; cv=none; d=zohomail.com; s=zohoarc; b=XfcDSTtVbxPfX96e6RjS1H1XuvAGF5r8Sr9uYy4v+0QetNuLZBdLzGrztD4tN6us6byM2LvgrC7iaibgNT3rNjOaISrFP1z+X5kDCwNOqbGUg+mr4e6iXWBgy/Ks+9ZvLjtbBcFrlmkPLODjoKgYUToGzzn9YuQPfvM7CxmQU7c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305141; 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=DbHP73B2mtfkEhWK170YnmX6bUMcBxSm9VcnBgUTU2k=; b=JGoTlPJqEvn7gDRIOMUX9J0CJqZdYOFqzKkv+2ail22tjYXLiDdyzksFhdL68pl3FiOXVNkPpDCE7Apo7W+RbIiBwXE163oDH3PZSxf6Hisd7c7l0eMJKgWMoYYDoVEjI9ycX62dRBuC5IwU8t48qb533e9uJU1n3znoEGpngsw= 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 1710305141744194.93477252698767; Tue, 12 Mar 2024 21:45:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRG-00082k-OQ; Wed, 13 Mar 2024 00:42:02 -0400 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 1rkGQx-0007vP-LA for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:44 -0400 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 1rkGQs-0001rm-GJ for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:43 -0400 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-558-TbqmcWdJONCMMTZoDeUzLg-1; Wed, 13 Mar 2024 00:41:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 7D824380213A; Wed, 13 Mar 2024 04:41:33 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4195F111E5; Wed, 13 Mar 2024 04:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304897; 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=DbHP73B2mtfkEhWK170YnmX6bUMcBxSm9VcnBgUTU2k=; b=HV9nwkRoh+UENK35QRj5mDUchOR7JVyU5TDWQuPyGl3aTRO0e6G17SGVHHDfaBK/oKMPVn jA13UoZgJl5acdMvqonIhhj1xyvCBiuPh4ucj1jsUTOzATHtoFC1gQWBbhlgmnQ5/IuCxW YIwa+TqpkdEZKzsK+OvtBZ4lilMJg2o= X-MC-Unique: TbqmcWdJONCMMTZoDeUzLg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 14/23] qapi/schema: assert info is present when necessary Date: Wed, 13 Mar 2024 00:41:18 -0400 Message-ID: <20240313044127.49089-15-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710305141954100001 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 Reviewed-by: Markus Armbruster --- scripts/qapi/schema.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 22e065fc13d..d514b3c28f6 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -750,6 +750,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) @@ -840,6 +841,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.44.0 From nobody Mon May 13 09:21:40 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=1710305101; cv=none; d=zohomail.com; s=zohoarc; b=LorguqjJrXc/pbuMQRmRRDHPWt4DqCQpuszNN572Hbwjt2rvo5/goO4ERHwMAcNrEnOr4kotU/ZqHtnVhi41lynhJZ2Ns17fbaerxkXw+3b3uhcY6vA+96sHBU5e6MvuYa0YRYVht2eeJ2jb51xeiJqAVX22SzW1mMYDQTaOMrg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305101; 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=vDBILCYokuD+BvPljO3SV3muUHZxbA1WQCNU/LWfLsw=; b=nukwaThOqhRFt8XewlybmgpjOyl9AhpBJujpYc+x36T+LUy/NXDq32xjXsyThMgDOu57FOgabPHh1YeWoR+EonpYO3yTkDn9PfuZ3s7OtDQFX+sad+SHTqtiEIp95DZaXtkF6KC4dxjJgfh8NmOkBOGPfTRKrsiGZt1Abejmw9I= 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 171030510104580.8413341429216; Tue, 12 Mar 2024 21:45:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRC-0007yw-F3; Wed, 13 Mar 2024 00:41:58 -0400 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 1rkGQx-0007vM-Du for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:44 -0400 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 1rkGQv-0001tN-He for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:43 -0400 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-647-RYAPmci5OfqE8mE5f9PJ6w-1; Wed, 13 Mar 2024 00:41:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 C73D785A58C; Wed, 13 Mar 2024 04:41:33 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C49C10E4B; Wed, 13 Mar 2024 04:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304900; 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=vDBILCYokuD+BvPljO3SV3muUHZxbA1WQCNU/LWfLsw=; b=MKeJMofyJZBfJ1Sc+ZLWw46R4NCTA4GHCXRcv8omVJsCd2G0J/Gi8uOysGwkzE1Mhay/R6 PUig4Qpxh23f9gbckGQNsuso2BUjiiS7YoIwrENV/Jbs8iZADIhFkrpEqVY9KH2HjBbx8B dPb4751JqepBuCnNgK1oj9ecz7XIok8= X-MC-Unique: RYAPmci5OfqE8mE5f9PJ6w-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 15/23] qapi/schema: add _check_complete flag Date: Wed, 13 Mar 2024 00:41:19 -0400 Message-ID: <20240313044127.49089-16-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710305101819100002 Content-Type: text/plain; charset="utf-8" Instead of using the None value for the members field, use a dedicated flag to detect recursive misconfigurations. This is intended to assist with subsequent patches that seek to remove the "None" value from the members field (which can never hold that value after the final call to check()) in order to simplify the static typing of that field; avoiding the need of assertions littered at many callsites to eliminate the possibility of the None value. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/schema.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index d514b3c28f6..50ebc4f12de 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -450,12 +450,13 @@ def __init__(self, name, info, doc, ifcond, features, self.local_members =3D local_members self.variants =3D variants self.members =3D None + self._check_complete =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: + if self._check_complete: # A previous .check() completed: nothing to do return if self._checked: @@ -464,7 +465,7 @@ def check(self, schema): "object %s contains itself" % self.name) =20 super().check(schema) - assert self._checked and self.members is None + assert self._checked and not self._check_complete =20 seen =3D OrderedDict() if self._base_name: @@ -487,7 +488,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._check_complete =3D True # 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.44.0 From nobody Mon May 13 09:21:40 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=1710305125; cv=none; d=zohomail.com; s=zohoarc; b=Bw7kXxNm+/5wnsLj8Ds3mDZNqhuDe0HpPuketWPdsKyEIBGJJ/+h6AFT1jJy77Hlxa0Am331ngB2tiXnQ+xxpY5xnvIa+ZkLvQatGaOCfasMZ110AhQZiUxSrwYOR+kv92+8YrZb+w88L92RAvB3uuFf5lnZuWI+ubuLqlFH8dI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305125; 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=B8T6l1nkITPsHA3ff3vpDB9Fc3LR0VgnTn5VXh/nU+Y=; b=N8HhfeWXcRyfING1SWBpevDX7P33IlmE/xvcyjBgs8fsmkkSFdIAyRG7965SEw7A2zj8GZ/XTNvV4af7THqxgQo/R1CDVUUDYrvRZtxFome+z1sTeIHchxjC1XjC3dSMdcsBLVbnnkqMo9+IDOLP45Kf9aDjWadE53JxH0XUf3M= 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 171030512510424.099282922983434; Tue, 12 Mar 2024 21:45:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRB-0007yZ-7Y; Wed, 13 Mar 2024 00:41:57 -0400 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 1rkGQu-0007uM-SQ for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:42 -0400 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 1rkGQs-0001ry-OB for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:40 -0400 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-558-gNZNUUzqOVeSxAkisoRPrw-1; Wed, 13 Mar 2024 00:41:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 1B8C4800268; Wed, 13 Mar 2024 04:41:34 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id D4D9B10F53; Wed, 13 Mar 2024 04:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304898; 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=B8T6l1nkITPsHA3ff3vpDB9Fc3LR0VgnTn5VXh/nU+Y=; b=CqHaec0C9/su8zpy4bIJM++Z3YQ6B0z1iMhN7rAjFmen4UgWMyhUGtxPdFStoaN+yFLfHe vnTk4aC3oioHA3+9Jeoo6dKQQR72n+NeZQ8Zd7iDUdtFnIbkenOq7bjHHmDZxaWZA+Gpzi wCk/LVlh9czHWmS8eJ8c+IFZrmZR6IQ= X-MC-Unique: gNZNUUzqOVeSxAkisoRPrw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 16/23] qapi/schema: Don't initialize "members" with `None` Date: Wed, 13 Mar 2024 00:41:20 -0400 Message-ID: <20240313044127.49089-17-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710305125963100002 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/_check_complete fields.) Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/schema.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 50ebc4f12de..fb30314741a 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, @@ -449,7 +449,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._check_complete =3D False =20 def check(self, schema): @@ -482,7 +482,11 @@ 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 works in terms of the supertype, but local_members + # is asserted to be List[QAPISchemaObjectTypeMember]. + # Cast down to the subtype. + members =3D cast(List[QAPISchemaObjectTypeMember], list(seen.value= s())) =20 if self.variants: self.variants.check(schema, seen) @@ -515,11 +519,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.44.0 From nobody Mon May 13 09:21:40 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=1710305058; cv=none; d=zohomail.com; s=zohoarc; b=UsQV9V6Sg67dZCpUN0hGrScTuKfeiPUp4suBnOBWfFTOaNugPejPTMwJ8LKIFSKCvYzSDDnfsQhSj9x1E54rZ91rGOknebl3/tOT0XLcbMPmxW8oq2XmkBMqIloUIrZ0ZEChEsjelnWr61XRIROLWHKIW15ZJZjZ/JuvlPMIIpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305058; 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=WEDIoVPOeTuf+QVZMJaYVYq2r7iKETXU0cn8JtACErE=; b=BcEuQBK/DwUBOmCDAZNqcg7fdwRDyHbWIlf2dM12mgC4uUUT+12co2BM8wgpdS3p36NsO8FbGCl6doJ2vJl36ICKKWBVeQ/dhiiUA1Yx5Xx/s9VgjVojI/JVk7ad4r7aT3l5FxYZPvgXzTu8y1HTJeVQprUSAGN5xfQblTL3xM4= 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 1710305058396539.9699997769862; Tue, 12 Mar 2024 21:44:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRB-0007yY-4P; Wed, 13 Mar 2024 00:41:57 -0400 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 1rkGQu-0007uF-6Z for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:40 -0400 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 1rkGQr-0001rS-AQ for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:39 -0400 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-558--xfbeI5TOT6VIbkZZhrUjw-1; Wed, 13 Mar 2024 00:41:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 624B71C05AE9; Wed, 13 Mar 2024 04:41:34 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2881710E4B; Wed, 13 Mar 2024 04:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304896; 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=WEDIoVPOeTuf+QVZMJaYVYq2r7iKETXU0cn8JtACErE=; b=U59bbtF05ABJboorLZEunUdds+7TIzh7P2jnOPwxc33/xeGMtBVnRSFOQFMap9QJFNyc/8 MNzY8lErKTlf+HghRJN0G/mT4XkD0xaIfAxEydVf2/X37v5zqF5p/s4bfy1RXTD8RKWWME DqXMYcECkazEgB/dpihbYOie6GhoP+Q= X-MC-Unique: -xfbeI5TOT6VIbkZZhrUjw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 17/23] qapi/schema: fix typing for QAPISchemaVariants.tag_member Date: Wed, 13 Mar 2024 00:41:21 -0400 Message-ID: <20240313044127.49089-18-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1710305059720100003 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 Reviewed-by: Markus Armbruster --- 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 fb30314741a..39f653f13fd 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -627,25 +627,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 @@ -665,11 +679,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.44.0 From nobody Mon May 13 09:21:40 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=1710305197; cv=none; d=zohomail.com; s=zohoarc; b=mZ0NZQku9AEJwepeoypE6MTrmPItU4VR/IC222h6AFhY62nb9nPBCHyqwn4l8YubtOKsEhQgEUiNxcCTs4z0oCRNVvY6nYqc1F/UzHevVC7orPA01lpUYAERGWfnDBDUdmgfAb30hZL1pPgxCNlbQfSXESm3eieiHIJGspgejKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305197; 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=sYDsDCrGqE3cjrmd52lK26TXCSjR12gSUoy0kxO2XdE=; b=VRxUHciaGe1XihuudxLHTkLGHDL0RuvRGfT7Z+Smf4XezWC4ZnpCdjMXKh4mIvIiOW/zllJRhWuKLX0MQl9F2mZOpBDLVxEECO2At0ezLIzqxxXpC9Cc2+yz4s2O2I223DPpnMnzH3bpFrabVctpfxpIA0FQhnhh9J19jCS+FZE= 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 1710305197792339.42988041851515; Tue, 12 Mar 2024 21:46:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRE-0007zs-Ft; Wed, 13 Mar 2024 00:42:00 -0400 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 1rkGQx-0007vL-C2 for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:44 -0400 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 1rkGQu-0001sq-4o for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:43 -0400 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-611-F4DGufEqOFmMElCqqKeHww-1; Wed, 13 Mar 2024 00:41:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 A9B208007A3; Wed, 13 Mar 2024 04:41:34 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F1CA10F53; Wed, 13 Mar 2024 04:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304899; 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=sYDsDCrGqE3cjrmd52lK26TXCSjR12gSUoy0kxO2XdE=; b=IZHtM0OfwuTFUOypB8mnTcnAFsWKxXilaSJSUJXDFLmoiorXXDgPCGyINb/i44vG4Mq0ZB FAIaAQ1dk9gEEEOwitveWImbebxmlRjDkPHGV9RVhkRaeZ3NSbDfXH+nQUmV3Q1mMQ+ZUO SppmWMSsHtJ6+3s4XwM7+ZFFWg7oGIs= X-MC-Unique: F4DGufEqOFmMElCqqKeHww-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 18/23] qapi/schema: assert inner type of QAPISchemaVariants in check_clash() Date: Wed, 13 Mar 2024 00:41:22 -0400 Message-ID: <20240313044127.49089-19-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710305198113100001 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 Reviewed-by: Markus Armbruster --- 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 39f653f13fd..3b8c2ebbb5f 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -715,7 +715,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.44.0 From nobody Mon May 13 09:21:40 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=1710304956; cv=none; d=zohomail.com; s=zohoarc; b=L1vrptbZbp1/QY4G+buylahe1KPCpdCfvTY58qumcpptT6U6XZKN2pAdK2kr7nyXsETyQduk/J8y3/94dru+2bx1rnx5U+qCn4BcfO4K5nINlNejuxcAlimxf5TIt1aF4aY/VoBu8kzcdgcfIwxPAnymx4vK31iQ6xYeePIeJao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710304956; 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=NavLvS6rBldL7oxXMuG+C39E9A+moUuZMnnLhZNAYms=; b=kpDIJBp02yNhAiCDJBRERhF+NvE8yLDyehNZYXzYwfS2x8WBGz5qVDGA2zjIWSULwqzpBzDDobaAXVUTmrtZp0Tn0v+R8M/AAyQ9HZASPRp8ndJ28IvPwSW0U2SsDtiVt1r3Sr/H/rBHDpi39q373Aqf+UYtwAdZZ386sUO2GBk= 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 1710304956711843.768089821772; Tue, 12 Mar 2024 21:42:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRF-00082K-NM; Wed, 13 Mar 2024 00:42:01 -0400 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 1rkGQv-0007uQ-KC for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:42 -0400 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 1rkGQt-0001sM-JY for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:41 -0400 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-611-035zUkxCOviLYvlSpVseXw-1; Wed, 13 Mar 2024 00:41:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 F27F029AB3F5; Wed, 13 Mar 2024 04:41:34 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8148175AD; Wed, 13 Mar 2024 04:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304898; 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=NavLvS6rBldL7oxXMuG+C39E9A+moUuZMnnLhZNAYms=; b=SFiEK2/NUVLme3E1+hjpK4MS31xSZJaF9HDT6wq84ecqNJARKAskXxs4lzppmSTwByV/yn cBf1JT3Fuep+io+Mv9QJ9tZ6kpHNFqU+rlXZ4VbE7gMadNNbiJpcUP/olU/tEeS2NwzHtj Rc/ILMbLmuJ/cqF3X1iC38jhyGF5R8s= X-MC-Unique: 035zUkxCOviLYvlSpVseXw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 19/23] qapi/parser: demote QAPIExpression to Dict[str, Any] Date: Wed, 13 Mar 2024 00:41:23 -0400 Message-ID: <20240313044127.49089-20-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-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.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710304957861100003 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 Reviewed-by: Markus Armbruster --- 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 ec4ebef4e33..2f3c704fa24 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.44.0 From nobody Mon May 13 09:21:40 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=1710305239; cv=none; d=zohomail.com; s=zohoarc; b=m/JH+TaFCT6982pyZi9btKcCAJSrHX5BW2rqrJCHhUOCU6glWdBrW9qmUtpdgZZs+Pja3lRTL2uJgrKLM50xhPiau/a6U7feboIJwrWQYJPeG9mMVUpBJQ3IdUEDbLcicZ5BJ8MTckjjQX/ox0F6MR7V3ATDchiO3DDDH1Nm1qY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305239; 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=iiPw2apbpe1XJcFWVgqw1Vt5RvDKxKtkjHU12JG5Zgs=; b=AvkPFloOvGxbJaLLA8HfR0hFm6A/DFYoCyKQgMkDmScYuDDMBu54Y0ko5uMQx8ZMIXQTrD3SpLqSNZ7KshRTjud8lTatYbr/fi3mpytQ4lIutuVanKmtQ/hFhU42ZnA2zIz8APkWNwtXOrVnh7K3fCGjb+5RTba7h/yLA28NU+o= 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 1710305239266978.3737427868381; Tue, 12 Mar 2024 21:47:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRM-00086U-MY; Wed, 13 Mar 2024 00:42:08 -0400 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 1rkGQu-0007uK-Im for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:41 -0400 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 1rkGQs-0001rk-H7 for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:40 -0400 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-619-4IIw7_AVOOu1WHXesv7FLQ-1; Wed, 13 Mar 2024 00:41:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 47377185A784; Wed, 13 Mar 2024 04:41:35 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C26B10E4B; Wed, 13 Mar 2024 04:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304897; 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=iiPw2apbpe1XJcFWVgqw1Vt5RvDKxKtkjHU12JG5Zgs=; b=DVPJkJ5YyaXkcZN1ZJuzJHorroOSn9gwAPQ2qEL3krWQin8l/bIqqW+Y2NkE0xwRkMFlwu joyvCDAzPRk/XbAcTh0fHTpe5uqZNtG5EtzQW54SRX80203KzHpX1Sxn8+T1SwNFkv8jx8 lPqfErxtocntBI3jNabh/pYYcfjRFYU= X-MC-Unique: 4IIw7_AVOOu1WHXesv7FLQ-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 20/23] qapi/parser.py: assert member.info is present in connect_member Date: Wed, 13 Mar 2024 00:41:24 -0400 Message-ID: <20240313044127.49089-21-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710305240262100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 2f3c704fa24..7b13a583ac1 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -707,6 +707,7 @@ def append_line(self, line: str) -> None: =20 def connect_member(self, member: 'QAPISchemaMember') -> None: if member.name not in self.args: + assert member.info if self.symbol not in member.info.pragma.documentation_excepti= ons: raise QAPISemError(member.info, "%s '%s' lacks documentation" --=20 2.44.0 From nobody Mon May 13 09:21:40 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=1710305258; cv=none; d=zohomail.com; s=zohoarc; b=fHRvZnK3wZQuXaccb4RLJ69I6so8qHjJAJDeYOYJXbvkvqlohmrCDcg6os+tEmgz1//KeHHFey8jpodMBRsGOKTEKi3D4NG0lkkmeZ18J5dt9m+SzNnKCklZWTQ+hL6Znp+/JI6yyyvjqTUowVYffOCedywCu0c5AxSo9IMNWX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305258; 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=l6Odprvxjy6pMT3s+sZOXZi0Aae1e7fQzafmowF7FBA=; b=OLPnFh4rkw2U5I0QOiORk/2aNRbBxfMy59trio/TgLF6Seiss5N8YvpyyVXNv+tU6dsM8qCH2tHBaMnsuTHEmtl4x+r+VQFUEVO8FsxOCH+IUfWm7TClo2viKXZ9uLfqLEaRHAw+6sNWYTCxpR5HisT2Fn764cB8A+NgeZUXZ7c= 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 171030525860481.68753353042302; Tue, 12 Mar 2024 21:47:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRO-00086h-Ar; Wed, 13 Mar 2024 00:42:10 -0400 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 1rkGQy-0007w2-Ut for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:48 -0400 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 1rkGQu-0001sl-0K for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:44 -0400 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-619-1hAJV16kNXyZsRLpCwzOHA-1; Wed, 13 Mar 2024 00:41:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 9EEC31C05B02; Wed, 13 Mar 2024 04:41:35 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59DC4111E5; Wed, 13 Mar 2024 04:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304899; 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=l6Odprvxjy6pMT3s+sZOXZi0Aae1e7fQzafmowF7FBA=; b=icg3s8rH2WztqXHt9ONzuqDTYiHm36mXsdWK5vnT3maxSB3lvT+hCjuUsvUoNXMk1DZJAk IxoC+tY+XPNx77j+eH9Ufd2AWOiql/YgtGRTcpMQNo4Ewxajzy76it00+FMo4wn7f0XjLu alaKmiX6lvRbMJgO/KjRwc/UoYrd4/o= X-MC-Unique: 1hAJV16kNXyZsRLpCwzOHA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 21/23] qapi/schema: add type hints Date: Wed, 13 Mar 2024 00:41:25 -0400 Message-ID: <20240313044127.49089-22-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710305260454100003 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 Reviewed-by: Markus Armbruster --- scripts/qapi/schema.py | 568 ++++++++++++++++++++++++++++------------- 1 file changed, 396 insertions(+), 172 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 3b8c2ebbb5f..d2faaea6eac 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,34 +86,43 @@ 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 _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 []: @@ -110,21 +133,21 @@ def __init__(self, name: str, info, doc, ifcond=3DNon= e, 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 - seen =3D {} + seen: Dict[str, QAPISchemaMember] =3D {} for f in self.features: f.check_clash(self.info, seen) super().check(schema) =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: @@ -132,62 +155,120 @@ def connect_doc(self, doc=3DNone): doc.connect_feature(f) =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 @@ -195,9 +276,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: @@ -226,10 +307,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): @@ -237,11 +318,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 @@ -250,22 +331,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', @@ -277,17 +358,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(): @@ -295,7 +376,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 @@ -303,7 +384,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', @@ -311,24 +392,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 @@ -336,7 +417,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) @@ -345,32 +435,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, @@ -380,60 +470,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) @@ -452,7 +553,7 @@ def __init__(self, name, info, doc, ifcond, features, self.members: List[QAPISchemaObjectTypeMember] self._check_complete =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). @@ -498,14 +599,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(): @@ -513,32 +618,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, @@ -551,7 +656,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 @@ -559,7 +672,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 @@ -567,8 +680,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() @@ -597,26 +710,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. @@ -627,11 +746,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 " @@ -639,11 +758,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)) @@ -712,7 +833,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. @@ -726,18 +851,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( @@ -746,11 +880,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 @@ -782,14 +916,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: @@ -799,12 +939,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) @@ -816,19 +964,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: @@ -838,24 +986,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 @@ -863,7 +1029,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: @@ -899,14 +1065,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, @@ -918,14 +1084,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( @@ -947,14 +1122,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, @@ -962,7 +1137,7 @@ def visit(self, visitor): =20 =20 class QAPISchema: - def __init__(self, fname): + def __init__(self, fname: str): self.fname =3D fname =20 try: @@ -974,9 +1149,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) @@ -986,10 +1161,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) @@ -1006,18 +1181,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 @@ -1032,23 +1216,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 @@ -1056,7 +1242,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'), @@ -1085,31 +1271,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() @@ -1125,7 +1332,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') @@ -1136,7 +1343,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:] @@ -1147,13 +1361,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'] @@ -1165,13 +1383,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'] @@ -1196,7 +1420,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) @@ -1214,7 +1438,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') @@ -1239,7 +1463,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) @@ -1253,7 +1477,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) @@ -1272,7 +1496,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() @@ -1281,7 +1505,7 @@ def check(self): for doc in self.docs: doc.check() =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.44.0 From nobody Mon May 13 09:21:40 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=1710305204; cv=none; d=zohomail.com; s=zohoarc; b=Zx6jYno8+RQ6AZUi+ugug4OsAuc5sz/sOys03mqaqGHGhEQpbZyTpRfQGD8XsAlfPbNRuGG0hrKoFE//GZUv4Lg2HwtTanEedn9g9lI/wXQ4yxrEi64FDTx/czAVVOb144xXsNQc+49Ox0Ro52+0ID3XMFhW094iugT61T+ZmgM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305204; 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=bx3EHnsEmcvVefVjCE8VVdLYHyjdxGGfvCmgZC2jPVU=; b=MaGVudpjUciOXyvqd7A2YMGFWURih+cPW3n+aqcJ5NAMSDhY9GYLL1kW75DRGMgCcuwoYZTiB+RJNjsx7Fq4r7RHK6WonxyYUHY9lwKIMMXq98jtjKuXoUATrENUv9JpeRnhqmtwLJS+Wb4EeQzDYiyreGlbbViiiQvSMuy4XFQ= 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 1710305204927602.6470638167592; Tue, 12 Mar 2024 21:46:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRE-0007zu-GG; Wed, 13 Mar 2024 00:42:00 -0400 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 1rkGQv-0007uO-AA for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:42 -0400 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 1rkGQs-0001rw-RR for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:41 -0400 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-403-FIA7Ap21N76OUFllxYjoyw-1; Wed, 13 Mar 2024 00:41:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 E810D185A781; Wed, 13 Mar 2024 04:41:35 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADCEC10E4B; Wed, 13 Mar 2024 04:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304898; 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=bx3EHnsEmcvVefVjCE8VVdLYHyjdxGGfvCmgZC2jPVU=; b=WnsdCUh/HatBzIUlSIB74b5sRqxelh3rBDyvP2+W65dEi7UK3HmrEZgDxK7l3eM2nQ/f7A zf6L6L6aJvA9p1phmPwgLy8svsa00RjiS6g3pJxpgdTVsBGgOstjVHtVXPkYsRmgzdD5+o fwi8qbQwgLBPK5LioWcwuRhETI2IaTs= X-MC-Unique: FIA7Ap21N76OUFllxYjoyw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 22/23] qapi/schema: turn on mypy strictness Date: Wed, 13 Mar 2024 00:41:26 -0400 Message-ID: <20240313044127.49089-23-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710305206145100001 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 Reviewed-by: Markus Armbruster --- 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.44.0 From nobody Mon May 13 09:21:40 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=1710305130; cv=none; d=zohomail.com; s=zohoarc; b=KuqBqQpApAem/Mv6PPfa16ieYdqgLBCv8LMh2timnI67pZrmjf/YDD0I3h39wPZK5knGZFvQWkhM0HD6oyH4BC37//Q66HX4ipLDJPujw6nueDutodsrutjMU5SxFLQusT+PDSzzljaUVdMsDHVWmhS1xejC/OGA2pK+fKvZgxI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710305130; 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=RvtrkMOEfqhsQDoRE6/5bd/EgdkgzrqkxiRpjpwJPnw=; b=F91N+QU/WRBLHWInv2+jvCPze7d4kscEomclL9ufoyWN5yZkEbpdJnHfQeTAg/Gff0Bdu0JNyuF0mteOYU4zzfATmqlsh+NKsb1NBPYM3KpTfc4789/q+zBZARA2z1xJdE0ytdUdklM0pP8CXass+jNinmkzdd+JrbEgdPs6k7w= 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 1710305130259269.01588353739453; Tue, 12 Mar 2024 21:45:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkGRN-00086Z-Im; Wed, 13 Mar 2024 00:42:09 -0400 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 1rkGQx-0007vE-1a for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:44 -0400 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 1rkGQt-0001sV-Lt for qemu-devel@nongnu.org; Wed, 13 Mar 2024 00:41:42 -0400 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-645-f3uAtmCSOC2ik3yLYTtKmg-1; Wed, 13 Mar 2024 00:41:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 3EF5E1C05AE9; Wed, 13 Mar 2024 04:41:36 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.16.65]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03928111E5; Wed, 13 Mar 2024 04:41:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710304899; 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=RvtrkMOEfqhsQDoRE6/5bd/EgdkgzrqkxiRpjpwJPnw=; b=PFxJIBFMbVzvWQODIoOEdq7MqAGryrgeZeDsI1lOm7ait22uDb2RFS0VQ8ZekTUn7WOGsw lSF9Nc+YIWzfZeeChFj3fTHQJ8U35zGPpJmTL5kdijP6uIcS7SIBOFHz5s3vCeFYSSL0fr +9nBBuD2VmgWzy+Z8xWYpyjyAFt5wts= X-MC-Unique: f3uAtmCSOC2ik3yLYTtKmg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v4 23/23] qapi/schema: remove unnecessary asserts Date: Wed, 13 Mar 2024 00:41:27 -0400 Message-ID: <20240313044127.49089-24-jsnow@redhat.com> In-Reply-To: <20240313044127.49089-1-jsnow@redhat.com> References: <20240313044127.49089-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: 1710305132015100001 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 Reviewed-by: Markus Armbruster --- scripts/qapi/schema.py | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index d2faaea6eac..ffd9170f577 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -123,10 +123,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 @@ -163,7 +161,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 @@ -377,7 +374,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 @@ -386,7 +382,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 @@ -429,9 +424,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 @@ -474,7 +467,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 @@ -519,7 +511,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 @@ -539,12 +530,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 @@ -666,7 +654,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) @@ -742,8 +729,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 @@ -857,7 +842,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() @@ -925,7 +909,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 @@ -954,10 +937,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() @@ -965,7 +945,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: @@ -1016,8 +995,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 @@ -1057,7 +1034,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( @@ -1095,7 +1071,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.44.0