From nobody Wed Nov 27 04:35: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=1700099302; cv=none; d=zohomail.com; s=zohoarc; b=BNroXVAb7rf9GOK8TwnNEYsQZNp3HGc5NxVmheQ0bITVEUjNNy3/5u4ISuQnPw6d81nC6j1jw5EtNLGd/+y5Auuov+VmGrBE5PTi3EsuyipzkG1Vvl72RAVJEYE1mmWzvD4ds2XNbb/5/D4A5wDKiK8RjpsNhGczbDLdadhiTLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099302; 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=Gb8CAZVMsVsHjLgjk1Zt5AMrISOZgCh7rMmJiIH9KEM=; b=GwAPz6wJDYVptmCqZQppLxO9rDWDb/LeXZ6BEqag4izbo/ne+Ryo/iook4yoORlwvbrP/gFNT2lZfB+EkF5VpAKa1KevtZJHfhGkU1BFrRef7gtsgZ6306CjI2qiwRzFGTvk0z+Htl2gBVHjNgHWcphiIbqRBVfRP9t6xdK/H6I= 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 1700099302378957.7420741829392; Wed, 15 Nov 2023 17:48:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQL-0005Im-Bg; Wed, 15 Nov 2023 20:44:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQJ-0005GI-KL for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQE-0001zq-4V for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:03 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-381-_xUr2OrcP36ttdrqveUZKg-1; Wed, 15 Nov 2023 20:43:51 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 99D3E3C11CC1; Thu, 16 Nov 2023 01:43:51 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5615CC15881; Thu, 16 Nov 2023 01:43:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099037; 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=Gb8CAZVMsVsHjLgjk1Zt5AMrISOZgCh7rMmJiIH9KEM=; b=hJ1ayTXn2Y+5RqsBI1LsGiHDU7vVP1IVcNFwx58sfnfLyyMlWkwyek5OPCqLMat55EMkWc YXGqV4ed73dutJXhBrbaxm2fhzYSG08ys6XoAyCUJi/kYFifyp9XABlHdv4W9MWjhN/ZAR JDd1ev1Ge+C6zjvMZES3eNYamLhf9+c= X-MC-Unique: _xUr2OrcP36ttdrqveUZKg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 01/19] qapi/schema: fix QAPISchemaEntity.__repr__() Date: Wed, 15 Nov 2023 20:43:32 -0500 Message-ID: <20231116014350.653792-2-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, 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: 1700099304071100015 Content-Type: text/plain; charset="utf-8" This needs parentheses to work how you want it to: >>> "%s-%s-%s" % 'a', 'b', 'c' Traceback (most recent call last): File "", line 1, in TypeError: not enough arguments for format string >>> "%s-%s-%s" % ('a', 'b', 'c') 'a-b-c' Signed-off-by: John Snow --- scripts/qapi/schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index d739e558e9e..c79747b2a15 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -76,7 +76,7 @@ def __init__(self, name: str, info, doc, ifcond=3DNone, f= eatures=3DNone): 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) + return "<%s:%s at 0x%x>" % (type(self).__name__, self.name, id(sel= f)) =20 def c_name(self): return c_name(self.name) --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099171; cv=none; d=zohomail.com; s=zohoarc; b=WUvHp8i9Htp+b5uOHJuSkQAIOGflHBEhbmPi6834ZTfSZ9tWM7tk9MO76DxPlAr+l/Tq2CW9M3PeyOyoBhcbZM0PXv7qCW9VmqmM+zPkYXCGIAlevNxoO8vLVGJ/Y1bOxJFL+5czJugMbtxfjENfuQcOTPWHvsURV93hN/ft9Sc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099171; 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=08it7JyTmlqZ2qYMjBMaLdaRQndHwtSJh7g5239FHgk=; b=h6GG2nIF3YMndRGcpeuwv8vDI712X6vbKgkR/DL/2yPeAV79vB+cgbuHxesGv7cnVykIzDQQoSX0UU2Z23wS0ei/aifDo8Lc9TGBVTmPYgIbXzr0SW1uZO9wPg1qy1CX/BZb9L82aMcv5kgxPieC7vs1T5v0QYFf/2X6JPYaJJM= 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 1700099171111156.52912378331018; Wed, 15 Nov 2023 17:46:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQJ-0005GD-JK; Wed, 15 Nov 2023 20:44:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQH-0005Eo-S8 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQC-0001zP-EL for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:01 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-477-4VQTjWjoPiWX20yeV7hLDw-1; Wed, 15 Nov 2023 20:43:52 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 EC51C1C05EC3; Thu, 16 Nov 2023 01:43:51 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id A946CC15881; Thu, 16 Nov 2023 01:43:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099035; 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=08it7JyTmlqZ2qYMjBMaLdaRQndHwtSJh7g5239FHgk=; b=JhmnLFXY9Kn8PsH5BTcQbnEVheP+vf/r0l2+cCZt/UHKtklw8uOo64C2HTSB49oIY4b/Pu RoeGGUx6C3DpCz15idzHfxtEPHfGkOEJe8ikzvo2ytTkP/bTxy2q+qTcYdQJ9D9njBGv14 GnvaQzNZeflj+g2GCqUTr7kI9FWK/FE= X-MC-Unique: 4VQTjWjoPiWX20yeV7hLDw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 02/19] qapi/schema: add pylint suppressions Date: Wed, 15 Nov 2023 20:43:33 -0500 Message-ID: <20231116014350.653792-3-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, 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: 1700099171600100009 Content-Type: text/plain; charset="utf-8" With this, 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 | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index 90546df5345..aafddd3d8d0 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 c79747b2a15..153e703e0ef 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -13,6 +13,7 @@ # See the COPYING file in the top-level directory. =20 # TODO catching name collisions in generated code would be nice +# pylint: disable=3Dtoo-many-lines =20 from collections import OrderedDict import os @@ -82,6 +83,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: @@ -116,6 +118,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): @@ -134,6 +137,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.41.0 From nobody Wed Nov 27 04:35: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=1700099301; cv=none; d=zohomail.com; s=zohoarc; b=HA+CS4flgbbyENcWQRmEBzBUIWAEGNQLNJN3sui/3PQBUi4xSQwJUsk9hUQ5BIaYkNJOLNmzWzFLcWaPb8MxesUCBzNRhldTPuuxZ+2u50RAy9NTqdEGsr1eNTUhAeSkwPh5EVnSne3I69R5htCW0gkYeWK3LNuFdbPW8L6+LCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099301; 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=pizuQG2VKmmCYLJ6GmUnliG1sq7KBbVuRhIS3gCZAzg=; b=LRU2cjK0QMFVrHYqudOLRx6RcdgDEsr2dvN44OnWXL7OHyVdhTX2JNmeDobIp+t6SAa95FTMc/uGEmJS3UArFAOJo6KeAu4vC+c4PhxM7A4C0ofeBDqa4OMJmks3lZELUnIncgrEHSM475MzgQx/46ks0IPIFOAyNSpWzzOasIM= 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 1700099301922101.58107780595162; Wed, 15 Nov 2023 17:48:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQJ-0005Gv-VW; Wed, 15 Nov 2023 20:44:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQI-0005Ew-6k for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQD-0001zc-RI for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:01 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-32-7GvnHjE4N3KMuACPqNLOLw-1; Wed, 15 Nov 2023 20:43:52 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 4DCFF185A782; Thu, 16 Nov 2023 01:43:52 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 09159C15881; Thu, 16 Nov 2023 01:43:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099036; 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=pizuQG2VKmmCYLJ6GmUnliG1sq7KBbVuRhIS3gCZAzg=; b=BzR1Ov3+mHHR3hCsl0FDCGPhaWR1UdLz6RWxdFurZi0AOLlgl/+kZe6ENPZXMH6HX9A7zD vBRentjjBV5Dt3Gh1XUxUL9qPjgR1hq8KOxaFJ4zL9weRlF4alCS805nF8z731GXkL1ZMg Q8chcpfGaEcaBnwmyi+z45QaYALk4QQ= X-MC-Unique: 7GvnHjE4N3KMuACPqNLOLw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 03/19] qapi/schema: name QAPISchemaInclude entities Date: Wed, 15 Nov 2023 20:43:34 -0500 Message-ID: <20231116014350.653792-4-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1700099304059100014 Content-Type: text/plain; charset="utf-8" It simplifies typing to mandate that entities will always have a name; to achieve this we can occasionally assign an internal name. This alleviates errors such as: qapi/schema.py:287: error: Argument 1 to "__init__" of "QAPISchemaEntity" has incompatible type "None"; expected "str" [arg-type] Trying to fix it the other way by allowing entities to only have optional names opens up a nightmare portal of whackamole to try and audit that every other pathway doesn't actually pass a None name when we expect it to; this is the simpler direction of consitifying the typing. Signed-off-by: John Snow --- scripts/qapi/schema.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 153e703e0ef..0fb44452dd5 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -220,7 +220,9 @@ def visit(self, visitor): =20 class QAPISchemaInclude(QAPISchemaEntity): def __init__(self, sub_module, info): - super().__init__(None, info, None) + # Includes are internal entity objects; and may occur multiple tim= es + name =3D f"q_include_{info.fname}:{info.line}" + super().__init__(name, info, None) self._sub_module =3D sub_module =20 def visit(self, visitor): --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099092; cv=none; d=zohomail.com; s=zohoarc; b=OPMt+Km1/uhMPR1jpe5v1IQPj/FiB2Y36+cZj7CffDqUQjOQ0LZlwTGT7ytoMNGE4hAaU5DpMt849gs8yURZ412ofYcAu5Z+cT1HI7I6G50+CJa6bOkZ0GjsPkiS8E5jtRWM+36ODoFcrOf8apSgxAoLdoxhehu1g2aNWfWkzxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099092; 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=Kg3m98RICCt6Ri/bKbY7xmy4OwxNVxaMaqze8HLBBIw=; b=MD34znRvT4oT8CGMCDlT0Gy4pUmV69JhygdxOEFZKOFCF+1FZblwxPitMfP2WCC3Ao+fTVMl47M0W7CRn/xJ/X9UGnNmuWFxuJygMhsWJ4oKgyym+n5bVD2BfnRfvSqlO9aCuskBH6yUjk0XzWU3ktxNWOcQZkJuNoTdQUNSXLI= 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 1700099092961249.16472179796665; Wed, 15 Nov 2023 17:44:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQI-0005GB-Sc; Wed, 15 Nov 2023 20:44:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQG-0005ET-LO for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQB-0001zJ-Dq for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:00 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-466-Lsh9LAnTNrGRG4fXX0Ea0g-1; Wed, 15 Nov 2023 20:43:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 9C7C33C11CC0; Thu, 16 Nov 2023 01:43:52 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BE7FC15881; Thu, 16 Nov 2023 01:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099034; 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=Kg3m98RICCt6Ri/bKbY7xmy4OwxNVxaMaqze8HLBBIw=; b=NM6XqBF+Jp9Sa1fnUg8YRfiqTm2PbTwOgskeVryuFToVh+d/W4geSdjhfjWL7uacMJq46J c2eyUqRK/4v8o1FhyqTxP8CrnSxHHqQB42pQ3Cf4O5tgQmBeNCJK8yLtSgV6L2TxpUfVJJ f4bdBo/LW1zj9L8WjTFuzRDY/w6YsYQ= X-MC-Unique: Lsh9LAnTNrGRG4fXX0Ea0g-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 04/19] qapi/schema: declare type for QAPISchemaObjectTypeMember.type Date: Wed, 15 Nov 2023 20:43:35 -0500 Message-ID: <20231116014350.653792-5-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1700099093694100002 Content-Type: text/plain; charset="utf-8" declare, but don't initialize the type of "type" to be QAPISchemaType - and allow the value to be initialized during check(). This avoids the need for several "assert type is not None" statements littered throughout the code by asserting it "will always be set." It's a little hokey, but it works -- at the expense of slightly incorrect type information before check() is called, anyway. If this field is accessed before it is initialized, you'll be treated to an AttributeError exception. Fixes stuff like this: qapi/schema.py:657: error: "None" has no attribute "alternate_qtype" [attr= -defined] qapi/schema.py:662: error: "None" has no attribute "describe" [attr-define= d] Signed-off-by: John Snow --- scripts/qapi/schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 0fb44452dd5..c5fdd625452 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -771,7 +771,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(). Kind of hokey. self.optional =3D optional self.features =3D features or [] =20 --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099169; cv=none; d=zohomail.com; s=zohoarc; b=C9wwT0WzNKmbWHThC5Qoj7+b+FztD66gJEFCifuNVI2piOi27u2Uxy+UyZND3BLg3QEDP+gnjjO7B3aqk4/55QOILza11zIugLRVoW34Mt0J4oPOwUfZKfV4l2c2TqrFTYc7Wc4aVeR0HLtASOiPRHtLRtn657Zc/JAKyE62t+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099169; 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=LUNYTwKFIURIMs3zNQb1pL4DzA4DI1sItK09tnGDlGw=; b=miBDjOn0yxiKUulGnBQuciY4DpBqut0uJNTArtXN1dEi7mXkYtdC21mtHUoW8BjOsYlibVngK0sY7ov/bmk8ycdMwoeMz4LUrS0yqpllVDxOjdHs+SnvHKLLz71hkxloZJEN1Xe4gkOBN56rPBNE3h6eAUPBEzszvGdLUfRlUQU= 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 1700099169580494.7403163602356; Wed, 15 Nov 2023 17:46:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQQ-0005LE-OX; Wed, 15 Nov 2023 20:44:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQJ-0005GJ-Kf for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQD-0001zf-SM for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:03 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-7-V9uUfdNq--p_dRs5O1Zg-1; Wed, 15 Nov 2023 20:43:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 EBED3828B20; Thu, 16 Nov 2023 01:43:52 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACA21C15881; Thu, 16 Nov 2023 01:43:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099037; 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=LUNYTwKFIURIMs3zNQb1pL4DzA4DI1sItK09tnGDlGw=; b=hClPuCE7FahmpbYZyBjgPrB0WoE4fX3GiK1F4eLP7X7XrDqEPETUnpYyPe1IeOBaJfepAW d/z4E+Dr6Eqz1DQFcaLKS+RueSDYxHsA13+2q4t5LgtAAJLJXIk1a3jdyNVSyCBWuPMdeM SxDUpvoBdkjyLZ21UZMFN2mHbxXO5+0= X-MC-Unique: 7-V9uUfdNq--p_dRs5O1Zg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 05/19] qapi/schema: make c_type() and json_type() abstract methods Date: Wed, 15 Nov 2023 20:43:36 -0500 Message-ID: <20231116014350.653792-6-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, 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: 1700099171573100007 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" by raising NotImplementedError(), which requires subclasses to override the method with the proper return type. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qapi/schema.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index c5fdd625452..4600a566005 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -233,8 +233,8 @@ def visit(self, visitor): class QAPISchemaType(QAPISchemaEntity): # Return the C type for common use. # For the types we commonly box, this is a pointer type. - def c_type(self): - pass + def c_type(self) -> str: + raise NotImplementedError() =20 # Return the C type to be used in a parameter list. def c_param_type(self): @@ -244,8 +244,8 @@ def c_param_type(self): def c_unboxed_type(self): return self.c_type() =20 - def json_type(self): - pass + def json_type(self) -> str: + raise NotImplementedError() =20 def alternate_qtype(self): json2qtype =3D { --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099301; cv=none; d=zohomail.com; s=zohoarc; b=nNPHjizgmoJc8yuJ1/UJOJ0LkTM3+ZrFjUeUOSch8mINXSzTwCxXgMJEp7MigXlLzH2/77A63UWNvnHmvnXTc6aRaK/a7ib6slJAWlZfTLjOygSQp8Kl9psAN0PRN22QnT/2Ez8RpmQR6cyCzswQZYKNi2H01zjuqb546o/gbdk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099301; 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=AbiChjSL/2Si4PQ35HQcRARm4HUx3rnT4JAXvzmVC2A=; b=BzPJEcs1SzmGiwHWIj5Q5ydSB0dqn0rWBY1CnyeCVpJxZFmglj7BJSNvr7BO0q3VVqeIPihaChS7HmL2bX+q7S0Dg2Fe9bjdo/lAWvF7lJhztL7jhApjInYVNYnQnpK87TGGs+AwFD5Ssv6Jn/C/CvPsdjt0MuHzJbA75FXYuUI= 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 1700099301735905.4599922482483; Wed, 15 Nov 2023 17:48:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQY-0005M8-MK; Wed, 15 Nov 2023 20:44:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQJ-0005GP-N5 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQE-0001zw-2D for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:03 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-450-_LK-HtIcNYyX7P_NWkR8kQ-1; Wed, 15 Nov 2023 20:43:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 504D7101A529; Thu, 16 Nov 2023 01:43:53 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EA8DC15881; Thu, 16 Nov 2023 01:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099037; 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=AbiChjSL/2Si4PQ35HQcRARm4HUx3rnT4JAXvzmVC2A=; b=LMzcP+xbLjGQU4lJ9Vo9wxgWNTcGSaF51/XLXUZrkveez/uLdcN4wBZPfGMFCfCgHXRxiJ w1pqxs+f9jQ9T528oZKxM2T8ji+siVcWHysb4iGfzxn1TSHY8ILvchBin4WAwjPm28SFgA qV83lCHQVqGmz2ugNq32Xux9KLFTHOU= X-MC-Unique: _LK-HtIcNYyX7P_NWkR8kQ-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 06/19] qapi/schema: adjust type narrowing for mypy's benefit Date: Wed, 15 Nov 2023 20:43:37 -0500 Message-ID: <20231116014350.653792-7-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1700099302039100009 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. A simple change to use a temporary variable helps the medicine go down. Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qapi/schema.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 4600a566005..a1094283828 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -825,13 +825,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, @@ -848,8 +849,7 @@ 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, @@ -885,13 +885,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.41.0 From nobody Wed Nov 27 04:35: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=1700099092; cv=none; d=zohomail.com; s=zohoarc; b=lqiTANU6bd5tMTpvrs5EM2pN4d9o044L/VKWWvIUfozSsqkc9X7mEiL8ph0eR83DweSOKtE21nc1rLQXU6catTgkKmANgBvjIN92WdHlvIO/pe7HEmVOR3nkt2rBKFZjwkxeISNv58pM9wZ3oAmrh6NdEdSLPOOulB5AzX4Mcb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099092; 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=DEsxYWL/rvlUKgzze2QNRGRzTzXyfu0i4Gw01lfJ6SI=; b=HFu7HqEFhwQGn1dcKL0tKELNa8A4OdkLmX1Ai2ID3F2ovKqSXpA+Cv068u4mnvV9HpRnFtcVb3wsD7ELE6Bhq2eZazNV2ZidKdBhV7KaIhhNo+CpoMvbBF4TtXTPt/tQ/DE8VsDFY56q1+0v8sCVW22H1OON3fWFBdH+pqvpSpg= 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 1700099092632102.8148638660972; Wed, 15 Nov 2023 17:44:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQL-0005It-Gx; Wed, 15 Nov 2023 20:44:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQI-0005Eq-3x for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQD-0001zZ-P9 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:01 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-292-F_tLtw9RN768TLHrAPfXtQ-1; Wed, 15 Nov 2023 20:43:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 A43773813F24; Thu, 16 Nov 2023 01:43:53 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FDB3C15881; Thu, 16 Nov 2023 01:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099036; 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=DEsxYWL/rvlUKgzze2QNRGRzTzXyfu0i4Gw01lfJ6SI=; b=PFBRti6wz4m0gzQAuAJX77ReKO8cidd19RwtQ1TdtVkzn0HoynzWxxhF9cLVAbT2FFpW/O j+ezATN8fxCbxMhpHdUEcxWb2y7puILrac6E/rnU/uqt8Z8TGvfrZqgN1qRf9DJMWhkKkc gLTD2Move7ovah1M/ujXQsGAkv7OaSs= X-MC-Unique: F_tLtw9RN768TLHrAPfXtQ-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 07/19] qapi/introspect: assert schema.lookup_type did not fail Date: Wed, 15 Nov 2023 20:43:38 -0500 Message-ID: <20231116014350.653792-8-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1700099093693100001 Content-Type: text/plain; charset="utf-8" lookup_type() is capable of returning None, but introspect.py isn't prepared for that. (And rightly so, if these built-in types are absent, something has gone hugely wrong.) RFC: This is slightly cumbersome as-is, but a patch at the end of this seri= es tries to address it with some slightly slicker lookup functions that don't need as much hand-holding. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 67c7d89aae0..42981bce163 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -227,10 +227,14 @@ 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') + tmp =3D self._schema.lookup_type('int') + assert tmp is not None + typ =3D tmp elif (isinstance(typ, QAPISchemaArrayType) and typ.element_type.json_type() =3D=3D 'int'): - typ =3D self._schema.lookup_type('intList') + tmp =3D self._schema.lookup_type('intList') + assert tmp is not None + typ =3D tmp # Add type to work queue if new if typ not in self._used_types: self._used_types.append(typ) --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099299; cv=none; d=zohomail.com; s=zohoarc; b=YTWaSM6yimwst6ZdBAA+bu/+/UEtO0xMJPfQcM6pxTC/nPr57JHy8Hj4d4xBTNZLV/SEuax9Lw4y7TNL3ESYuMUFQOfCBmix4HMNhiszTH9KokxH+AMC0wnOj9NUi1hsRgslNG3ZfyA2HOrmHjXGziVuS63KHWuBxycOGn/zbIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099299; 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=HYLkqBBvaIhpzJOuU0P3RkHpLlo+uQ+r8gLb/DfUIYQ=; b=PM8hu/MxnunO4N238RnfgQNUxX/JOcuVu8SEdzJrMjcKz46zKaWyIl7Fwe7mswIvERn/k5xu9L6Ly4eQlGAFTn3FmtHy5N+SE+iCsKHmzw3BlAw/S2CtGHkCufYPG7pFHRlsOnoYbauadqW7bIumhgXCh5j+5412IrZgNTkKq7k= 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 1700099299348807.7921028814899; Wed, 15 Nov 2023 17:48:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQJ-0005Gc-Ta; Wed, 15 Nov 2023 20:44:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQI-0005Ep-3J for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQC-0001zV-Sn for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:01 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-50-d-EWvkQQNhOZ5xqTmAOxwA-1; Wed, 15 Nov 2023 20:43:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 040ED1C05EC9; Thu, 16 Nov 2023 01:43:54 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id B58F7C15881; Thu, 16 Nov 2023 01:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099036; 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=HYLkqBBvaIhpzJOuU0P3RkHpLlo+uQ+r8gLb/DfUIYQ=; b=QbcyyOkXeWfc/0HRttLGxQZ/eEsbSSd1SlK7y4fNfCpiL2NvCO56Ue9g5Ew0aOm+k1z2tF vTmD084M5kfffOlkIaRqGEQTI/bIKXE2OstJXmzp2ui05Hr9QJG8CxpqUlI5ZWAP1/oETW fEuqZybopxyBabCZghKQl1589jfAsoM= X-MC-Unique: d-EWvkQQNhOZ5xqTmAOxwA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 08/19] qapi/schema: add static typing and assertions to lookup_type() Date: Wed, 15 Nov 2023 20:43:39 -0500 Message-ID: <20231116014350.653792-9-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1700099300027100003 Content-Type: text/plain; charset="utf-8" This function is a bit hard to type as-is; mypy needs some assertions to assist with the type narrowing. Signed-off-by: John Snow --- scripts/qapi/schema.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index a1094283828..3308f334872 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -968,8 +968,12 @@ def lookup_entity(self, name, typ=3DNone): return None return ent =20 - def lookup_type(self, name): - return self.lookup_entity(name, QAPISchemaType) + def lookup_type(self, name: str) -> Optional[QAPISchemaType]: + typ =3D self.lookup_entity(name, QAPISchemaType) + if typ is None: + return None + assert isinstance(typ, QAPISchemaType) + return typ =20 def resolve_type(self, name, info, what): typ =3D self.lookup_type(name) --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099299; cv=none; d=zohomail.com; s=zohoarc; b=MseZylvqzXSo3hJjaRFIUtRvfjh/BXu9dVL1c9d3/Wy68cp9NblHGkCOEZOiTBnzKHZygCWPlINckgnspR7AuAu4vPas8TwsjPpNiEuFNTuf9lXccLwEXLttgtCM+l7JiY3EwZrpYtWkibJmAzasqrWvr7/7KDwGqSzhbxX1ntI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099299; 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=xCAXe+RXvP9aNPfdOK7rQogOvX6tsD3P/HmDMl4jIYA=; b=JV8efA3gthwz1ol7+lKKrkFLqrpqPZLnHVKT/i7E+7stMQGE2ni24ciOVmEoLJRYneqyvAht3VPgFLBNDXtwmIhtpCEvpn4LiABytFpLdFqKVdH2vzt/WjC5TaO2NFNcznH6R0A+/7A2yROSOZlFS3ZPPrbDz4dFczBJnfTB8BA= 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 1700099299807924.4858752349911; Wed, 15 Nov 2023 17:48:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQO-0005Jp-Ja; Wed, 15 Nov 2023 20:44:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQJ-0005GM-LV for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQE-0001zp-20 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:03 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-511-Tvtl6IfANB-HwN9aaIQgtw-1; Wed, 15 Nov 2023 20:43:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 587A03C11CC1; Thu, 16 Nov 2023 01:43:54 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15AD5C15881; Thu, 16 Nov 2023 01:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099036; 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=xCAXe+RXvP9aNPfdOK7rQogOvX6tsD3P/HmDMl4jIYA=; b=IYs3RH8vpnDga1bQ5PUAfy6k2e1zUbtcCZv1z85Fx3eo3W/w7oOGe13cJhV774ejqXUs9e lZVo8QXbpEtIJhw1m9wJuLDM2Na7+QayMPsI+mWvRaciw8Nubi037R/ImIRYhsMR5N59ji hp39iZTYvorXVwnDf9Y9sOwN+auC98k= X-MC-Unique: Tvtl6IfANB-HwN9aaIQgtw-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 09/19] qapi/schema: assert info is present when necessary Date: Wed, 15 Nov 2023 20:43:40 -0500 Message-ID: <20231116014350.653792-10-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, 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: 1700099300027100004 Content-Type: text/plain; charset="utf-8" QAPISchemaInfo is sometimes defined as an Optional field because built-in definitions don't *have* a source definition. As a consequence, there are a few places where we need to assert that it's present because the root entity definition only suggests it's "Optional". Signed-off-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- scripts/qapi/schema.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 3308f334872..c9a194103e1 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -733,6 +733,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) @@ -823,6 +824,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.41.0 From nobody Wed Nov 27 04:35: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=1700099176; cv=none; d=zohomail.com; s=zohoarc; b=iaH5PAKwGSvdZb2hP8twJAWUq5xeDIAAZRO4bOnChuU81jAfuyyoBGkUk19Dictq3kzvbIoKrkelz+3Htjk3rWBaH+KKqhN1TIMvpNB5Jd5lqSrKDOwDI/0xrMk5L92oGhpWxsMtgBNUV+v7LZaSxOKb6t3JuneWJYrN9tlSw30= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099176; 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=oK5TLvGHeEz6GjH3xnyCpoO4sbbIXKIwxy0cQYHdnKU=; b=kP00ztzqJHeSpd83KMampfqC5bV8mwipC4dAPtW/u2kYqH+FXlIq5YaBuMjXstZ+9Ag329onULyA6zBG+JSaj03ZypRJtXwQzIM4su8P4SFHF67pe/GralDirPh6cEWgpARPR/FV1zaARbOh8iYusRVFcJd8t3ZE2xU4H45pUJk= 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 1700099176037104.44291063521382; Wed, 15 Nov 2023 17:46:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQO-0005Jn-JH; Wed, 15 Nov 2023 20:44:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQJ-0005GL-L1 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:03 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQF-000206-D4 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:03 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-467-D7I6cy5ZNd-imEiGH6G__g-1; Wed, 15 Nov 2023 20:43:54 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 A656E3813F43; Thu, 16 Nov 2023 01:43:54 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66600C15881; Thu, 16 Nov 2023 01:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099038; 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=oK5TLvGHeEz6GjH3xnyCpoO4sbbIXKIwxy0cQYHdnKU=; b=dlazBobFX5fhJ1/b2hDjl3r7HQON6JUgVDe2mNb5vzWH21p6B9oEM1w3lidjjxoASueq6V OmPfJbq8DDDhTTytzvtqrVaU/PCQGifPgN/zKD2z8CSoKgb65F8MUhxa/LOs+aaTmtU91H +RY7eYQGn8Xj9sGQqiPovIovNtRJDaU= X-MC-Unique: D7I6cy5ZNd-imEiGH6G__g-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 10/19] qapi/schema: make QAPISchemaArrayType.element_type non-Optional Date: Wed, 15 Nov 2023 20:43:41 -0500 Message-ID: <20231116014350.653792-11-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, 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: 1700099177578100003 Content-Type: text/plain; charset="utf-8" This field should always be present and defined. Change this to be a runtime @property that can emit an error if it's called prior to check(). This helps simplify typing by avoiding the need to interrogate the value for None at multiple callsites. RFC: Yes, this is a slightly different technique than the one I used for QAPISchemaObjectTypeMember.type; I think I prefer this one as being a little less hokey, but it is more SLOC. Dealer's choice for which style wins out -- now you have an example of both. Signed-off-by: John Snow --- scripts/qapi/schema.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index c9a194103e1..462acb2bb61 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -366,7 +366,16 @@ 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: Optional[QAPISchemaType] =3D None + + @property + def element_type(self) -> QAPISchemaType: + if self._element_type is None: + raise RuntimeError( + "QAPISchemaArray has no element_type until " + "after check() has been run." + ) + return self._element_type =20 def need_has_if_optional(self): # When FOO is an array, we still need has_FOO to distinguish @@ -375,7 +384,7 @@ def need_has_if_optional(self): =20 def check(self, schema): super().check(schema) - self.element_type =3D schema.resolve_type( + self._element_type =3D schema.resolve_type( self._element_type_name, self.info, self.info and self.info.defn_meta) assert not isinstance(self.element_type, QAPISchemaArrayType) --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099312; cv=none; d=zohomail.com; s=zohoarc; b=Rl8FEuFfxMl4eY7wLSaHk7i7yPUuPukXVMFAFicOw8adqPHVBJBmVr1y5kmuEr6VedA0sIeV53SV6tbYzer+XJM7Gc74EEs4rsynMDhgzrnwl//xj+HUu6K0Fk5kFhN8pHJOGOfshaGqToEiDVZXE81xDINgjKJFtdUtwjMjtOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099312; 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=QXJzx/jpVoPhmJMyDwQ8ccRKvqe6ESeYERwYom9inLk=; b=C4eKKDIPgtf9WwgCuY4q6tUjLFRfzAB+3et5qfVpP4PVEXTgxEgLieuNYbLKDWtTfVrCNOTnKBf8mEggVIbKuiuZxbuA+uNY2Zg/RcdLge5sFtx4khmi/3RIRq4weuLaUz7bX6La5xDOiXIP3AidkycIZ70ksqqL6cdx7Staheg= 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 1700099312301408.1883156536255; Wed, 15 Nov 2023 17:48:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQR-0005LI-2x; Wed, 15 Nov 2023 20:44:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQL-0005In-3y for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQF-000208-HB for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:04 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-Mt4ACs1HMxGBvCyWTu9jfg-1; Wed, 15 Nov 2023 20:43:55 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 05BA1101A529; Thu, 16 Nov 2023 01:43:55 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6CE3C15881; Thu, 16 Nov 2023 01:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099038; 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=QXJzx/jpVoPhmJMyDwQ8ccRKvqe6ESeYERwYom9inLk=; b=Ow6rXgaBaVsA59YbAe7uc1uP5jKzjur9n0Cp+XCrdEJzLOdnY108IbCK8Qp3guB8Zn5CmB j481prJjXrWtPqgNZHpMvLdg8J6LSQdBO/6xOWKz0imZw2UVYuNZfpLJxx5I2HxWwAKSFQ ndo0mQ+29PUuklU0mwdI/b8yG7a25As= X-MC-Unique: Mt4ACs1HMxGBvCyWTu9jfg-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 11/19] qapi/schema: fix QAPISchemaArrayType.check's call to resolve_type Date: Wed, 15 Nov 2023 20:43:42 -0500 Message-ID: <20231116014350.653792-12-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, 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: 1700099314206100003 Content-Type: text/plain; charset="utf-8" There's more conditionals in here than we can reasonably pack into a terse little statement, so break it apart into something more explicit. (When would a built-in array ever cause a QAPISemError? I don't know, maybe never - but the type system wasn't happy all the same.) Signed-off-by: John Snow --- scripts/qapi/schema.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 462acb2bb61..164d86c4064 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -384,9 +384,16 @@ def need_has_if_optional(self): =20 def check(self, schema): super().check(schema) + + if self.info: + assert self.info.defn_meta # guaranteed to be set by expr.py + what =3D self.info.defn_meta + else: + what =3D 'built-in array' + self._element_type =3D schema.resolve_type( - self._element_type_name, self.info, - self.info and self.info.defn_meta) + self._element_type_name, self.info, what + ) assert not isinstance(self.element_type, QAPISchemaArrayType) =20 def set_module(self, schema): --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099316; cv=none; d=zohomail.com; s=zohoarc; b=D42EUBK1OENGzCKPMvQe5FBsrvDKUQS2zYoW/l0xieR/7EdMgXFFyfkiGpHKGOWhJGVGofhJD0ygOy2UA9ci8/PwA6646Zd4350nlaFh94oj6ufb9h6gqn3eKiMhi8ZyEXeqwlXXha5hPqq2jdXAh4uff+af9BCsZYPqWpjRFKU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099316; 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=gi5EYqfimKMm9nEhPGFz0iR7hcyEZzY6gH4iQaJdxSU=; b=U4EwqILF/FipeMycPJTEnOHkvjvI3G1t5e/W4H72J4re6MBzNEBqnBeyenX5hRdcQ6ih/s0j69em4wJHwK0x6w3hoeqa7c6mIFyrrFf2ZRqm6UwLyl7+DTDL3kEEQGRg6Tb1LCdcnIVVnSHDNG3mbTN+iW4G1FXMERihcNHTOGE= 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 1700099316770924.8865592157387; Wed, 15 Nov 2023 17:48:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQL-0005Iy-GY; Wed, 15 Nov 2023 20:44:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQI-0005Ex-78 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:02 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQD-0001zi-RW for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:01 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-412-NmgZ6iOIMmCGsDMei6hEew-1; Wed, 15 Nov 2023 20:43:55 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 55F13101A53B; Thu, 16 Nov 2023 01:43:55 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 169C9C15881; Thu, 16 Nov 2023 01:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099037; 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=gi5EYqfimKMm9nEhPGFz0iR7hcyEZzY6gH4iQaJdxSU=; b=EfHsGCBzR9GlbFtMAuMUU5qWN8lfx8e6KZyyOAt1SYMYWNbBCNe7HIibvxLrWoPZ1D6ohY W9zyy0eZgbAIHqN2lxg69tAvcfudPgLU1L64s3V2jAIdsiZpzxRyIr9Ww9lpXXSdGR6Y7T 4HTyAxTknWIVmZDZEdWCGZFfcnaWUqQ= X-MC-Unique: NmgZ6iOIMmCGsDMei6hEew-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 12/19] qapi/schema: split "checked" field into "checking" and "checked" Date: Wed, 15 Nov 2023 20:43:43 -0500 Message-ID: <20231116014350.653792-13-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1700099318082100005 Content-Type: text/plain; charset="utf-8" Differentiate between "actively in the process of checking" and "checking has completed". This allows us to clean up the types of some internal fields such as QAPISchemaObjectType's members field which currently uses "None" as a canary for determining if check has completed. This simplifies the typing from a cumbersome Optional[List[T]] to merely a List[T], which is more pythonic: it is safe to iterate over an empty list with "for x in []" whereas with an Optional[List[T]] you have to rely on the more cumbersome "if L: for x in L: ..." RFC: are we guaranteed to have members here? can we just use "if members" without adding the new field? Signed-off-by: John Snow --- scripts/qapi/schema.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 164d86c4064..200bc0730d6 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -18,7 +18,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, @@ -447,22 +447,24 @@ 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] =3D [] + self._checking =3D False =20 def check(self, schema): # This calls another type T's .check() exactly when the C # struct emitted by gen_object() contains that T's C struct # (pointers don't count). - if self.members is not None: - # A previous .check() completed: nothing to do - return - if self._checked: + if self._checking: # Recursed: C struct contains itself raise QAPISemError(self.info, "object %s contains itself" % self.name) + if self._checked: + # A previous .check() completed: nothing to do + return =20 + self._checking =3D True super().check(schema) - assert self._checked and self.members is None + assert self._checked and not self.members =20 seen =3D OrderedDict() if self._base_name: @@ -479,13 +481,17 @@ def check(self, schema): for m in self.local_members: m.check(schema) m.check_clash(self.info, seen) - members =3D seen.values() + + # check_clash is abstract, but local_members is asserted to be + # List[QAPISchemaObjectTypeMember]. Cast to the narrower type. + members =3D cast(List[QAPISchemaObjectTypeMember], list(seen.value= s())) =20 if self.variants: self.variants.check(schema, seen) self.variants.check_clash(self.info, seen) =20 - self.members =3D members # mark completed + self.members =3D members + self._checking =3D False # mark completed =20 # Check that the members of this type do not cause duplicate JSON memb= ers, # and update seen to track the members seen so far. Report any errors --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099099; cv=none; d=zohomail.com; s=zohoarc; b=WvY9+kMsvQuzKzTFaWAeBxtfzhApwYLN6PhV+1eL5BAUYcvyCvA+ma6dO2SR99nOHS0d4kXITN1MY/FmQ9ZTtqtilHdRDG2WJxGs7vmUGYpy8Ro9DI+X0av4aaoZJTuepNbQ7Bcx1ts+byRbUEL4+QfLoaRP8D58KUBl7sNUPGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099099; 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=4+md9DVhvTNARGMr4KalPOeP3cyXwJOih9g+YoQcPuA=; b=ehJ79w7bPrOE/B9eJXUF0q8GPtjIHDSor9xJFGnvRyqzehUav2pdtQdEWHJf7lx50wGNeU2RhlGg11v9d6MI4WuL6vjiB9Va+kTJZUyIbLLv4NQzCQc3ea9yEPxv+scGiDnQRyV7qqUY00qsouFkS3eGmDcP2eRoPHt6F/CyEso= 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 17000990997821010.9135835201859; Wed, 15 Nov 2023 17:44:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQh-0005Mr-Vd; Wed, 15 Nov 2023 20:44:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQL-0005Ip-7l for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQG-00021g-Gp for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:04 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-396-IniX0dqbMwCmSqmY5UL6tQ-1; Wed, 15 Nov 2023 20:43:56 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 A7743828B21; Thu, 16 Nov 2023 01:43:55 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66569C15882; Thu, 16 Nov 2023 01:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099039; 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=4+md9DVhvTNARGMr4KalPOeP3cyXwJOih9g+YoQcPuA=; b=B7IbmpvXswulSkhfyO/zGJdh+KZdXXT7/ct9y3BoQye4mL9adtg5Gb9L9aUWbjT3JbEwjM 23AJQFASXzEnTOYIgIm2EIyShK9lJm/9NJKKcZNMzH69oqOEsQL+RIadO/6SoZZk/O8r4v SRMsOmMP0vXNqT4Cwp28F7mUb43QnSw= X-MC-Unique: IniX0dqbMwCmSqmY5UL6tQ-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 13/19] qapi/schema: fix typing for QAPISchemaVariants.tag_member Date: Wed, 15 Nov 2023 20:43:44 -0500 Message-ID: <20231116014350.653792-14-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1700099101339100003 Content-Type: text/plain; charset="utf-8" There are two related changes here: (1) We need to perform type narrowing for resolving the type of tag_member during check(), and (2) tag_member is a delayed initialization field, but we can hide it behind a property that raises an Exception if it's called too early. This simplifies the typing in quite a few places and avoids needing to assert that the "tag_member is not None" at a dozen callsites, which can be confusing and suggest the wrong thing to a drive-by contributor. Signed-off-by: John Snow --- scripts/qapi/schema.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 200bc0730d6..476b19aed61 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.lookup_type(self.tag_member.defined_in) assert base_type if not base_type.is_implicit(): @@ -666,11 +680,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.41.0 From nobody Wed Nov 27 04:35: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=1700099283; cv=none; d=zohomail.com; s=zohoarc; b=aD+te4/Ds7iTEWs4pWvTdDjLDHsMyfWRGnj1xobCkx8VZGDqOUQQlEckSs835xnA+Vegz437bc5Gz+j6vMKHeK3TJvK5mkanx4pQtjeWR0fMGQ0hy2/aKtDiPv5vm3wWjBIzm+QDrjEeCGOHBP6/xG3VwB8LtUbYwqjoKaj6hnc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099283; 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=c1/ixl/HcaQ8BKWHpVLZPVs1V8B+oy2fFnGDNW16PNo=; b=AJtaIlQ+YfxO2+ENycy7QpVPpOpGqzrNPIrdXaunpBdTW3kXZ3pBQl4YT3Pebm4/dUt1DZRgbemMIMY3UeZ//VyYQY6uGHTl/FF8yxFiX+afCQ20PVAUoGAHFOEfeZNVhO1vYmX4wQWBpVlqc7Ws9l+7aFGFeHl8y9+QMgjw0D0= 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 SMTP id 1700099283142277.1050840734571; Wed, 15 Nov 2023 17:48:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQW-0005Lp-De; Wed, 15 Nov 2023 20:44:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQL-0005Io-42 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:05 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQG-00021e-Gh for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:04 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-647-htlJlfQdO7CAnMY7PZVwzA-1; Wed, 15 Nov 2023 20:43:56 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 06B933813F25; Thu, 16 Nov 2023 01:43:56 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id B94DBC15881; Thu, 16 Nov 2023 01:43:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099039; 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=c1/ixl/HcaQ8BKWHpVLZPVs1V8B+oy2fFnGDNW16PNo=; b=jV8kFHtCIVAjxchUaqGmsErJXjiglCVgxZAsRqnXq04rnB1M7OjbEHRmfTNhblQHOdFmxN BoME6mbY4csDXADI0ecobtRDpxsuU6j3Dih68bIpsfkLjtBSfORmkD/TaRZflIm5tCLlp7 eKkr6uoZz6GQ8u/SYGkYaF8DK8fJha0= X-MC-Unique: htlJlfQdO7CAnMY7PZVwzA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 14/19] qapi/schema: assert QAPISchemaVariants are QAPISchemaObjectType Date: Wed, 15 Nov 2023 20:43:45 -0500 Message-ID: <20231116014350.653792-15-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, 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: 1700099283923100001 Content-Type: text/plain; charset="utf-8" I'm actually not too sure about this one, it seems to hold up at runtime but instead of lying and coming up with an elaborate ruse as a commit message I'm just going to admit I just cribbed my own notes from the last time I typed schema.py and I no longer remember why or if this is correct. Cool! With more seriousness, variants are only guaranteed to house a QAPISchemaType as per the definition of QAPISchemaObjectTypeMember but the only classes/types that have a check_clash method are descendents of QAPISchemaMember and the QAPISchemaVariants class itself. Signed-off-by: John Snow --- scripts/qapi/schema.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 476b19aed61..ce5b01b3182 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -717,6 +717,7 @@ 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 + assert isinstance(v.type, QAPISchemaObjectType) # I think, an= yway? v.type.check_clash(info, dict(seen)) =20 =20 --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099171; cv=none; d=zohomail.com; s=zohoarc; b=WPlTK1IXLu+LMuQ33mJB/bKTo2NleoSctaBLqz07vndqJdJb7bzIWpWHWousqHGfYdXrPHobBQu6xMYhRp45M2MBBQnRJpQHTLqo31tTbpj4gnfzwGFmSQDA4D2nLG5TAbdWEsf27SSkaXWpMIiQWGEx4Ag+qQfvMvDuFbQM4Z0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099171; 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=wDMUx5WUimMYInObg2HL2FZ5zCDslAURlR2Qdinz46k=; b=EDSBle8gi5Wx8dl5G98qDY9IRq7DGLjUtfGT/t2vSlYcGSkGu6BdIL5Z/b4M0szBmHG4NV0U8Vsm6urWWM2dvBHKnTSEcOfPuuML9fpTNqzmbkgF6770h/iBe+0CLgdrUnZ9glH0SyYifqMAXO1AbwbY0nBDp+Ti5h78rYvg558= 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 1700099171262535.5490858579205; Wed, 15 Nov 2023 17:46:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQk-0005O3-2R; Wed, 15 Nov 2023 20:44:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQO-0005KR-V6 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQG-00021j-NX for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:08 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-368-BYGxaspXORS11NqDDhb8uA-1; Wed, 15 Nov 2023 20:43:56 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 5C3EB29ABA27; Thu, 16 Nov 2023 01:43:56 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1ABFBC15881; Thu, 16 Nov 2023 01:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099040; 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=wDMUx5WUimMYInObg2HL2FZ5zCDslAURlR2Qdinz46k=; b=KA88bmfi/DiWtxpQgbJ9weiQwkJ1+ptmGt2qAgtvv5bckUqVWuAkj5/btogaizC0yW+jKC YCL9IwZMA36r5xFYKcv7npSP6JtS4+OsVFi7KqwFw+dHbCKprTREimqj0Bj16CPise0sO4 KkJBk1C22LiJxtPPf/m9+RiZDJcxWis= X-MC-Unique: BYGxaspXORS11NqDDhb8uA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 15/19] qapi/parser: demote QAPIExpression to Dict[str, Any] Date: Wed, 15 Nov 2023 20:43:46 -0500 Message-ID: <20231116014350.653792-16-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-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.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1700099171587100008 Dict[str, object] is a stricter type, but with the way that code is currently arranged, it is infeasible to enforce this strictness. In particular, although expr.py's entire raison d'=C3=AAtre is normalization and type-checking of QAPI Expressions, that type information is not "remembered" in any meaningful way by mypy because each individual expression is not downcast to a specific expression type that holds all the details of each expression's unique form. As a result, all of the code in schema.py that deals with actually creating type-safe specialized structures has no guarantee (myopically) that the data it is being passed is correct. There are two ways to solve this: (1) Re-assert that the incoming data is in the shape we expect it to be, or (2) Disable type checking for this data. (1) is appealing to my sense of strictness, but I gotta concede that it is asinine to re-check the shape of a QAPIExpression in schema.py when expr.py has just completed that work at length. The duplication of code and the nightmare thought of needing to update both locations if and when we change the shape of these structures makes me extremely reluctant to go down this route. (2) allows us the chance to miss updating types in the case that types are updated in expr.py, but it *is* an awful lot simpler and, importantly, gets us closer to type checking schema.py *at all*. Something is better than nothing, I'd argue. So, do the simpler dumber thing and worry about future strictness improvements later. Signed-off-by: John Snow --- scripts/qapi/parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index bf31018aef0..b7f08cf36f2 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.41.0 From nobody Wed Nov 27 04:35: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=1700099324; cv=none; d=zohomail.com; s=zohoarc; b=c3OG1VIYHZiV0LP41IQlx7LNYaO5Sn/QPwL5L3u8kxG+noXZPDuBFCm2OPNzBYEOKMFeeqnIjaQlN1HAVuSbrM8wFGvuRTjZqeUTTuggOr1naEhWbZ4JxQZQ2Ofxe8gDwAhd4+b6wjpn2IgbcE65nMOuPXn9aHv096pqdKeUUb0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099324; 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=enrJLUtWlojyWtWCax6eEDvqVwZO3al6bjKNDT/LY3M=; b=np0GFYdOl3UaKf1DS5k/1q6GAx8Kan5H9uFT82/8W7fZeygksHjLQYZYFBwP/MEZRu7eH+7G4GZn5wsU1OU7obqAn7JvM/2UM4eNuVgr5NFuSW4uo0wH2YkFeXZ7+XWsNSATGiHHomUU/cNzfpWFJssU/uPhTNIVWYKgzWHXfuw= 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 1700099324878978.1901512157217; Wed, 15 Nov 2023 17:48:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RR2-0005R7-2B; Wed, 15 Nov 2023 20:44:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQd-0005NJ-4c for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:27 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQQ-00024d-5x for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:22 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-94-6ebj--LxOZq-4dk1hs_XDA-1; Wed, 15 Nov 2023 20:43:57 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 B1FFE3813F24; Thu, 16 Nov 2023 01:43:56 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AB5CC15881; Thu, 16 Nov 2023 01:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099049; 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=enrJLUtWlojyWtWCax6eEDvqVwZO3al6bjKNDT/LY3M=; b=jWB8IrsNH/VfOiLwMKTvjxBhBK4lrs1OPo7CjnjOBMs6ioq35QrrUjnJeWoH7IZyCC1E+d HLHVexvW1t99pIyt5GuQbBRSaMOwDWIi+r4u1n0bYYRBRg4SeTe6n6ovqGjF2LZWUOrTE4 CDsV4apFnXJM76gPscU2qUVan3ZAVY8= X-MC-Unique: 6ebj--LxOZq-4dk1hs_XDA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 16/19] qapi/schema: add type hints Date: Wed, 15 Nov 2023 20:43:47 -0500 Message-ID: <20231116014350.653792-17-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1700099326188100003 Content-Type: text/plain; charset="utf-8" This patch only adds type hints, which aren't utilized at runtime and don't change the behavior of this module in any way. In a scant few locations, type hints are removed where no longer necessary due to inference power from typing all of the rest of creation; and any type hints that no longer need string quotes are changed. Signed-off-by: John Snow --- scripts/qapi/schema.py | 554 +++++++++++++++++++++++++++++------------ 1 file changed, 389 insertions(+), 165 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index ce5b01b3182..5d19b59def0 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -15,10 +15,20 @@ # TODO catching name collisions in generated code would be nice # pylint: disable=3Dtoo-many-lines =20 +from __future__ import annotations + 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, @@ -30,39 +40,50 @@ ) 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 class 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 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 - self._module =3D None + 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 @@ -74,102 +95,162 @@ def __init__(self, name: str, info, doc, ifcond=3DNon= e, features=3DNone): self.features =3D features or [] self._checked =3D False =20 - def __repr__(self): + def __repr__(self) -> str: 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(sel= f)) =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: # pylint: disable=3Dunused-argument assert not self._checked - seen =3D {} + seen: Dict[str, QAPISchemaMember] =3D {} for f in self.features: f.check_clash(self.info, seen) self._checked =3D True =20 - def connect_doc(self, doc=3DNone): + def connect_doc(self, doc: Optional[QAPIDoc] =3D None) -> None: doc =3D doc or self.doc if doc: for f in self.features: doc.connect_feature(f) =20 - def check_doc(self): + def check_doc(self) -> None: if self.doc: self.doc.check() =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 @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 visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: # pylint: disable=3Dunused-argument assert self._checked =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 @@ -177,9 +258,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: @@ -208,10 +289,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): @@ -219,13 +300,13 @@ def visit(self, visitor): =20 =20 class QAPISchemaInclude(QAPISchemaEntity): - def __init__(self, sub_module, info): + def __init__(self, sub_module: QAPISchemaModule, info: QAPISourceInfo): # Includes are internal entity objects; and may occur multiple tim= es name =3D f"q_include_{info.fname}:{info.line}" super().__init__(name, info, None) 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 @@ -237,17 +318,17 @@ def c_type(self) -> str: raise NotImplementedError() =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 def json_type(self) -> str: raise NotImplementedError() =20 - def alternate_qtype(self): + def alternate_qtype(self) -> Optional[str]: json2qtype =3D { 'null': 'QTYPE_QNULL', 'string': 'QTYPE_QSTRING', @@ -259,17 +340,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(): @@ -277,7 +358,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 @@ -285,7 +366,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', @@ -293,24 +374,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 @@ -318,7 +399,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) @@ -327,32 +417,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, @@ -362,7 +452,9 @@ 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 @@ -377,12 +469,12 @@ def element_type(self) -> QAPISchemaType: ) return self._element_type =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) =20 if self.info: @@ -396,42 +488,51 @@ def check(self, schema): ) 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) @@ -450,7 +551,7 @@ def __init__(self, name, info, doc, ifcond, features, self.members: List[QAPISchemaObjectTypeMember] =3D [] self._checking =3D False =20 - def check(self, schema): + def check(self, schema: QAPISchema) -> None: # This calls another type T's .check() exactly when the C # struct emitted by gen_object() contains that T's C struct # (pointers don't count). @@ -496,14 +597,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(): @@ -511,34 +616,34 @@ 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: assert self.members is not None return not self.members and not self.variants =20 - def has_conditional_members(self): + def has_conditional_members(self) -> bool: assert self.members is not None 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)) @@ -713,7 +834,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 @@ -725,18 +850,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( @@ -745,11 +879,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 @@ -781,14 +915,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: @@ -798,12 +938,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) @@ -815,19 +963,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: @@ -837,24 +985,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(QAPISchemaEntity): 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 @@ -862,7 +1028,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: @@ -897,14 +1063,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, @@ -916,14 +1082,23 @@ def visit(self, visitor): class QAPISchemaEvent(QAPISchemaEntity): 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( @@ -945,14 +1120,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, @@ -960,7 +1135,7 @@ def visit(self, visitor): =20 =20 class QAPISchema: - def __init__(self, fname): + def __init__(self, fname: str): self.fname =3D fname =20 try: @@ -972,9 +1147,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, QAPISchemaEntity] =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) @@ -984,7 +1159,7 @@ def __init__(self, fname): self._def_exprs(exprs) self.check() =20 - def _def_entity(self, ent): + def _def_entity(self, ent: QAPISchemaEntity) -> None: # Only the predefined types are allowed to not have info assert ent.info or self._predefining self._entity_list.append(ent) @@ -1003,7 +1178,11 @@ def _def_entity(self, ent): ent.info, "%s is already defined" % other_ent.describe()) self._entity_dict[ent.name] =3D ent =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 @@ -1016,7 +1195,12 @@ def lookup_type(self, name: str) -> Optional[QAPISch= emaType]: assert isinstance(typ, QAPISchemaType) return typ =20 - def resolve_type(self, name, info, what): + def resolve_type( + self, + name: str, + info: Optional[QAPISourceInfo], + what: Union[str, Callable[[Optional[QAPISourceInfo]], str]], + ) -> QAPISchemaType: typ =3D self.lookup_type(name) if not typ: if callable(what): @@ -1030,23 +1214,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_entity(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 @@ -1054,7 +1240,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'), @@ -1083,30 +1269,51 @@ def _def_predefineds(self): self._def_entity(QAPISchemaEnumType('QType', None, None, None, Non= e, 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_entity(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() @@ -1122,7 +1329,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') @@ -1133,7 +1340,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:] @@ -1144,13 +1358,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'] @@ -1162,13 +1380,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'] @@ -1193,7 +1417,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) @@ -1211,7 +1435,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') @@ -1237,7 +1461,7 @@ def _def_command(self, expr: QAPIExpression): boxed, allow_oob, allow_preconf= ig, 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) @@ -1251,7 +1475,7 @@ def _def_event(self, expr: QAPIExpression): self._def_entity(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) @@ -1270,7 +1494,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() @@ -1278,7 +1502,7 @@ def check(self): for ent in self._entity_list: ent.set_module(self) =20 - def visit(self, visitor): + def visit(self, visitor: QAPISchemaVisitor) -> None: visitor.visit_begin(self) for mod in self._module_dict.values(): mod.visit(visitor) --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099117; cv=none; d=zohomail.com; s=zohoarc; b=EHdy2TJLQcTTLa4d3vvNsnTeK63Obeelzhmbb36fJ5G75Ti3GFDCUA2PDTf1wYBMHSlaNbC2XM18TDzlc0VE8cAtbXNPhfrikgugHQcZA4MsVLKuls4sFNYgwTVdejfAyR75GHX/ofC8mEUgjaac0tQ3cwmU4rpI0xaA8yQ/OBM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099117; 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=Z9l+KTbDrQrCxNh54ZdZId0hTUVU4MQfBShpl+9MLrg=; b=WPO1tqq6iWqB0muPhXCrSz/BRN+WvM8l/9j0pChANy+oDZa+vmLRLYXCSwhjI7jmEdZoRpoIZzgQifZuXKkIuYqUhQyIMc5rAetR9D5YELqBJMV/3EZoYsleJjwaDzs+2DRmjzmJ+Gv9zry9cwCP6pYn/e7KYPzLNVwRZmmh8UM= 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 1700099117143499.4001489814043; Wed, 15 Nov 2023 17:45:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQm-0005OO-IE; Wed, 15 Nov 2023 20:44:32 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQL-0005JE-T6 for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQI-00022o-RB for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:05 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-219-YvlO2c8NMzmPIpNNZfl4OA-1; Wed, 15 Nov 2023 20:43:57 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 1308B811E7B; Thu, 16 Nov 2023 01:43:57 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id C4984C15881; Thu, 16 Nov 2023 01:43:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099042; 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=Z9l+KTbDrQrCxNh54ZdZId0hTUVU4MQfBShpl+9MLrg=; b=euKRHXU16V1A6H4MdaK/c94+VpkE1pTu0sgSzUTCYkTWdC0nMj5oKFpwPQyEPolHEjvM9M RXQmPKi0CXGY0/oL00F59pi+hmXnVQLLhE2m46zo35leexKodDmqCQQX8AYDpeg0ZV73xx SFDimc8Jtf9iN3RjtWlWpwyBmtz1N/I= X-MC-Unique: YvlO2c8NMzmPIpNNZfl4OA-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 17/19] qapi/schema: turn on mypy strictness Date: Wed, 15 Nov 2023 20:43:48 -0500 Message-ID: <20231116014350.653792-18-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, 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: 1700099117342100001 Content-Type: text/plain; charset="utf-8" This patch can be rolled in with the previous one once the series is ready for merge, but for work-in-progress' sake, it's separate here. Signed-off-by: John Snow --- scripts/qapi/mypy.ini | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 56e0dfb1327..8109470a031 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -2,8 +2,3 @@ strict =3D True disallow_untyped_calls =3D False python_version =3D 3.8 - -[mypy-qapi.schema] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False --=20 2.41.0 From nobody Wed Nov 27 04:35: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=1700099318; cv=none; d=zohomail.com; s=zohoarc; b=OoMIbBRQwGbURLq0bz6W7S5LBEg9pLFTQb9H52Z0MRLFWPIZJMMISHa7w8Zya0sPOaxRcy0dRAve2oOlSGrDtdKntY0gqfpeJDOVnqaFXGOt/3Fkz6crgOEsYNcWxSvEtmBVwGS1jcVwLaSwqC51YqLVUt7PMoH1rnObCOUHSN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099318; 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=Y6FJzfXk8Xh4RUkNFX52+G4sAFZOc9b8NvO/oKrBAZA=; b=hHuyNpVPmIizdQxjEMFcFasUMB0P5SbV13xBqBN9wdZu5mXtkc5Pibx2yzZ5yRlJWf9sh8tNSE95UanCAq0x4NNymNZBVYnvDRR6IXzmGpyPks1Ua/9iWxdg6I/kUtqgeeUHmcUff8I//xBJqce2KKRzvZrHRdK3j2Nw5Hq24iQ= 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 1700099318177114.27162184396082; Wed, 15 Nov 2023 17:48:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQo-0005Oi-JH; Wed, 15 Nov 2023 20:44:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQO-0005KQ-Ue for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:09 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQI-00022N-3H for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:08 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-107-2KPuCeexMNS0BXGCVs0OyQ-1; Wed, 15 Nov 2023 20:43:57 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 66B143C11CC3; Thu, 16 Nov 2023 01:43:57 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 264B7C15881; Thu, 16 Nov 2023 01:43:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099041; 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=Y6FJzfXk8Xh4RUkNFX52+G4sAFZOc9b8NvO/oKrBAZA=; b=eGnWob7t+ZeurHioi3gXU7LZ1HZNSNR8piIw4i5MQ+0XvMIS/yTPN4/oXpNkimlLGvdCk3 pJ5D2+2ysUid/j0LOx4TvSebqKg7xuZGnuNX9p7RV9hQ7U9+TMQidDpa7kVsNVUTBMjrTr zQVYt5e6CaYXI8i6KC25yD3X1AjV08Y= X-MC-Unique: 2KPuCeexMNS0BXGCVs0OyQ-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 18/19] qapi/schema: remove unnecessary asserts Date: Wed, 15 Nov 2023 20:43:49 -0500 Message-ID: <20231116014350.653792-19-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, 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: 1700099320112100011 Content-Type: text/plain; charset="utf-8" With strict typing enabled, these runtime statements aren't necessary anymore. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/schema.py | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 5d19b59def0..b5f377e68b8 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -78,9 +78,7 @@ def __init__( ifcond: Optional[QAPISchemaIfCond] =3D None, features: Optional[List[QAPISchemaFeature]] =3D None, ): - 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 self._module: Optional[QAPISchemaModule] =3D None @@ -145,7 +143,6 @@ def visit(self, visitor: QAPISchemaVisitor) -> None: assert self._checked =20 def describe(self) -> str: - assert self.meta return "%s '%s'" % (self.meta, self.name) =20 =20 @@ -359,7 +356,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 @@ -368,7 +364,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 @@ -411,9 +406,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 @@ -456,7 +449,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: Optional[QAPISchemaType] =3D None =20 @@ -517,7 +509,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 @@ -537,12 +528,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 @@ -856,7 +841,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() @@ -924,7 +908,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 @@ -953,10 +936,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(). Kind of hokey. @@ -1015,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 @@ -1093,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.41.0 From nobody Wed Nov 27 04:35: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=1700099317; cv=none; d=zohomail.com; s=zohoarc; b=PQ6RLbm1ISo/yWFcIeCzTbM/kzWw+AbzOhT5r5kC7isbFRVvgosJBnUuhI7syC4Pe+JswSg3Y/UvGmSENUuW6dHwLoBQf8Q4G7ciYD9K/UrGAWqC/T/94nGjJtIIvZ9rlK4m7ELMWcWRq0dqxxnATfrpVkkhFrToK2YEJGLc2kI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700099317; 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=M2mScccsI/m2XDWoGf9Kl1sVKUo1rs7PmXyaA/Q5qx4=; b=ledlyIIXcdvSepzWxjD90E/A0BG3JXXOoGdTjya+oDXBANmbyyjm03L6C9qipfRDkil8T08uef7xW2GjmJF4cbPAJmEpp8DaGqkxgmP7o2zD7BRvoCnhHIc2/YUooRqHriDRSFsrVQYYfKfHcvj68hx9ZONPgB7PHIy1ykjLm4Y= 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 1700099317188906.2307202519148; Wed, 15 Nov 2023 17:48:37 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQu-0005Ph-Qc; Wed, 15 Nov 2023 20:44:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQO-0005Jr-HV for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:08 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r3RQK-00023Y-Rr for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:08 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-416-saj6Tb3DNkOMQtibDYCpDQ-1; Wed, 15 Nov 2023 20:43:58 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 BBD57811E7D; Thu, 16 Nov 2023 01:43:57 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id 778EBC15881; Thu, 16 Nov 2023 01:43:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099044; 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=M2mScccsI/m2XDWoGf9Kl1sVKUo1rs7PmXyaA/Q5qx4=; b=AiXWpI+gHJ4f4KMWaAn/Iu2s6GKCV4HKqnth6+c5klDbEUoX99ZccVeBBqbiaEQVKo/Q+X iai71ix6AsAvJBWS4UxjZgVfa8J3pnmxYYo6nmASETvkYweilaehLw5aH/WbIrQIxjWvRU 09519wqeBTNoJjrgKiKaHYAH1Wz7DEM= X-MC-Unique: saj6Tb3DNkOMQtibDYCpDQ-1 From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 19/19] qapi/schema: refactor entity lookup helpers Date: Wed, 15 Nov 2023 20:43:50 -0500 Message-ID: <20231116014350.653792-20-jsnow@redhat.com> In-Reply-To: <20231116014350.653792-1-jsnow@redhat.com> References: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: 1700099318118100007 Content-Type: text/plain; charset="utf-8" This is not a clear win, but I was confused and I couldn't help myself. Before: lookup_entity(self, name: str, typ: Optional[type] =3D None ) -> Optional[QAPISchemaEntity]: ... lookup_type(self, name: str) -> Optional[QAPISchemaType]: ... resolve_type(self, name: str, info: Optional[QAPISourceInfo], what: Union[str, Callable[[Optional[QAPISourceInfo]], str]] ) -> QAPISchemaType: ... After: get_entity(self, name: str) -> Optional[QAPISchemaEntity]: ... get_typed_entity(self, name: str, typ: Type[_EntityType] ) -> Optional[_EntityType]: ... lookup_type(self, name: str) -> QAPISchemaType: ... resolve_type(self, name: str, info: Optional[QAPISourceInfo], what: Union[str, Callable[[Optional[QAPISourceInfo]], str]] ) -> QAPISchemaType: ... In essence, any function that can return a None value becomes "get ..." to encourage association with the dict.get() function which has the same behavior. Any function named "lookup" or "resolve" by contrast is no longer allowed to return a None value. This means that any callers to resolve_type or lookup_type don't have to check that the function worked, they can just assume it did. Callers to resolve_type will be greeted with a QAPISemError if something has gone wrong, as they have in the past. Callers to lookup_type will be greeted with a KeyError if the entity does not exist, or a TypeError if it does, but is the wrong type. get_entity and get_typed_entity remain for any callers who are specifically interested in the negative case. These functions have only a single caller each. Signed-off-by: John Snow --- docs/sphinx/qapidoc.py | 2 +- scripts/qapi/introspect.py | 8 ++---- scripts/qapi/schema.py | 52 ++++++++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 26 deletions(-) diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py index 8f3b9997a15..96deadbf7fc 100644 --- a/docs/sphinx/qapidoc.py +++ b/docs/sphinx/qapidoc.py @@ -508,7 +508,7 @@ def run(self): vis.visit_begin(schema) for doc in schema.docs: if doc.symbol: - vis.symbol(doc, schema.lookup_entity(doc.symbol)) + vis.symbol(doc, schema.get_entity(doc.symbol)) else: vis.freeform(doc) return vis.get_document_nodes() diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 42981bce163..67c7d89aae0 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -227,14 +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': - tmp =3D self._schema.lookup_type('int') - assert tmp is not None - typ =3D tmp + typ =3D self._schema.lookup_type('int') elif (isinstance(typ, QAPISchemaArrayType) and typ.element_type.json_type() =3D=3D 'int'): - tmp =3D self._schema.lookup_type('intList') - assert tmp is not None - typ =3D tmp + typ =3D self._schema.lookup_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 b5f377e68b8..5813136e78b 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -26,6 +26,8 @@ Dict, List, Optional, + Type, + TypeVar, Union, cast, ) @@ -767,7 +769,6 @@ def check( # Here we do: assert self.tag_member.defined_in base_type =3D schema.lookup_type(self.tag_member.defined_in) - assert base_type if not base_type.is_implicit(): base =3D "base type '%s'" % self.tag_member.defined_in if not isinstance(self.tag_member.type, QAPISchemaEnumType): @@ -1111,6 +1112,12 @@ def visit(self, visitor: QAPISchemaVisitor) -> None: self.arg_type, self.boxed) =20 =20 +# Used for type-dependent type lookup return values. +_EntityType =3D TypeVar( # pylint: disable=3Dinvalid-name + '_EntityType', bound=3DQAPISchemaEntity +) + + class QAPISchema: def __init__(self, fname: str): self.fname =3D fname @@ -1155,22 +1162,28 @@ def _def_entity(self, ent: QAPISchemaEntity) -> Non= e: ent.info, "%s is already defined" % other_ent.describe()) self._entity_dict[ent.name] =3D ent =20 - def lookup_entity( + def get_entity(self, name: str) -> Optional[QAPISchemaEntity]: + return self._entity_dict.get(name) + + def get_typed_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 + typ: Type[_EntityType] + ) -> Optional[_EntityType]: + ent =3D self.get_entity(name) + if ent is not None and not isinstance(ent, typ): + etype =3D type(ent).__name__ + ttype =3D typ.__name__ + raise TypeError( + f"Entity '{name}' is of type '{etype}', not '{ttype}'." + ) return ent =20 - def lookup_type(self, name: str) -> Optional[QAPISchemaType]: - typ =3D self.lookup_entity(name, QAPISchemaType) - if typ is None: - return None - assert isinstance(typ, QAPISchemaType) - return typ + def lookup_type(self, name: str) -> QAPISchemaType: + ent =3D self.get_typed_entity(name, QAPISchemaType) + if ent is None: + raise KeyError(f"Entity '{name}' is not defined.") + return ent =20 def resolve_type( self, @@ -1178,13 +1191,14 @@ def resolve_type( info: Optional[QAPISourceInfo], what: Union[str, Callable[[Optional[QAPISourceInfo]], str]], ) -> QAPISchemaType: - typ =3D self.lookup_type(name) - if not typ: + try: + return self.lookup_type(name) + except (KeyError, TypeError) as err: if callable(what): what =3D what(info) raise QAPISemError( - info, "%s uses unknown type '%s'" % (what, name)) - return typ + info, "%s uses unknown type '%s'" % (what, name) + ) from err =20 def _module_name(self, fname: str) -> str: if QAPISchemaModule.is_system_module(fname): @@ -1279,7 +1293,7 @@ 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): + if not self.get_entity(name): self._def_entity(QAPISchemaArrayType(name, info, element_type)) return name =20 @@ -1295,7 +1309,7 @@ def _make_implicit_object_type( return None # See also QAPISchemaObjectTypeMember.describe() name =3D 'q_obj_%s-%s' % (name, role) - typ =3D self.lookup_entity(name, QAPISchemaObjectType) + typ =3D self.get_typed_entity(name, QAPISchemaObjectType) if typ: # The implicit object type has multiple users. This can # only be a duplicate definition, which will be flagged --=20 2.41.0