From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260829; cv=none; d=zohomail.com; s=zohoarc; b=ZxGdZZvthcB2iXDVS83NFS8iOQczNMgSXBTxvoxW1XOYbVYvXNuDaLCaD0ZKbaIZO9tjme/o1tIz6Btg6/VrBoQfQTL12SFdwYfIZMAH1JORfApfLM2dCHZV2Tm3sngPfEf+q0aXxKSnfB6ozIsorUmp8OntGADyzEKdiwBP2SI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260829; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uK8aJWmONLmLz8GThMNVOIyusxyJ7b5QrlusdD7Nbd4=; b=BXl+9xaa0Opm+yBySA6CeOc7KFnuoS2smVr546jmZzWGa/HVnsCmbv1biQqsit/3MlyYCvHMpSlAjRGzbhdnSXtQj7DLD/X2O7HG5RK2ZEa8RloLUeRMUB5at4mvg6555Ahi/18+/vzN/FZ30YtAP6kDBpFi+fMAD09UmfESdfA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260829135850.4764238638672; Fri, 9 Oct 2020 09:27:09 -0700 (PDT) Received: from localhost ([::1]:33370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvEZ-0000Zx-RO for importer@patchew.org; Fri, 09 Oct 2020 12:27:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv41-0003mP-DF for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22654) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv3w-0003Dp-7P for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-482-2b62jCfWPkeU6n3NXc6Oyg-1; Fri, 09 Oct 2020 12:16:01 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 861131084D69; Fri, 9 Oct 2020 16:16:00 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id C648338A; Fri, 9 Oct 2020 16:15:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260164; 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=uK8aJWmONLmLz8GThMNVOIyusxyJ7b5QrlusdD7Nbd4=; b=b46dGkRpgWIVi9LXAY+a3uSyaTqk1Gdpq7YDth0VPQkOqd2sBKho3opVtDYkUNCLCx/n/u Esp3CJubMAiTnIVi1tL6s3SCY3/qhZzhjf2OBmmKAmg9D2kecjZTrSmVJ6LwJ3CwG1pW7n Ih5pfnom7gLkQA7BjRrIHyG5Neurwuo= X-MC-Unique: 2b62jCfWPkeU6n3NXc6Oyg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 01/36] docs: repair broken references Date: Fri, 9 Oct 2020 12:15:23 -0400 Message-Id: <20201009161558.107041-2-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In two different places, we are not making a cross-reference to some resource correctly. Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- docs/devel/multi-thread-tcg.rst | 2 +- docs/devel/testing.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/devel/multi-thread-tcg.rst b/docs/devel/multi-thread-tcg.= rst index 21483870dbc..92a9eba13c9 100644 --- a/docs/devel/multi-thread-tcg.rst +++ b/docs/devel/multi-thread-tcg.rst @@ -267,7 +267,7 @@ of view of external observers (e.g. another processor c= ore). They can apply to any memory operations as well as just loads or stores. =20 The Linux kernel has an excellent `write-up -` +`_ on the various forms of memory barrier and the guarantees they can provide. =20 diff --git a/docs/devel/testing.rst b/docs/devel/testing.rst index bd64c1bdcdd..8875a40a2b6 100644 --- a/docs/devel/testing.rst +++ b/docs/devel/testing.rst @@ -953,7 +953,7 @@ compiler flags are needed to build for a given target. If you have the ability to run containers as the user you can also take advantage of the build systems "Docker" support. It will then use containers to build any test case for an enabled guest where there is -no system compiler available. See :ref: `_docker-ref` for details. +no system compiler available. See :ref:`docker-ref` for details. =20 Running subset of tests ----------------------- --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260984; cv=none; d=zohomail.com; s=zohoarc; b=Nw9v1dq7TRG531RuM3PdIpPJMf2IHF+GV50pzbrVMJfixmBTQLpR/TQ2KphUlBGOHtc5P7Fi0tAVfIIAtdUA2EGBkjhDp9h46MEk4+ervFxQpp0qMcrWPSbT5jo7qE8mEjhUDX1Lj9+Th50tENzsjd6gha3mCgyVa+WWDBaCP9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260984; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ksAvwBgTkP36TK2l/cDDZbXxzNHg6nzwET102AvLoQY=; b=VXXWnIoyX4LfPbNONpXpCgq0SIiJfTOp0YGypA+Vsji+S5GEmGh7nOzoNbeXO/m5Uw9SZEHe935DB8qnSfqYZsI0Y4q4gjEojoLFSyE2VJe4JKlWWW7Ymf2V6vpS26zgpGya5D2BtsUaN/3vABEm4e3lMfu3x4HK+E/P9ZXd3LY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260984033294.5286135007168; Fri, 9 Oct 2020 09:29:44 -0700 (PDT) Received: from localhost ([::1]:41600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvH4-00045V-Lz for importer@patchew.org; Fri, 09 Oct 2020 12:29:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv42-0003o0-FP for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23757) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv40-0003EM-Jp for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:14 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-JGXXNCjUP3--7hoXXaxryQ-1; Fri, 09 Oct 2020 12:16:05 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D49381019627; Fri, 9 Oct 2020 16:16:04 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id B249638A; Fri, 9 Oct 2020 16:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260168; 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=ksAvwBgTkP36TK2l/cDDZbXxzNHg6nzwET102AvLoQY=; b=akcaVvdqWOWOYqKgEKZ9z5MuC+6v5sf2ux1oJ6/ljaPzCjhhtkNK3yuPh0ZI3RLQ9hwlfE RCSB26zwUFCHtc3+UN8/0Tdt/iHG0Ho71hDyuNSiVoq7CrXhwXTvwucwKXrf0gflQ7nONO klv6g/4hgZbJf1PzBk2QOFTlHxsUWJs= X-MC-Unique: JGXXNCjUP3--7hoXXaxryQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 02/36] qapi: modify docstrings to be sphinx-compatible Date: Fri, 9 Oct 2020 12:15:24 -0400 Message-Id: <20201009161558.107041-3-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" A precise style guide and a package-wide overhaul is forthcoming pending further discussion and consensus. For now, merely avoid obvious errors that cause Sphinx documentation build problems, using a style loosely based on PEP 257 and Sphinx Autodoc. It is chosen for interoperability with our existing Sphinx framework, and because it has loose recognition in the Pycharm IDE. See also: https://www.python.org/dev/peps/pep-0257/ https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#in= fo-field-lists Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index ca66c82b5b8..dc7b94aa115 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -154,9 +154,11 @@ def _bottom(self): =20 @contextmanager def ifcontext(ifcond, *args): - """A 'with' statement context manager to wrap with start_if()/end_if() + """ + A with-statement context manager that wraps with `start_if()` / `end_i= f()`. =20 - *args: any number of QAPIGenCCode + :param ifcond: A list of conditionals, passed to `start_if()`. + :param args: any number of `QAPIGenCCode`. =20 Example:: =20 --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260704; cv=none; d=zohomail.com; s=zohoarc; b=E2nMKDXsM2BcmT4SxdTMB7ajXfPs4UlaK4S1F3GKhj+HKyLUsc5qqz2un9KtDpindRExWmHYsuE1qLRX/yP9CHRXPBHtX6HE23DWDYYb4asVPq1cjl+Xi/5zGhLMkreIbf/gp/f3eUK3kHJxhSTLULc2Xka1KX9366dpGHReUqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260704; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0Jfb+bdIMSiZN7tkd6saMYGS35LZrC9sw8FjbzbOQqk=; b=mG+S3ubvXzfxMHOOAkjUvExsdAyaOHv4joDAYDYfMA7fHeunikIe2bnZd3JqPwoIdMJFukN8VjRz+tutBB4aBwCysGMm3q6T3FKJBI2xhzFyRQqBUEIslOFyQFsl9m12HHnsL747n/Bm+Lb7VEqYzp4ForaVvg0WyGqCR0LhtWg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260704428387.45595974880916; Fri, 9 Oct 2020 09:25:04 -0700 (PDT) Received: from localhost ([::1]:53226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvCU-0005W7-2K for importer@patchew.org; Fri, 09 Oct 2020 12:24:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv42-0003oe-QO for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:53236) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv40-0003Ea-NL for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:14 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-34-BwuiF7BIMSGl0urV_tWoOA-1; Fri, 09 Oct 2020 12:16:06 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C11431084D71; Fri, 9 Oct 2020 16:16:05 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 08FF81A925; Fri, 9 Oct 2020 16:16:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260168; 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=0Jfb+bdIMSiZN7tkd6saMYGS35LZrC9sw8FjbzbOQqk=; b=Mkh/mn8Uv3w29gfhvPB2n8Wtkq0VEjjc6lfjlLpZbHdjomaLzs0WDj1kz0FCb84lGjJejv RzZYrlpT+svJSEUJjMXjeGF8ZFhFZCix2RQ3BXP7MIec7aB2F4zg6+1mkMxjBiAsk888p9 7fWpDIHy8a3+vsM2vUC7EN3ARdo3fn8= X-MC-Unique: BwuiF7BIMSGl0urV_tWoOA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 03/36] qapi-gen: Separate arg-parsing from generation Date: Fri, 9 Oct 2020 12:15:25 -0400 Message-Id: <20201009161558.107041-4-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is a minor re-work of the entrypoint script. It isolates a generate() method from the actual command-line mechanism. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi-gen.py | 89 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 22 deletions(-) diff --git a/scripts/qapi-gen.py b/scripts/qapi-gen.py index 541e8c1f55d..054554ed846 100644 --- a/scripts/qapi-gen.py +++ b/scripts/qapi-gen.py @@ -1,30 +1,77 @@ #!/usr/bin/env python3 -# QAPI generator -# + # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. =20 +""" +QAPI Generator + +This is the main entry point for generating C code from the QAPI schema. +""" =20 import argparse import re import sys +from typing import Optional =20 from qapi.commands import gen_commands +from qapi.error import QAPIError from qapi.events import gen_events from qapi.introspect import gen_introspect -from qapi.schema import QAPIError, QAPISchema +from qapi.schema import QAPISchema from qapi.types import gen_types from qapi.visit import gen_visit =20 =20 -def main(argv): +def invalid_char(prefix: str) -> Optional[str]: + match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', prefix) + if match.end() !=3D len(prefix): + return prefix[match.end()] + return None + + +def generate(schema_file: str, + output_dir: str, + prefix: str, + unmask: bool =3D False, + builtins: bool =3D False) -> None: + """ + Generate C code for the given schema into the target directory. + + :param schema_file: The primary QAPI schema file. + :param output_dir: The output directory to store generated code. + :param prefix: Optional C-code prefix for symbol names. + :param unmask: Expose non-ABI names through introspection? + :param builtins: Generate code for built-in types? + + :raise QAPIError: On failures. + """ + assert invalid_char(prefix) is None + + schema =3D QAPISchema(schema_file) + gen_types(schema, output_dir, prefix, builtins) + gen_visit(schema, output_dir, prefix, builtins) + gen_commands(schema, output_dir, prefix) + gen_events(schema, output_dir, prefix) + gen_introspect(schema, output_dir, prefix, unmask) + + +def main() -> int: + """ + gapi-gen executable entry point. + Expects arguments via sys.argv, see --help for details. + + :return: int, 0 on success, 1 on failure. + """ parser =3D argparse.ArgumentParser( description=3D'Generate code from a QAPI schema') parser.add_argument('-b', '--builtins', action=3D'store_true', help=3D"generate code for built-in types") - parser.add_argument('-o', '--output-dir', action=3D'store', default=3D= '', + parser.add_argument('-o', '--output-dir', action=3D'store', + default=3D'', help=3D"write output to directory OUTPUT_DIR") - parser.add_argument('-p', '--prefix', action=3D'store', default=3D'', + parser.add_argument('-p', '--prefix', action=3D'store', + default=3D'', help=3D"prefix for symbols") parser.add_argument('-u', '--unmask-non-abi-names', action=3D'store_tr= ue', dest=3D'unmask', @@ -32,25 +79,23 @@ def main(argv): parser.add_argument('schema', action=3D'store') args =3D parser.parse_args() =20 - match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', args.prefix) - if match.end() !=3D len(args.prefix): - print("%s: 'funny character '%s' in argument of --prefix" - % (sys.argv[0], args.prefix[match.end()]), - file=3Dsys.stderr) - sys.exit(1) + funny_char =3D invalid_char(args.prefix) + if funny_char: + msg =3D f"funny character '{funny_char}' in argument of --prefix" + print(f"{sys.argv[0]}: {msg}", file=3Dsys.stderr) + return 1 =20 try: - schema =3D QAPISchema(args.schema) + generate(args.schema, + output_dir=3Dargs.output_dir, + prefix=3Dargs.prefix, + unmask=3Dargs.unmask, + builtins=3Dargs.builtins) except QAPIError as err: - print(err, file=3Dsys.stderr) - exit(1) - - gen_types(schema, args.output_dir, args.prefix, args.builtins) - gen_visit(schema, args.output_dir, args.prefix, args.builtins) - gen_commands(schema, args.output_dir, args.prefix) - gen_events(schema, args.output_dir, args.prefix) - gen_introspect(schema, args.output_dir, args.prefix, args.unmask) + print(f"{sys.argv[0]}: {str(err)}", file=3Dsys.stderr) + return 1 + return 0 =20 =20 if __name__ =3D=3D '__main__': - main(sys.argv) + sys.exit(main()) --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261252; cv=none; d=zohomail.com; s=zohoarc; b=eNw9V33i2TMkPFwUvNwVHsOrNySKDI7dsycIroewdMVBRAcHLzr6Yw4IVKDKvFBG13+V4ZovOcGATVE085PUOriZIof65QIwtQTEh33R58ComWGGDr9aCX1QLmZqj4kLPOIeee7dLy4gkltUuXasdLNa1rN11zgqR4xjbw86jT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261252; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SPfnjfrOlLsUE7jHCe08cK+cSvcFh3jpGCbJzLC8hew=; b=DxPXD7Fs05T7RK8hq+ywRTT20xkV7J3VKuYAEpflDDBjXNnY3JLpuBxbJoaRLwxFu4PCCqfGSKsH25Pl1y1fNrUxn6EV2qzigf31n3Qalz+nKDIShBM48PtDE9/fp7/yQYzhDE8Suhn8eVR7zaduw+6w3vX+RIuJv3GJosh8644= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261252551638.8278624408505; Fri, 9 Oct 2020 09:34:12 -0700 (PDT) Received: from localhost ([::1]:58624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvLP-0002t0-70 for importer@patchew.org; Fri, 09 Oct 2020 12:34:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv45-0003su-3v for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:54470) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv40-0003Ew-Ng for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-Tc3txzENOqCkchfqRh-LpA-1; Fri, 09 Oct 2020 12:16:07 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C26B680401F; Fri, 9 Oct 2020 16:16:06 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4FC01A925; Fri, 9 Oct 2020 16:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260171; 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=SPfnjfrOlLsUE7jHCe08cK+cSvcFh3jpGCbJzLC8hew=; b=MD70R9xZshGsm+k5sSiKGF/f2a6xTJMD12rCFigiwc9YJYYrTXl/P8mYnyk/IPV66w7UgO vcgE8tGMl+VfENSy5WzAkAaBGVpkt7jGPNc1h5kgpBXaXaFnC4+o1+FXzfiIzR9ZE1ZV8l tPM1tlOg/Fis4cDx/nfwQOZVeAyGlIQ= X-MC-Unique: Tc3txzENOqCkchfqRh-LpA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 04/36] qapi: move generator entrypoint into package Date: Fri, 9 Oct 2020 12:15:26 -0400 Message-Id: <20201009161558.107041-5-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As part of delinting and adding type hints to the QAPI generator, it's helpful for the entrypoint to be part of the package, only leaving a very tiny entrypoint shim outside of the package. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi-gen.py | 94 +++---------------------------------------- scripts/qapi/main.py | 95 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 88 deletions(-) create mode 100644 scripts/qapi/main.py diff --git a/scripts/qapi-gen.py b/scripts/qapi-gen.py index 054554ed846..f3518d29a54 100644 --- a/scripts/qapi-gen.py +++ b/scripts/qapi-gen.py @@ -4,98 +4,16 @@ # See the COPYING file in the top-level directory. =20 """ -QAPI Generator +QAPI code generation execution shim. =20 -This is the main entry point for generating C code from the QAPI schema. +This standalone script exists primarily to facilitate the running of the Q= API +code generator without needing to install the python module to the current +execution environment. """ =20 -import argparse -import re import sys -from typing import Optional - -from qapi.commands import gen_commands -from qapi.error import QAPIError -from qapi.events import gen_events -from qapi.introspect import gen_introspect -from qapi.schema import QAPISchema -from qapi.types import gen_types -from qapi.visit import gen_visit - - -def invalid_char(prefix: str) -> Optional[str]: - match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', prefix) - if match.end() !=3D len(prefix): - return prefix[match.end()] - return None - - -def generate(schema_file: str, - output_dir: str, - prefix: str, - unmask: bool =3D False, - builtins: bool =3D False) -> None: - """ - Generate C code for the given schema into the target directory. - - :param schema_file: The primary QAPI schema file. - :param output_dir: The output directory to store generated code. - :param prefix: Optional C-code prefix for symbol names. - :param unmask: Expose non-ABI names through introspection? - :param builtins: Generate code for built-in types? - - :raise QAPIError: On failures. - """ - assert invalid_char(prefix) is None - - schema =3D QAPISchema(schema_file) - gen_types(schema, output_dir, prefix, builtins) - gen_visit(schema, output_dir, prefix, builtins) - gen_commands(schema, output_dir, prefix) - gen_events(schema, output_dir, prefix) - gen_introspect(schema, output_dir, prefix, unmask) - - -def main() -> int: - """ - gapi-gen executable entry point. - Expects arguments via sys.argv, see --help for details. - - :return: int, 0 on success, 1 on failure. - """ - parser =3D argparse.ArgumentParser( - description=3D'Generate code from a QAPI schema') - parser.add_argument('-b', '--builtins', action=3D'store_true', - help=3D"generate code for built-in types") - parser.add_argument('-o', '--output-dir', action=3D'store', - default=3D'', - help=3D"write output to directory OUTPUT_DIR") - parser.add_argument('-p', '--prefix', action=3D'store', - default=3D'', - help=3D"prefix for symbols") - parser.add_argument('-u', '--unmask-non-abi-names', action=3D'store_tr= ue', - dest=3D'unmask', - help=3D"expose non-ABI names in introspection") - parser.add_argument('schema', action=3D'store') - args =3D parser.parse_args() - - funny_char =3D invalid_char(args.prefix) - if funny_char: - msg =3D f"funny character '{funny_char}' in argument of --prefix" - print(f"{sys.argv[0]}: {msg}", file=3Dsys.stderr) - return 1 - - try: - generate(args.schema, - output_dir=3Dargs.output_dir, - prefix=3Dargs.prefix, - unmask=3Dargs.unmask, - builtins=3Dargs.builtins) - except QAPIError as err: - print(f"{sys.argv[0]}: {str(err)}", file=3Dsys.stderr) - return 1 - return 0 =20 +from qapi import main =20 if __name__ =3D=3D '__main__': - sys.exit(main()) + sys.exit(main.main()) diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py new file mode 100644 index 00000000000..f3003065d8e --- /dev/null +++ b/scripts/qapi/main.py @@ -0,0 +1,95 @@ +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory. + +""" +QAPI Generator + +This is the main entry point for generating C code from the QAPI schema. +""" + +import argparse +import re +import sys +from typing import Optional + +from qapi.commands import gen_commands +from qapi.error import QAPIError +from qapi.events import gen_events +from qapi.introspect import gen_introspect +from qapi.schema import QAPISchema +from qapi.types import gen_types +from qapi.visit import gen_visit + + +def invalid_char(prefix: str) -> Optional[str]: + match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', prefix) + if match.end() !=3D len(prefix): + return prefix[match.end()] + return None + + +def generate(schema_file: str, + output_dir: str, + prefix: str, + unmask: bool =3D False, + builtins: bool =3D False) -> None: + """ + Generate C code for the given schema into the target directory. + + :param schema_file: The primary QAPI schema file. + :param output_dir: The output directory to store generated code. + :param prefix: Optional C-code prefix for symbol names. + :param unmask: Expose non-ABI names through introspection? + :param builtins: Generate code for built-in types? + + :raise QAPIError: On failures. + """ + assert invalid_char(prefix) is None + + schema =3D QAPISchema(schema_file) + gen_types(schema, output_dir, prefix, builtins) + gen_visit(schema, output_dir, prefix, builtins) + gen_commands(schema, output_dir, prefix) + gen_events(schema, output_dir, prefix) + gen_introspect(schema, output_dir, prefix, unmask) + + +def main() -> int: + """ + gapi-gen executable entry point. + Expects arguments via sys.argv, see --help for details. + + :return: int, 0 on success, 1 on failure. + """ + parser =3D argparse.ArgumentParser( + description=3D'Generate code from a QAPI schema') + parser.add_argument('-b', '--builtins', action=3D'store_true', + help=3D"generate code for built-in types") + parser.add_argument('-o', '--output-dir', action=3D'store', + default=3D'', + help=3D"write output to directory OUTPUT_DIR") + parser.add_argument('-p', '--prefix', action=3D'store', + default=3D'', + help=3D"prefix for symbols") + parser.add_argument('-u', '--unmask-non-abi-names', action=3D'store_tr= ue', + dest=3D'unmask', + help=3D"expose non-ABI names in introspection") + parser.add_argument('schema', action=3D'store') + args =3D parser.parse_args() + + funny_char =3D invalid_char(args.prefix) + if funny_char: + msg =3D f"funny character '{funny_char}' in argument of --prefix" + print(f"{sys.argv[0]}: {msg}", file=3Dsys.stderr) + return 1 + + try: + generate(args.schema, + output_dir=3Dargs.output_dir, + prefix=3Dargs.prefix, + unmask=3Dargs.unmask, + builtins=3Dargs.builtins) + except QAPIError as err: + print(f"{sys.argv[0]}: {str(err)}", file=3Dsys.stderr) + return 1 + return 0 --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260727; cv=none; d=zohomail.com; s=zohoarc; b=Yb4x78U0yHJX2+XA4DxNyN2xmyPvFAmopxHr7g6fL6/hk8SnB2Aqdb2th7vxFo2uJ0I3fTOM8vuaQ4QiNwqLMSOGNnWpHdwyLUNCA1QJdVJT71Njr92CHLu9jnyNI/Yoql3lmidcd8diu797aSEH0yhZfCCkvM7nRs+w8Dt43ls= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260727; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QbQLgQHv+rh8sneq0+VYBnxbAEhkFvL5iw+8YyxByd8=; b=AMGqU94VQP7yj7WB7QgM6hwWm85yNfAD9naF1qZbQTM2MF47RKfy1iXFRpkuXKSx0ggdXtYfHN0yx7pSPgiGz+bHhfwyf+AJxwgN1r5/bY4pz0Tr4Mkc2jX73/5q4pYVBPER+RLYn5F/cu39ukTSbnmhYvS4eggAUJO0Kba4n2A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260726762831.7101230911578; Fri, 9 Oct 2020 09:25:26 -0700 (PDT) Received: from localhost ([::1]:54762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvCv-00068O-DD for importer@patchew.org; Fri, 09 Oct 2020 12:25:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv44-0003r7-3j for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:59730) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv40-0003Eo-Mi for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:15 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-304-BBVsGl6KPZSHj_F0cUvDPg-1; Fri, 09 Oct 2020 12:16:08 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE9FC101962F; Fri, 9 Oct 2020 16:16:07 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7DDC1A8EC; Fri, 9 Oct 2020 16:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260170; 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=QbQLgQHv+rh8sneq0+VYBnxbAEhkFvL5iw+8YyxByd8=; b=N/vxdG2g5dhbN/yiGFaqZ4XvPRAa8n7eMITc5hNutAeMcSPW6i2PY+aAMEuleEHjHWiz6A DQz+NgLTb+eVxG24/udtZZ0FFJBgp4tZgcfzvRi5aEqZhWd8gnApUsygfPF0LgJcmmuJ62 UAdS6dpSS/Z4WYuDIQxcb83c6AAAQTc= X-MC-Unique: BBVsGl6KPZSHj_F0cUvDPg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 05/36] qapi: Prefer explicit relative imports Date: Fri, 9 Oct 2020 12:15:27 -0400 Message-Id: <20201009161558.107041-6-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , John Snow , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) All of the QAPI include statements are changed to be package-aware, as explicit relative imports. A quirk of Python packages is that the name of the package exists only *outside* of the package. This means that to a module inside of the qapi folder, there is inherently no such thing as the "qapi" package. The reason these imports work is because the "qapi" package exists in the context of the caller -- the execution shim, where sys.path includes a directory that has a 'qapi' folder in it. When we write "from qapi import sibling", we are NOT referencing the folder 'qapi', but rather "any package named qapi in sys.path". If you should so happen to have a 'qapi' package in your path, it will use *that* package. When we write "from .sibling import foo", we always reference explicitly our sibling module; guaranteeing consistency in *where* we are importing these modules from. This can be useful when working with virtual environments and packages in development mode. In development mode, a package is installed as a series of symlinks that forwards to your same source files. The problem arises because code quality checkers will follow "import qapi.x" to the "installed" version instead of the sibling file and -- even though they are the same file -- they have different module paths, and this causes cyclic import problems, false positive type mismatch errors, and more. It can also be useful when dealing with hierarchical packages, e.g. if we allow qemu.core.qmp, qemu.qapi.parser, etc. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 4 ++-- scripts/qapi/events.py | 8 ++++---- scripts/qapi/expr.py | 4 ++-- scripts/qapi/gen.py | 4 ++-- scripts/qapi/introspect.py | 8 ++++---- scripts/qapi/main.py | 14 +++++++------- scripts/qapi/parser.py | 4 ++-- scripts/qapi/schema.py | 8 ++++---- scripts/qapi/types.py | 6 +++--- scripts/qapi/visit.py | 6 +++--- 10 files changed, 33 insertions(+), 33 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 6e6fc94a14b..1f43a0a34ef 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -13,8 +13,8 @@ See the COPYING file in the top-level directory. """ =20 -from qapi.common import * -from qapi.gen import QAPIGenCCode, QAPISchemaModularCVisitor, ifcontext +from .common import * +from .gen import QAPIGenCCode, QAPISchemaModularCVisitor, ifcontext =20 =20 def gen_command_decl(name, arg_type, boxed, ret_type): diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index b544af5a1ce..04672724388 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,10 +12,10 @@ See the COPYING file in the top-level directory. """ =20 -from qapi.common import * -from qapi.gen import QAPISchemaModularCVisitor, ifcontext -from qapi.schema import QAPISchemaEnumMember -from qapi.types import gen_enum, gen_enum_lookup +from .common import * +from .gen import QAPISchemaModularCVisitor, ifcontext +from .schema import QAPISchemaEnumMember +from .types import gen_enum, gen_enum_lookup =20 =20 def build_event_send_proto(name, arg_type, boxed): diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index a15c1fb4742..bb4dc55f56f 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -16,8 +16,8 @@ =20 import re from collections import OrderedDict -from qapi.common import c_name -from qapi.error import QAPISemError +from .common import c_name +from .error import QAPISemError =20 =20 # Names must be letters, numbers, -, and _. They must start with letter, diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index dc7b94aa115..fc57fdca5b9 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -17,8 +17,8 @@ import re from contextlib import contextmanager =20 -from qapi.common import * -from qapi.schema import QAPISchemaVisitor +from .common import * +from .schema import QAPISchemaVisitor =20 =20 class QAPIGen: diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 5907b09cd57..6c82d9d95f5 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,10 +10,10 @@ See the COPYING file in the top-level directory. """ =20 -from qapi.common import * -from qapi.gen import QAPISchemaMonolithicCVisitor -from qapi.schema import (QAPISchemaArrayType, QAPISchemaBuiltinType, - QAPISchemaType) +from .common import * +from .gen import QAPISchemaMonolithicCVisitor +from .schema import (QAPISchemaArrayType, QAPISchemaBuiltinType, + QAPISchemaType) =20 =20 def _make_tree(obj, ifcond, features, extra=3DNone): diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index f3003065d8e..25190ac0331 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -12,13 +12,13 @@ import sys from typing import Optional =20 -from qapi.commands import gen_commands -from qapi.error import QAPIError -from qapi.events import gen_events -from qapi.introspect import gen_introspect -from qapi.schema import QAPISchema -from qapi.types import gen_types -from qapi.visit import gen_visit +from .commands import gen_commands +from .error import QAPIError +from .events import gen_events +from .introspect import gen_introspect +from .schema import QAPISchema +from .types import gen_types +from .visit import gen_visit =20 =20 def invalid_char(prefix: str) -> Optional[str]: diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 9d1a3e2eea9..7298f5dbd14 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -18,8 +18,8 @@ import re from collections import OrderedDict =20 -from qapi.error import QAPIParseError, QAPISemError -from qapi.source import QAPISourceInfo +from .error import QAPIParseError, QAPISemError +from .source import QAPISourceInfo =20 =20 class QAPISchemaParser: diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index d1307ec661c..676185d1a71 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -18,10 +18,10 @@ import re from collections import OrderedDict =20 -from qapi.common import c_name, pointer_suffix -from qapi.error import QAPIError, QAPISemError -from qapi.expr import check_exprs -from qapi.parser import QAPISchemaParser +from .common import c_name, pointer_suffix +from .error import QAPIError, QAPISemError +from .expr import check_exprs +from .parser import QAPISchemaParser =20 =20 class QAPISchemaEntity: diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 3640f17cd67..ca9a5aacb39 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -13,9 +13,9 @@ # See the COPYING file in the top-level directory. """ =20 -from qapi.common import * -from qapi.gen import QAPISchemaModularCVisitor, ifcontext -from qapi.schema import QAPISchemaEnumMember, QAPISchemaObjectType +from .common import * +from .gen import QAPISchemaModularCVisitor, ifcontext +from .schema import QAPISchemaEnumMember, QAPISchemaObjectType =20 =20 # variants must be emitted before their container; track what has already diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index cdabc5fa283..7850f6e8480 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -13,9 +13,9 @@ See the COPYING file in the top-level directory. """ =20 -from qapi.common import * -from qapi.gen import QAPISchemaModularCVisitor, ifcontext -from qapi.schema import QAPISchemaObjectType +from .common import * +from .gen import QAPISchemaModularCVisitor, ifcontext +from .schema import QAPISchemaObjectType =20 =20 def gen_visit_decl(name, scalar=3DFalse): --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260329; cv=none; d=zohomail.com; s=zohoarc; b=kNhtpBjW8393EI8SRHjKTpy/DaJ/oYlqK2E2J+PLJUyqFy6OgQdm05+x9ZRdjky8ohmHJ21Aa5ilhN03TaNO0ucuEso4aS5D19piNJsTLYo4mQRnVxF5LMzWh8ap9plnSFKTj4a41zchOpxTiwZlX+Yi9LfdLK4S1/gLYUbimOo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260329; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XgT1fGOUL4jL/DLtb47u7sZvwkz25A0LYeYu8H3PXls=; b=bliPs0durFhzVIWJ/vcGXdpyFAWbmx1yPTFD6HeQl8uapPccogxLHXCAGgMlxAPNP6uDni1GxuV8/M5rfL6F0jjbnQ7hTVOzvm+q0an3HqqnCrYQvh6C7JCQesSnPWAdchxU+Rg5dIqHvZGzJ5cXCTCotF7nsNtNPRpJdXPMCbY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260329331838.2758086142272; Fri, 9 Oct 2020 09:18:49 -0700 (PDT) Received: from localhost ([::1]:33850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQv6V-0005qo-Rw for importer@patchew.org; Fri, 09 Oct 2020 12:18:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv46-0003vX-Ak for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv42-0003FH-Cg for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-pD6x0s0UNoKmO7ZhM0VZFA-1; Fri, 09 Oct 2020 12:16:09 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB6FB18A8234; Fri, 9 Oct 2020 16:16:08 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id E63A919936; Fri, 9 Oct 2020 16:16:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260173; 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=XgT1fGOUL4jL/DLtb47u7sZvwkz25A0LYeYu8H3PXls=; b=AWei3Cgh4DnqD5DIU1S7KWpcPDUrDABG4XKtc2IcqUp4Tw5CKMclJ2Z1F26pnSzKSotIXA XSydkads5Bua0P/V5d3DCUcCzDmlohoWco4+PtajsISyApEs6e0NaTuTbme3q17T0eoXsY 7cF1Lp2hwQqlkAAt1zeWn6893VH9L10= X-MC-Unique: pD6x0s0UNoKmO7ZhM0VZFA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 06/36] qapi: Remove wildcard includes Date: Fri, 9 Oct 2020 12:15:28 -0400 Message-Id: <20201009161558.107041-7-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , John Snow , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Wildcard includes become hard to manage when refactoring and dealing with circular dependencies with strictly typed mypy. flake8 also flags each one as a warning, as it is not smart enough to know which names exist in the imported file. Remove them and include things explicitly by name instead. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 2 +- scripts/qapi/events.py | 7 ++++++- scripts/qapi/gen.py | 12 +++++++++--- scripts/qapi/introspect.py | 7 ++++++- scripts/qapi/types.py | 8 +++++++- scripts/qapi/visit.py | 10 +++++++++- 6 files changed, 38 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 1f43a0a34ef..e06c10afcd0 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -13,7 +13,7 @@ See the COPYING file in the top-level directory. """ =20 -from .common import * +from .common import build_params, c_name, mcgen from .gen import QAPIGenCCode, QAPISchemaModularCVisitor, ifcontext =20 =20 diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 04672724388..6b3afa14d72 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,7 +12,12 @@ See the COPYING file in the top-level directory. """ =20 -from .common import * +from .common import ( + build_params, + c_enum_const, + c_name, + mcgen, +) from .gen import QAPISchemaModularCVisitor, ifcontext from .schema import QAPISchemaEnumMember from .types import gen_enum, gen_enum_lookup diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index fc57fdca5b9..1fed712b43b 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -11,13 +11,19 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 - +from contextlib import contextmanager import errno import os import re -from contextlib import contextmanager =20 -from .common import * +from .common import ( + c_fname, + gen_endif, + gen_if, + guardend, + guardstart, + mcgen, +) from .schema import QAPISchemaVisitor =20 =20 diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 6c82d9d95f5..42016a7e668 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,7 +10,12 @@ See the COPYING file in the top-level directory. """ =20 -from .common import * +from .common import ( + c_name, + gen_endif, + gen_if, + mcgen, +) from .gen import QAPISchemaMonolithicCVisitor from .schema import (QAPISchemaArrayType, QAPISchemaBuiltinType, QAPISchemaType) diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index ca9a5aacb39..53b47f9e58a 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -13,7 +13,13 @@ # See the COPYING file in the top-level directory. """ =20 -from .common import * +from .common import ( + c_enum_const, + c_name, + gen_endif, + gen_if, + mcgen, +) from .gen import QAPISchemaModularCVisitor, ifcontext from .schema import QAPISchemaEnumMember, QAPISchemaObjectType =20 diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 7850f6e8480..ea277e7704b 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -13,7 +13,15 @@ See the COPYING file in the top-level directory. """ =20 -from .common import * +from .common import ( + c_enum_const, + c_name, + gen_endif, + gen_if, + mcgen, + pop_indent, + push_indent, +) from .gen import QAPISchemaModularCVisitor, ifcontext from .schema import QAPISchemaObjectType =20 --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260857; cv=none; d=zohomail.com; s=zohoarc; b=MCcV6ryiLvUBUFrKMoCqWfALCQ2GnxbUHJjz5c9Bhq/rRQNsEOuSjpw5Yrxm9ZESlhRcIs8ZCCo2OWGtYTOYpytuIt5tp4P/6qkUgNh/YJaV4K+/fz5w9Y7uMDpywbtmeELkA12cr3/33bQcsEmkQNr8iVis/hfF1uckBX2ZjOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260857; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1iHAWFK5hEPkFza6aTuhnCLY5QE27kffQhXifiMaVy0=; b=c6tZ79NaeoboDYlCob3MDih3R6d0TIz9rMcFk9MMEn0bQuIfrxWf2glnxJOr1YnyBsrQvFcZVdLm3F5EUwLz+7alzt2YzLFE5CE2YavaeFZWyWiQgzUZuayBH3e2Qiri0MiheWG0FSC8mpbHqi7c2adnbIDveS0VFQFWKPy4zEU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260857806577.1539949496382; Fri, 9 Oct 2020 09:27:37 -0700 (PDT) Received: from localhost ([::1]:34864 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvF2-0001E8-Ji for importer@patchew.org; Fri, 09 Oct 2020 12:27:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv45-0003tP-9x for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31143) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv41-0003F1-FV for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-3-NDtc3uVBPQWDWI4z9vhHNw-1; Fri, 09 Oct 2020 12:16:10 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A18C61084D6A; Fri, 9 Oct 2020 16:16:09 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id E25AF19936; Fri, 9 Oct 2020 16:16:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260172; 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=1iHAWFK5hEPkFza6aTuhnCLY5QE27kffQhXifiMaVy0=; b=i3QV4f+RRiFhX4T30Ri8QixUaaifEj2R/+hf/4+1Frez97isx1el01u8fBLwS1AOOtfIrA oFn5zF8dBZsCDF/Kc7RwhvK+zrQSJFez8mddvv7aFFIHjWqrlgct8wGaO4kekjmlOXIY0L qeJYCOUQ3kKOTArxB2P8MCI3kN2WBFc= X-MC-Unique: NDtc3uVBPQWDWI4z9vhHNw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 07/36] qapi: enforce import order/styling with isort Date: Fri, 9 Oct 2020 12:15:29 -0400 Message-Id: <20201009161558.107041-8-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" While we're mucking around with imports, we might as well formalize the style we use. Let's use isort to do it for us. lines_after_imports=3D2: Use two lines after imports, to match PEP8's desire to have "two lines before and after" class definitions, which are likely to start immediately after imports. force_sort_within_sections: Intermingles "from x" and "import x" style statements, such that sorting is always performed strictly on the module name itself. force_grid_wrap=3D4: Four or more imports from a single module will force the one-per-line style that's more git-friendly. This will generally happen for 'typing' imports. multi_line_output=3D3: Uses the one-per-line indented style for long imports. include_trailing_comma: Adds a comma to the last import in a group, which makes git conflicts nicer to deal with, generally. line_length: 72 is chosen to match PEP8's "docstrings and comments" line length limit. If you have a single line import that exceeds 72 characters, your names are too long! Suggested-by: Cleber Rosa Signed-off-by: John Snow Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/.isort.cfg | 7 +++++++ scripts/qapi/expr.py | 3 ++- scripts/qapi/introspect.py | 7 +++++-- scripts/qapi/parser.py | 2 +- scripts/qapi/schema.py | 2 +- 5 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 scripts/qapi/.isort.cfg diff --git a/scripts/qapi/.isort.cfg b/scripts/qapi/.isort.cfg new file mode 100644 index 00000000000..643caa1fbd6 --- /dev/null +++ b/scripts/qapi/.isort.cfg @@ -0,0 +1,7 @@ +[settings] +force_grid_wrap=3D4 +force_sort_within_sections=3DTrue +include_trailing_comma=3DTrue +line_length=3D72 +lines_after_imports=3D2 +multi_line_output=3D3 diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index bb4dc55f56f..2fcaaa2497a 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -14,8 +14,9 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 -import re from collections import OrderedDict +import re + from .common import c_name from .error import QAPISemError =20 diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 42016a7e668..fafec94e022 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -17,8 +17,11 @@ mcgen, ) from .gen import QAPISchemaMonolithicCVisitor -from .schema import (QAPISchemaArrayType, QAPISchemaBuiltinType, - QAPISchemaType) +from .schema import ( + QAPISchemaArrayType, + QAPISchemaBuiltinType, + QAPISchemaType, +) =20 =20 def _make_tree(obj, ifcond, features, extra=3DNone): diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 7298f5dbd14..e7b9d670ad6 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -14,9 +14,9 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 +from collections import OrderedDict import os import re -from collections import OrderedDict =20 from .error import QAPIParseError, QAPISemError from .source import QAPISourceInfo diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 676185d1a71..71ebb1e396d 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -14,9 +14,9 @@ =20 # TODO catching name collisions in generated code would be nice =20 +from collections import OrderedDict import os import re -from collections import OrderedDict =20 from .common import c_name, pointer_suffix from .error import QAPIError, QAPISemError --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260828; cv=none; d=zohomail.com; s=zohoarc; b=nsCclpeiSa3vvbtGfn8ABgIjVAJlYz2LbX+hXQuwKI6EWvreZVbKH9RulmMI7kKWUei2PTwgwSaxuXKxBvFgxsfd1GnLl90V+9AE0I8Q+cndCt4R3hiDWsLwPBXgLfIuSc9oSeLxSuRqjzeZdvanhGsYQ8gQfJYRZdi6q4Vi0y4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260828; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=E+XO8wBJyyOlh0DOIqFwPn8JUVzvKdWGYYfKMPpS9/s=; b=bOx1LmIcCdeNiUyYpBfRbAsMO0MQGME6BmO6eMfuD4OE0LLcvKgUW2keVhzWykQ/IqeK1oSInYAWyV04rHb9rKM1CN5D+KoVLq79MuNUrtW9JYitk9wynci+vAd8+kGfLI1E/hde3NwItpOz8i2q7yQF2fhnbHbZDxYhgG5Hp8M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260828395513.7602360678743; Fri, 9 Oct 2020 09:27:08 -0700 (PDT) Received: from localhost ([::1]:33214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvEY-0000WC-QX for importer@patchew.org; Fri, 09 Oct 2020 12:27:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv45-0003uW-Qj for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv42-0003FE-63 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-261-G2RTpIn0Mdml5V3xFRnnYw-1; Fri, 09 Oct 2020 12:16:11 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E905804024; Fri, 9 Oct 2020 16:16:10 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB6311A92A; Fri, 9 Oct 2020 16:16:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260173; 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=E+XO8wBJyyOlh0DOIqFwPn8JUVzvKdWGYYfKMPpS9/s=; b=KuDEoHWe4kUZkgyLj9cB76Wz4vomw6RU1JjUKli3f1+DUZsLtmgeVY84dUJHkTJ7D3wDEb o9EN4b33n90iM1jac9yF5Nb3wJPc+5Ff75IQSHpExguoMPIb0nT2yaovr+j790bx+m1Qtj k7byEIleL60f2v1up0+jpqLc1Vtbziw= X-MC-Unique: G2RTpIn0Mdml5V3xFRnnYw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 08/36] qapi: delint using flake8 Date: Fri, 9 Oct 2020 12:15:30 -0400 Message-Id: <20201009161558.107041-9-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Petty style guide fixes and line length enforcement. Not a big win, not a big loss, but flake8 passes 100% on the qapi module, which gives us an easy baseline to enforce hereafter. A note on the flake8 exception: flake8 will warn on *any* bare except, but pylint's is context-aware and will suppress the warning if you re-raise the exception. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/.flake8 | 2 ++ scripts/qapi/commands.py | 3 ++- scripts/qapi/schema.py | 8 +++++--- scripts/qapi/visit.py | 16 +++++++++++----- 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 scripts/qapi/.flake8 diff --git a/scripts/qapi/.flake8 b/scripts/qapi/.flake8 new file mode 100644 index 00000000000..6b158c68b84 --- /dev/null +++ b/scripts/qapi/.flake8 @@ -0,0 +1,2 @@ +[flake8] +extend-ignore =3D E722 # Prefer pylint's bare-except checks to flake8's diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index e06c10afcd0..cde0c1e7770 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -65,7 +65,8 @@ def gen_call(name, arg_type, boxed, ret_type): def gen_marshal_output(ret_type): return mcgen(''' =20 -static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, QObject **ret= _out, Error **errp) +static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, + QObject **ret_out, Error **errp) { Visitor *v; =20 diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 71ebb1e396d..afd750989e1 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -536,7 +536,7 @@ def set_defined_in(self, name): v.set_defined_in(name) =20 def check(self, schema, seen): - if not self.tag_member: # flat union + if not self.tag_member: # flat union self.tag_member =3D seen.get(c_name(self._tag_name)) base =3D "'base'" # Pointing to the base type when not implicit would be @@ -824,7 +824,7 @@ def __init__(self, fname): self._entity_dict =3D {} self._module_dict =3D OrderedDict() self._schema_dir =3D os.path.dirname(fname) - self._make_module(None) # built-ins + self._make_module(None) # built-ins self._make_module(fname) self._predefining =3D True self._def_predefineds() @@ -968,7 +968,9 @@ def _make_implicit_object_type(self, name, info, ifcond= , role, members): # But it's not tight: the disjunction need not imply it. We # may end up compiling useless wrapper types. # TODO kill simple unions or implement the disjunction - assert (ifcond or []) =3D=3D typ._ifcond # pylint: disable=3Dp= rotected-access + + # pylint: disable=3Dprotected-access + assert (ifcond or []) =3D=3D typ._ifcond else: self._def_entity(QAPISchemaObjectType( name, info, None, ifcond, None, None, members, None)) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index ea277e7704b..9fdbe5b9ef3 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -31,7 +31,9 @@ def gen_visit_decl(name, scalar=3DFalse): if not scalar: c_type +=3D '*' return mcgen(''' -bool visit_type_%(c_name)s(Visitor *v, const char *name, %(c_type)sobj, Er= ror **errp); + +bool visit_type_%(c_name)s(Visitor *v, const char *name, + %(c_type)sobj, Error **errp); ''', c_name=3Dc_name(name), c_type=3Dc_type) =20 @@ -125,7 +127,8 @@ def gen_visit_object_members(name, base, members, varia= nts): def gen_visit_list(name, element_type): return mcgen(''' =20 -bool visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj,= Error **errp) +bool visit_type_%(c_name)s(Visitor *v, const char *name, + %(c_name)s **obj, Error **errp) { bool ok =3D false; %(c_name)s *tail; @@ -158,7 +161,8 @@ def gen_visit_list(name, element_type): def gen_visit_enum(name): return mcgen(''' =20 -bool visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s *obj, = Error **errp) +bool visit_type_%(c_name)s(Visitor *v, const char *name, + %(c_name)s *obj, Error **errp) { int value =3D *obj; bool ok =3D visit_type_enum(v, name, &value, &%(c_name)s_lookup, errp); @@ -172,7 +176,8 @@ def gen_visit_enum(name): def gen_visit_alternate(name, variants): ret =3D mcgen(''' =20 -bool visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj,= Error **errp) +bool visit_type_%(c_name)s(Visitor *v, const char *name, + %(c_name)s **obj, Error **errp) { bool ok =3D false; =20 @@ -247,7 +252,8 @@ def gen_visit_alternate(name, variants): def gen_visit_object(name, base, members, variants): return mcgen(''' =20 -bool visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj,= Error **errp) +bool visit_type_%(c_name)s(Visitor *v, const char *name, + %(c_name)s **obj, Error **errp) { bool ok =3D false; =20 --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261409; cv=none; d=zohomail.com; s=zohoarc; b=jpLtfnCUmMbQI+cQRAvvBcE+TencauaSmwB9LKKVjDNHXh12Ok0HjMsUXtbvhQTR4gAJcvpjdq/zWhoUnBjHTcHKSlcKP0hLDQnXsyvmAXcQwePOS/cbWSRDVgD0C41JFSgwSqFLI6N2Ylrffh8d6yzHNpHBGx9+qi2xMelx0Sg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261409; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=0HkGlH/S1G8I1HloqL7saGuuP/XHnYpyYBQxvhdOfUY=; b=QFutm4EuaoCARSOzFbLs/g9DWPStHwXgneKnXxKFLhensNykJXnMWhboWB7+IoL7xKDy14e4dJ4e8bUHj2NEnuMCJh1BT+BsI94vUQDAiaDGFkgFUm7Ju+J3t5HBeBCSu02x7+cAlys9CUWpEMaNPq+ueTNMoWxremVcVPLkzjI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261409311440.45040506216355; Fri, 9 Oct 2020 09:36:49 -0700 (PDT) Received: from localhost ([::1]:38842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvNv-0006OW-TU for importer@patchew.org; Fri, 09 Oct 2020 12:36:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv48-0003zJ-2Q for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26350) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv46-0003GU-3D for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-xasv_TYlMtiL8QsojjIHyQ-1; Fri, 09 Oct 2020 12:16:12 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 74FB518A8236; Fri, 9 Oct 2020 16:16:11 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id B40211A8EC; Fri, 9 Oct 2020 16:16:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260177; 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=0HkGlH/S1G8I1HloqL7saGuuP/XHnYpyYBQxvhdOfUY=; b=ehn9eeq4eY6DO7WAHW8UEPtig/xvODb7xc39R7nNq/fBYPnPCSotmT7ZHG3wdD5i9OJU54 HYBRrt9DqHtVSIcHX/acZtggbsqNzKil7HqNesEWy+eXL8TMiYk5ElE1CuR+zsGzwRVLhr XIayo7Ev4fIGgIu6cwo0ejY8zZKvrkY= X-MC-Unique: xasv_TYlMtiL8QsojjIHyQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 09/36] qapi: add pylintrc Date: Fri, 9 Oct 2020 12:15:31 -0400 Message-Id: <20201009161558.107041-10-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Using `pylint --generate-rcfile > pylintrc`, generate a skeleton pylintrc file. Sections that are not presently relevant (by the end of this series) are removed leaving just the empty section as a search engine / documentation hint to future authors. I am targeting pylint 2.6.0. In the future (and hopefully before 5.2 is released), I aim to have gitlab CI running the specific targeted versions of pylint, mypy, flake8, etc in a job. 2.5.x will work if you additionally pass --disable=3Dbad-whitespace. This warning was removed from 2.6.x, for lack of consistent support. Right now, quite a few modules are ignored as they are known to fail as of this commit. modules will be removed from the known-bad list throughout this and following series as they are repaired. Note: Normally, pylintrc would go in the folder above the module, but as that folder is shared by many things, it is going inside the module folder (for now). Due to a bug in pylint 2.5+, pylint does not correctly recognize when it is being run from "inside" a package, and must be run *outside* of the package. Therefore, to run it, you must: > pylint scripts/qapi/ --rcfile=3Dscripts/qapi/pylintrc Signed-off-by: John Snow Tested-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/pylintrc | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 scripts/qapi/pylintrc diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc new file mode 100644 index 00000000000..76d54c30f85 --- /dev/null +++ b/scripts/qapi/pylintrc @@ -0,0 +1,73 @@ +[MASTER] + +# Add files or directories matching the regex patterns to the ignore list. +# The regex matches against base names, not paths. +ignore-patterns=3Dcommon.py, + error.py, + expr.py, + gen.py, + parser.py, + schema.py, + source.py, + types.py, + visit.py, + + +[MESSAGES CONTROL] + +# Disable the message, report, category or checker with the given id(s). Y= ou +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once). You can also use "--disable=3Dal= l" to +# disable everything first and then reenable specific checks. For example,= if +# you want to run only the similarities checker, you can use "--disable=3D= all +# --enable=3Dsimilarities". If you want to run only the classes checker, b= ut have +# no Warning level messages displayed, use "--disable=3Dall --enable=3Dcla= sses +# --disable=3DW". +disable=3Dfixme, + missing-docstring, + too-many-arguments, + too-many-branches, + too-many-statements, + too-many-instance-attributes, + +[REPORTS] + +[REFACTORING] + +[MISCELLANEOUS] + +[LOGGING] + +[BASIC] + +# Good variable names which should always be accepted, separated by a comm= a. +good-names=3Di, + j, + k, + ex, + Run, + _ + +[VARIABLES] + +[STRING] + +[SPELLING] + +[FORMAT] + +[SIMILARITIES] + +# Ignore import statements themselves when computing similarities. +ignore-imports=3Dyes + +[TYPECHECK] + +[CLASSES] + +[IMPORTS] + +[DESIGN] + +[EXCEPTIONS] --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260487; cv=none; d=zohomail.com; s=zohoarc; b=ZbGcGpxJK6G/uEkyoLuDpNZGXtYELoFU74LS1swm90IsiASuNUszX+Fy1tzv2rpVvXQ7dFcvAwwWpJtSUDKkxVFPoO4SbT5JkckqjuBYR0HlX0shRpmrlaj6Kt61mAuKJlLMjN+Wk9SfOqJlVw3/Hw6iNTyAC3Y1eTRBmZkl2Ek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260487; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EW9kDSGFfqZGToEfukpDtNLZSJWc7nbVLrWC8RJvEkI=; b=MfMQuNsdQImXIERAYMkiUwf9ZmbE9Ij4Y+S/KyifThwIyWEbjQsjP5nKxnwA5S57YqX/G3Rr/wzS4feEjqC9tqyEallmrubv3pQFTr3hhVsLSkdlgA2rKT32KvHnf6KDr9X/f7V7TuOt7Ph2GLZo3Nc3PMC6Ur9vmb9de5DPKf4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160226048791235.91794510171633; Fri, 9 Oct 2020 09:21:27 -0700 (PDT) Received: from localhost ([::1]:42198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQv94-0000xt-7f for importer@patchew.org; Fri, 09 Oct 2020 12:21:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34386) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv47-0003xj-Cb for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55445) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv45-0003GO-OL for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-553-jxXMMcGWNoSlRsKjBEfZ3g-1; Fri, 09 Oct 2020 12:16:13 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 710F51019627; Fri, 9 Oct 2020 16:16:12 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A73F1A92A; Fri, 9 Oct 2020 16:16:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260177; 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=EW9kDSGFfqZGToEfukpDtNLZSJWc7nbVLrWC8RJvEkI=; b=iSFGDmEc20n91XEZCFAKnn7NVaH7KhJV3mS0X9dJD/R2lrBSNF0uyo11otbOrzh9qRlqbX 7BAUZ8BmtSwlesRDnulmrgY4JPG4m3l4xO5/c+RJcat+PqyNFfK//0vvn2SWYi7mi5qibG Xh6OeOi9LlIp5GdrxbYk8XByCx9pXxE= X-MC-Unique: jxXMMcGWNoSlRsKjBEfZ3g-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 10/36] qapi/common.py: Remove python compatibility workaround Date: Fri, 9 Oct 2020 12:15:32 -0400 Message-Id: <20201009161558.107041-11-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/common.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index ba35abea478..cee63eb95c7 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -119,10 +119,7 @@ def cgen(code, **kwds): raw =3D code % kwds if indent_level: indent =3D genindent(indent_level) - # re.subn() lacks flags support before Python 2.7, use re.compile() - raw =3D re.subn(re.compile(r'^(?!(#|$))', re.MULTILINE), - indent, raw) - raw =3D raw[0] + raw =3D re.sub(r'^(?!(#|$))', indent, raw, flags=3Dre.MULTILINE) return re.sub(re.escape(eatspace) + r' *', '', raw) =20 =20 --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261565; cv=none; d=zohomail.com; s=zohoarc; b=Uic/OSXupo/jXE7IfPTpnic9rq4N4/AJn7CCCpHL/RNHZ+d86ZmytkuqCtM2ctXiaRYJ8zffioWkrmh9v82sCIyHVRCzE0wEZQg2WQl0+eb4d0AdD/KeooA0kxWhtTFsOVAwzHgyL/LI2t1Z43nVKaX8Kc0/e9NAMzzLegWUmMs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261565; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KnK9/+GgEu+M3Hi8HeEQdcHK2jWaIlIyMMIo7F7VHcM=; b=QLa1+y7m89At5zaB4IzYM9NAwzBtV7ol4xFm+5sFO9KnQbqMoj8N8x6osnhMcAkD0uh1yRJKC1HQy9Xe+r6l/24gCx7SH/4stSkzNGdFPVR5NR6q7/WDRbpM2eY8X0hlAr/J2ch1kM+wcB0I11DJXXAWIA2q2D/iMmQhJ8ZyDyg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261565610576.1423468680276; Fri, 9 Oct 2020 09:39:25 -0700 (PDT) Received: from localhost ([::1]:47106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvQS-0001Vb-Bf for importer@patchew.org; Fri, 09 Oct 2020 12:39:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv49-00042d-Bw for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40466) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv47-0003Gu-Du for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-471-GxkFS4fDOn2ok4jDTx7FiA-1; Fri, 09 Oct 2020 12:16:14 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CBD431084D64; Fri, 9 Oct 2020 16:16:13 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id B31A319936; Fri, 9 Oct 2020 16:16:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260178; 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=KnK9/+GgEu+M3Hi8HeEQdcHK2jWaIlIyMMIo7F7VHcM=; b=CQ041tHzvHfB/I3jD6BBTtwoa9YIm5meWdj/OweerdNtTMVwLSJR0//ju2VEA2GSuEA/Sv h7UAn09XutawsXStPpJ9vUHYnoKU0n6Av3H6eReh4yhtNC1DF5ABQyWb3RdgrSaYitLmhr h2fPJlepcMPp0vxNe7LBjSYYWk5YHNM= X-MC-Unique: GxkFS4fDOn2ok4jDTx7FiA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 11/36] qapi/common.py: Add indent manager Date: Fri, 9 Oct 2020 12:15:33 -0400 Message-Id: <20201009161558.107041-12-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Code style tools really dislike the use of global keywords, because it generally involves re-binding the name at runtime which can have strange effects depending on when and how that global name is referenced in other modules. Make a little indent level manager instead. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/common.py | 49 ++++++++++++++++++++++++++++-------------- scripts/qapi/visit.py | 7 +++--- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index cee63eb95c7..b35318b72cf 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -93,33 +93,50 @@ def c_name(name, protect=3DTrue): pointer_suffix =3D ' *' + eatspace =20 =20 -def genindent(count): - ret =3D '' - for _ in range(count): - ret +=3D ' ' - return ret +class Indentation: + """ + Indentation level management. =20 + :param initial: Initial number of spaces, default 0. + """ + def __init__(self, initial: int =3D 0) -> None: + self._level =3D initial =20 -indent_level =3D 0 + def __int__(self) -> int: + return self._level =20 + def __repr__(self) -> str: + return "{}({:d})".format(type(self).__name__, self._level) =20 -def push_indent(indent_amount=3D4): - global indent_level - indent_level +=3D indent_amount + def __str__(self) -> str: + """Return the current indentation as a string of spaces.""" + return ' ' * self._level =20 + def __bool__(self) -> bool: + """True when there is a non-zero indentation.""" + return bool(self._level) =20 -def pop_indent(indent_amount=3D4): - global indent_level - indent_level -=3D indent_amount + def increase(self, amount: int =3D 4) -> None: + """Increase the indentation level by ``amount``, default 4.""" + self._level +=3D amount + + def decrease(self, amount: int =3D 4) -> None: + """Decrease the indentation level by ``amount``, default 4.""" + if self._level < amount: + raise ArithmeticError( + f"Can't remove {amount:d} spaces from {self!r}") + self._level -=3D amount + + +indent =3D Indentation() =20 =20 # Generate @code with @kwds interpolated. -# Obey indent_level, and strip eatspace. +# Obey indent, and strip eatspace. def cgen(code, **kwds): raw =3D code % kwds - if indent_level: - indent =3D genindent(indent_level) - raw =3D re.sub(r'^(?!(#|$))', indent, raw, flags=3Dre.MULTILINE) + if indent: + raw =3D re.sub(r'^(?!(#|$))', str(indent), raw, flags=3Dre.MULTILI= NE) return re.sub(re.escape(eatspace) + r' *', '', raw) =20 =20 diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 9fdbe5b9ef3..708f72c4a1e 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -18,9 +18,8 @@ c_name, gen_endif, gen_if, + indent, mcgen, - pop_indent, - push_indent, ) from .gen import QAPISchemaModularCVisitor, ifcontext from .schema import QAPISchemaObjectType @@ -69,7 +68,7 @@ def gen_visit_object_members(name, base, members, variant= s): if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) { ''', name=3Dmemb.name, c_name=3Dc_name(memb.name)) - push_indent() + indent.increase() ret +=3D mcgen(''' if (!visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, errp)) { return false; @@ -78,7 +77,7 @@ def gen_visit_object_members(name, base, members, variant= s): c_type=3Dmemb.type.c_name(), name=3Dmemb.name, c_name=3Dc_name(memb.name)) if memb.optional: - pop_indent() + indent.decrease() ret +=3D mcgen(''' } ''') --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260999; cv=none; d=zohomail.com; s=zohoarc; b=XVpzK4fVro1DnUva0OVOsFfOv6LPzI0gMQfFpvVMKnS4mvx9KnkDSzb3f2rQTVEUyLucbRzUnv/5XT2PG7wN6rFTL4RR6LA3RdwfDbhdRVCaIIy/0UjIwCxjoJBz2qWaXSqCSOUGUZI7+FSOmbdygKOnISY5Tjaq3RlAsgSHMSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260999; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sbAE7PoBtXSgQQ+NiLAvpOH4vFTXlbZMvRtulriPPz4=; b=Khed024faaC2OPih1Lo54196IZM/puKHu24XhqlsGNU3QKLihHktVxgMFDRm2BMj0aaksakutV2S+lLQQgBiTBozc5tP7IIX9zBgBbnowNCfG/fpOFoE5mmOI4wMvZ0fC8QozH2D2R7bKKCNqqxf4ddJpMbLt6AdiYxUQSgIjcM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260999189668.6489865272549; Fri, 9 Oct 2020 09:29:59 -0700 (PDT) Received: from localhost ([::1]:43110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvHJ-0004ho-Ql for importer@patchew.org; Fri, 09 Oct 2020 12:29:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4G-000443-Ts for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50687) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv47-0003Gw-HQ for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-17-K9qWYDUhO1yPoGTxCBefxQ-1; Fri, 09 Oct 2020 12:16:16 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E1DB218A822F; Fri, 9 Oct 2020 16:16:14 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D15C19936; Fri, 9 Oct 2020 16:16:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260178; 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=sbAE7PoBtXSgQQ+NiLAvpOH4vFTXlbZMvRtulriPPz4=; b=gs6ZzygVI+lpJwnMbcMmRLEoN9cwA9TBGi0D2+sDp3s6SYMbs5VQmjNxxeoiFvdyAJacSU CAyh7mkOVhowRWjhRV09TB5ip4rw12Z7Vn0yJziRIhhoCoDzKHuTX0Eae5sITVn4O1cTv5 BJ9wwMO3zCxJ6AKuqFBdcpDeqTpW2KY= X-MC-Unique: K9qWYDUhO1yPoGTxCBefxQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 12/36] qapi/common.py: delint with pylint Date: Fri, 9 Oct 2020 12:15:34 -0400 Message-Id: <20201009161558.107041-13-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" At this point, that just means using a consistent strategy for constant nam= es. constants get UPPER_CASE and names not used externally get a leading unders= core. As a preference, while renaming constants to be UPPERCASE, move them to the head of the file. Generally, it's nice to be able to audit the code that runs on import in one central place. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/common.py | 18 ++++++++---------- scripts/qapi/schema.py | 14 +++++++------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index b35318b72cf..a417b6029c8 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -14,6 +14,11 @@ import re =20 =20 +EATSPACE =3D '\033EATSPACE.' +POINTER_SUFFIX =3D ' *' + EATSPACE +_C_NAME_TRANS =3D str.maketrans('.-', '__') + + # ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1 # ENUM_NAME -> ENUM_NAME, ENUM_NAME1 -> ENUM_NAME1, ENUM_Name2 -> ENUM_NAM= E2 # ENUM24_Name -> ENUM24_NAME @@ -42,9 +47,6 @@ def c_enum_const(type_name, const_name, prefix=3DNone): return camel_to_upper(type_name) + '_' + c_name(const_name, False).upp= er() =20 =20 -c_name_trans =3D str.maketrans('.-', '__') - - # Map @name to a valid C identifier. # If @protect, avoid returning certain ticklish identifiers (like # C keywords) by prepending 'q_'. @@ -82,17 +84,13 @@ def c_name(name, protect=3DTrue): 'not_eq', 'or', 'or_eq', 'xor', 'xor_eq']) # namespace pollution: polluted_words =3D set(['unix', 'errno', 'mips', 'sparc', 'i386']) - name =3D name.translate(c_name_trans) + name =3D name.translate(_C_NAME_TRANS) if protect and (name in c89_words | c99_words | c11_words | gcc_words | cpp_words | polluted_words): return 'q_' + name return name =20 =20 -eatspace =3D '\033EATSPACE.' -pointer_suffix =3D ' *' + eatspace - - class Indentation: """ Indentation level management. @@ -132,12 +130,12 @@ def decrease(self, amount: int =3D 4) -> None: =20 =20 # Generate @code with @kwds interpolated. -# Obey indent, and strip eatspace. +# Obey indent, and strip EATSPACE. def cgen(code, **kwds): raw =3D code % kwds if indent: raw =3D re.sub(r'^(?!(#|$))', str(indent), raw, flags=3Dre.MULTILI= NE) - return re.sub(re.escape(eatspace) + r' *', '', raw) + return re.sub(re.escape(EATSPACE) + r' *', '', raw) =20 =20 def mcgen(code, **kwds): diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index afd750989e1..7c015929569 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -18,7 +18,7 @@ import os import re =20 -from .common import c_name, pointer_suffix +from .common import POINTER_SUFFIX, c_name from .error import QAPIError, QAPISemError from .expr import check_exprs from .parser import QAPISchemaParser @@ -309,7 +309,7 @@ def is_implicit(self): return True =20 def c_type(self): - return c_name(self.name) + pointer_suffix + return c_name(self.name) + POINTER_SUFFIX =20 def json_type(self): return 'array' @@ -430,7 +430,7 @@ def c_name(self): =20 def c_type(self): assert not self.is_implicit() - return c_name(self.name) + pointer_suffix + return c_name(self.name) + POINTER_SUFFIX =20 def c_unboxed_type(self): return c_name(self.name) @@ -504,7 +504,7 @@ def connect_doc(self, doc=3DNone): v.connect_doc(doc) =20 def c_type(self): - return c_name(self.name) + pointer_suffix + return c_name(self.name) + POINTER_SUFFIX =20 def json_type(self): return 'value' @@ -899,7 +899,7 @@ def _def_builtin_type(self, name, json_type, c_type): self._make_array_type(name, None) =20 def _def_predefineds(self): - for t in [('str', 'string', 'char' + pointer_suffix), + for t in [('str', 'string', 'char' + POINTER_SUFFIX), ('number', 'number', 'double'), ('int', 'int', 'int64_t'), ('int8', 'int', 'int8_t'), @@ -912,8 +912,8 @@ def _def_predefineds(self): ('uint64', 'int', 'uint64_t'), ('size', 'int', 'uint64_t'), ('bool', 'boolean', 'bool'), - ('any', 'value', 'QObject' + pointer_suffix), - ('null', 'null', 'QNull' + pointer_suffix)]: + ('any', 'value', 'QObject' + POINTER_SUFFIX), + ('null', 'null', 'QNull' + POINTER_SUFFIX)]: self._def_builtin_type(*t) self.the_empty_object_type =3D QAPISchemaObjectType( 'q_empty', None, None, None, None, None, [], None) --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260660; cv=none; d=zohomail.com; s=zohoarc; b=bywbtsu/RInty0cnsSlL79bdoIhAeHFcO1Y/EfNKm3/9rWGoCNrI+OaSMH+dXbeMPZ/wSmDrYQMqNI7HAnx/tAUg5KxaTBOCh3w6uPTnyuvQCky8WJs913CQPuIMqFPi3i0YAcZZs/ApwWpu39yg+bNxxHxZ3g7UEIHTcrQZytE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260660; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dzDMefnNZNoEKn8iwNmWWwoUzTm42txJyV0yVF2JleQ=; b=aBfQ1jmZ/uVf62jHLj/G9pdl5kTX8LQD8cThloa6AEOKVEzvsvcqXr0o/9OeUgTjPnuK7JaFXwQegyg7tK8hgYk4yDYe0r0nolbFuuXKCxlv7b3Qj96hmQfRo+n3oCBVMdcRiqLeq1Qac4RXpzKCNIf1iQVF1Q1hRBl8hKhUlqY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160226066076640.9404344152249; Fri, 9 Oct 2020 09:24:20 -0700 (PDT) Received: from localhost ([::1]:50632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvBr-0004SY-4d for importer@patchew.org; Fri, 09 Oct 2020 12:24:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4I-00047t-D7 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33351) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4G-0003He-J6 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-115-IkFXDzgZPhK4F-Rd-f4QvQ-1; Fri, 09 Oct 2020 12:16:21 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 74F3F186DD36; Fri, 9 Oct 2020 16:16:19 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 125B419936; Fri, 9 Oct 2020 16:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260183; 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=dzDMefnNZNoEKn8iwNmWWwoUzTm42txJyV0yVF2JleQ=; b=iiDOWJymlAx2OoTywxupGAhkCmArm44MJluwXn4e/NeOIvdyQ3k+2g45w9DVdfAEV1qtfP mM7fJr5n2HtlUAJhl8WSoEHYYgmvaRx1K+ntAgx2hzstwWsAyeDRJmIXcpqkbdBxAdx5qs axysznqdDzRwME7o/I8W4zf92+keUnU= X-MC-Unique: IkFXDzgZPhK4F-Rd-f4QvQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 13/36] qapi/common.py: Replace one-letter 'c' variable Date: Fri, 9 Oct 2020 12:15:35 -0400 Message-Id: <20201009161558.107041-14-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , John Snow , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster --- scripts/qapi/common.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index a417b6029c8..338adedef4f 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -30,14 +30,14 @@ def camel_to_upper(value): new_name =3D '' length =3D len(c_fun_str) for i in range(length): - c =3D c_fun_str[i] - # When c is upper and no '_' appears before, do more checks - if c.isupper() and (i > 0) and c_fun_str[i - 1] !=3D '_': + char =3D c_fun_str[i] + # When char is upper case and no '_' appears before, do more checks + if char.isupper() and (i > 0) and c_fun_str[i - 1] !=3D '_': if i < length - 1 and c_fun_str[i + 1].islower(): new_name +=3D '_' elif c_fun_str[i - 1].isdigit(): new_name +=3D '_' - new_name +=3D c + new_name +=3D char return new_name.lstrip('_').upper() =20 =20 --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260788; cv=none; d=zohomail.com; s=zohoarc; b=jNWMD2Tf4DI4F5s7fKvVITi9rNkQxR5mrwTE+F451J0ORmvacoeDA+YoMNKIHszB0jyL4Dl94zQJ4Er8uGAm5TVIhlFzXLdq8MP81AO8QKyEj/IRxzFBjvOr4FslmjtDRPVfLRodWLK+Ywc0o4RBnaY4yPv3ssyG9Hp1tmgcWl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260788; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QrXHxiLvRbPZAt+qYlKSWmWWRnps9cjuGJQdS7kbXBY=; b=SlpJzBsk9zrvvpd+28cZespH3g447dbcQ9XB0Z7Q8CWx2VjG8btbX/mwokR7lpo2b+MPIibOCMRERGWA0hcbIdszfDtr50XK6mVWvYS94FV3vtgnwEcHS+CZPH2ca6VxQIwxe3Vsi6A/ksre5pfUDu117fYJBH5snKi+iEANVl4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260788574156.15163567138097; Fri, 9 Oct 2020 09:26:28 -0700 (PDT) Received: from localhost ([::1]:58986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvDu-0007vD-7q for importer@patchew.org; Fri, 09 Oct 2020 12:26:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4L-0004D9-2g for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:38507) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4G-0003Hc-N6 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-110-WkMDg-NAPNOL3GlxxfYjUg-1; Fri, 09 Oct 2020 12:16:21 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57A5064086; Fri, 9 Oct 2020 16:16:20 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98E3419936; Fri, 9 Oct 2020 16:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260182; 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=QrXHxiLvRbPZAt+qYlKSWmWWRnps9cjuGJQdS7kbXBY=; b=IldNVv2K8p2Apgjc8TzFF6C0xhx3Go1Cr+O1ysDCuG6Wh6ZjBE65SwAOhecVkGl5I42Tyi nBdm3A2TBlwCi+VqJu8dnKsSpgCHPw0HeCeomfSIhPu7fqNeDXFfOkYFn2cFHKLu91TC4v oUZiuAWBtYDThR/Orgfy0ducn9u18oM= X-MC-Unique: WkMDg-NAPNOL3GlxxfYjUg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 14/36] qapi/common.py: check with pylint Date: Fri, 9 Oct 2020 12:15:36 -0400 Message-Id: <20201009161558.107041-15-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove qapi/common.py from the pylintrc ignore list. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Tested-by: Eduardo Habkost Reviewed-by: Markus Armbruster --- scripts/qapi/pylintrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index 76d54c30f85..507f15537ab 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -2,8 +2,7 @@ =20 # Add files or directories matching the regex patterns to the ignore list. # The regex matches against base names, not paths. -ignore-patterns=3Dcommon.py, - error.py, +ignore-patterns=3Derror.py, expr.py, gen.py, parser.py, --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261169; cv=none; d=zohomail.com; s=zohoarc; b=KoRWAwDhGDBW2KU4W7RoYA8ynBZMYvwYS5Rjg50BuYWmuRUCnz4nnd+xky6rxS6KD1qmugnbk3UKq7hRJo0FuLjm9WbVan/yNQWUn1dEGG2YRuwU6wviLkKbZo4QRE33gZmORYdEszvpVcrsxLnHaT+Peor2x++Wc7QkkCvvlqA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261169; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uzWtOCuBHxv0uBQt9mqperOOrxpQMDVzXHiuOcdXAu8=; b=Zr1NBOQL4DqDkfIGJ2ttmaSaYVxWzdsARgTkr2iaQT2xnXJdguVcGthkA5m/56iVVXI2iq2YOubgizU9OFxouKwzUhi/zmPe0ax/oB/AQqiuqGIzeAbeBhDWoq1WjPUGeAbQJx+loPloaL1DTU1vBWyPWraW6wDIAj7frwPaswk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261169496703.4834189356912; Fri, 9 Oct 2020 09:32:49 -0700 (PDT) Received: from localhost ([::1]:51644 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvK4-0008Q9-9K for importer@patchew.org; Fri, 09 Oct 2020 12:32:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4K-0004Ae-2X for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40314) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4G-0003Hq-JX for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:31 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-B7d_QcfOO_KJxNLbIM-3Aw-1; Fri, 09 Oct 2020 12:16:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A5B0101962D; Fri, 9 Oct 2020 16:16:21 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DFE21A92A; Fri, 9 Oct 2020 16:16:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260184; 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=uzWtOCuBHxv0uBQt9mqperOOrxpQMDVzXHiuOcdXAu8=; b=Owbm5rCCJrVHIJdDVPljS+HP5422QTQ8hUVLqpN8hba+LaALxUmA1M7526VsF1vEODyGoh Fd4BTe2sFp3QPu62SAI8MSNQBH1q0jpFTtLpOMUCKzDC90Qyq+0BeANmt/wX/+EzLyw9y4 2dRGw4ton5H/h5PCCAO1xd8rUDX+sPs= X-MC-Unique: B7d_QcfOO_KJxNLbIM-3Aw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 15/36] qapi/common.py: add type hint annotations Date: Fri, 9 Oct 2020 12:15:37 -0400 Message-Id: <20201009161558.107041-16-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Note that build_params() cannot be fully annotated due to import dependency issues. The commit after next will take care of it. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/common.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 338adedef4f..74a2c001ed9 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -12,6 +12,7 @@ # See the COPYING file in the top-level directory. =20 import re +from typing import Optional, Sequence =20 =20 EATSPACE =3D '\033EATSPACE.' @@ -22,7 +23,7 @@ # ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1 # ENUM_NAME -> ENUM_NAME, ENUM_NAME1 -> ENUM_NAME1, ENUM_Name2 -> ENUM_NAM= E2 # ENUM24_Name -> ENUM24_NAME -def camel_to_upper(value): +def camel_to_upper(value: str) -> str: c_fun_str =3D c_name(value, False) if value.isupper(): return c_fun_str @@ -41,7 +42,9 @@ def camel_to_upper(value): return new_name.lstrip('_').upper() =20 =20 -def c_enum_const(type_name, const_name, prefix=3DNone): +def c_enum_const(type_name: str, + const_name: str, + prefix: Optional[str] =3D None) -> str: if prefix is not None: type_name =3D prefix return camel_to_upper(type_name) + '_' + c_name(const_name, False).upp= er() @@ -56,7 +59,7 @@ def c_enum_const(type_name, const_name, prefix=3DNone): # into substrings of a generated C function name. # '__a.b_c' -> '__a_b_c', 'x-foo' -> 'x_foo' # protect=3DTrue: 'int' -> 'q_int'; protect=3DFalse: 'int' -> 'int' -def c_name(name, protect=3DTrue): +def c_name(name: str, protect: bool =3D True) -> str: # ANSI X3J11/88-090, 3.1.1 c89_words =3D set(['auto', 'break', 'case', 'char', 'const', 'continue= ', 'default', 'do', 'double', 'else', 'enum', 'extern', @@ -131,24 +134,24 @@ def decrease(self, amount: int =3D 4) -> None: =20 # Generate @code with @kwds interpolated. # Obey indent, and strip EATSPACE. -def cgen(code, **kwds): +def cgen(code: str, **kwds: object) -> str: raw =3D code % kwds if indent: raw =3D re.sub(r'^(?!(#|$))', str(indent), raw, flags=3Dre.MULTILI= NE) return re.sub(re.escape(EATSPACE) + r' *', '', raw) =20 =20 -def mcgen(code, **kwds): +def mcgen(code: str, **kwds: object) -> str: if code[0] =3D=3D '\n': code =3D code[1:] return cgen(code, **kwds) =20 =20 -def c_fname(filename): +def c_fname(filename: str) -> str: return re.sub(r'[^A-Za-z0-9_]', '_', filename) =20 =20 -def guardstart(name): +def guardstart(name: str) -> str: return mcgen(''' #ifndef %(name)s #define %(name)s @@ -157,7 +160,7 @@ def guardstart(name): name=3Dc_fname(name).upper()) =20 =20 -def guardend(name): +def guardend(name: str) -> str: return mcgen(''' =20 #endif /* %(name)s */ @@ -165,7 +168,7 @@ def guardend(name): name=3Dc_fname(name).upper()) =20 =20 -def gen_if(ifcond): +def gen_if(ifcond: Sequence[str]) -> str: ret =3D '' for ifc in ifcond: ret +=3D mcgen(''' @@ -174,7 +177,7 @@ def gen_if(ifcond): return ret =20 =20 -def gen_endif(ifcond): +def gen_endif(ifcond: Sequence[str]) -> str: ret =3D '' for ifc in reversed(ifcond): ret +=3D mcgen(''' @@ -183,7 +186,9 @@ def gen_endif(ifcond): return ret =20 =20 -def build_params(arg_type, boxed, extra=3DNone): +def build_params(arg_type, + boxed: bool, + extra: Optional[str] =3D None) -> str: ret =3D '' sep =3D '' if boxed: --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261762; cv=none; d=zohomail.com; s=zohoarc; b=ltYHAIT4k7shPDqWpf+Au+28aPf8okc/jrjQOq+asm/dHJsydaC0OeOGfK3ee1UVRGItLFJPgxfVApL4J3KYx5hQ6O6z2iHemGSAPUPUk3Rsno7Eu2/eos/VVq/rfD+7BTEan5BYaKh0dKtBA6lKPFpoiqE7I8vHlYxn7zbl5p8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261762; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IPHZPS7DVLAid6N1Y0imlk3WKvvs9C+8n7G+aYVVt0o=; b=aEChVejWkUNWwRple7IsM5Ohm+clavbDeFdViuIuHlZhm7yRT90w5aFO+ytpPXLZT0i6QE+MtXX5BQDsLy4uqZrk0a+uCGgAteE97tfNcQ4SUXq5IEeBBWaoaQloM8qtrt+9xiY+ZxxKMC4O9AfTP57Cp/TYFUXSM+zv1WPHzxo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261762381382.17543665453104; Fri, 9 Oct 2020 09:42:42 -0700 (PDT) Received: from localhost ([::1]:58094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvTc-0006DN-VK for importer@patchew.org; Fri, 09 Oct 2020 12:42:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4K-0004B7-BD for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:21692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4G-0003Hx-Lp for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:31 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-AkxnScEmOfaFe_FHEkDg2A-1; Fri, 09 Oct 2020 12:16:23 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1DC1A1019642; Fri, 9 Oct 2020 16:16:22 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61EF01A92A; Fri, 9 Oct 2020 16:16:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260185; 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=IPHZPS7DVLAid6N1Y0imlk3WKvvs9C+8n7G+aYVVt0o=; b=M5sumwJEEA1dzNiGXKn39RDBVQXZeXv+VwmEFJqEiy24kMRa7dxWWkBxS/cZ0YZ2M14Wrx +sLljssxQWQQy09x71Q2aua8ik7x/MVnOszKBLneFhIXfPctgAE6hXQfONrQOVv2tcAHZY hVujMAlP9vo/UIrOQ49UPbJ9i6R01I0= X-MC-Unique: AkxnScEmOfaFe_FHEkDg2A-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 16/36] qapi/common.py: Convert comments into docstrings, and elaborate Date: Fri, 9 Oct 2020 12:15:38 -0400 Message-Id: <20201009161558.107041-17-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As docstrings, they'll show up in documentation and IDE help. The docstring style being targeted is the Sphinx documentation style. Sphinx uses an extension of ReST with "domains". We use the (implicit) Python domain, which supports a number of custom "info fields". Those info fields are documented here: https://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html#in= fo-field-lists Primarily, we use `:param X: descr`, `:return[s]: descr`, and `:raise[s] Z: when`. Everything else is the Sphinx dialect of ReST. (No, nothing checks or enforces this style that I am aware of. Sphinx either chokes or succeeds, but does not enforce a standard of what is otherwise inside the docstring. Pycharm does highlight when your param fields are not aligned with the actual fields present. It does not highlight missing return or exception statements. There is no existing style guide I am aware of that covers a standard for a minimally acceptable docstring. I am debating writing one.) Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/common.py | 54 +++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 74a2c001ed9..669e3829b34 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -15,15 +15,25 @@ from typing import Optional, Sequence =20 =20 +#: Magic string that gets removed along with all space to its right. EATSPACE =3D '\033EATSPACE.' POINTER_SUFFIX =3D ' *' + EATSPACE _C_NAME_TRANS =3D str.maketrans('.-', '__') =20 =20 -# ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1 -# ENUM_NAME -> ENUM_NAME, ENUM_NAME1 -> ENUM_NAME1, ENUM_Name2 -> ENUM_NAM= E2 -# ENUM24_Name -> ENUM24_NAME def camel_to_upper(value: str) -> str: + """ + Converts CamelCase to CAMEL_CASE. + + Examples:: + + ENUMName -> ENUM_NAME + EnumName1 -> ENUM_NAME1 + ENUM_NAME -> ENUM_NAME + ENUM_NAME1 -> ENUM_NAME1 + ENUM_Name2 -> ENUM_NAME2 + ENUM24_Name -> ENUM24_NAME + """ c_fun_str =3D c_name(value, False) if value.isupper(): return c_fun_str @@ -45,21 +55,33 @@ def camel_to_upper(value: str) -> str: def c_enum_const(type_name: str, const_name: str, prefix: Optional[str] =3D None) -> str: + """ + Generate a C enumeration constant name. + + :param type_name: The name of the enumeration. + :param const_name: The name of this constant. + :param prefix: Optional, prefix that overrides the type_name. + """ if prefix is not None: type_name =3D prefix return camel_to_upper(type_name) + '_' + c_name(const_name, False).upp= er() =20 =20 -# Map @name to a valid C identifier. -# If @protect, avoid returning certain ticklish identifiers (like -# C keywords) by prepending 'q_'. -# -# Used for converting 'name' from a 'name':'type' qapi definition -# into a generated struct member, as well as converting type names -# into substrings of a generated C function name. -# '__a.b_c' -> '__a_b_c', 'x-foo' -> 'x_foo' -# protect=3DTrue: 'int' -> 'q_int'; protect=3DFalse: 'int' -> 'int' def c_name(name: str, protect: bool =3D True) -> str: + """ + Map ``name`` to a valid C identifier. + + Used for converting 'name' from a 'name':'type' qapi definition + into a generated struct member, as well as converting type names + into substrings of a generated C function name. + + '__a.b_c' -> '__a_b_c', 'x-foo' -> 'x_foo' + protect=3DTrue: 'int' -> 'q_int'; protect=3DFalse: 'int' -> 'int' + + :param name: The name to map. + :param protect: If true, avoid returning certain ticklish identifiers + (like C keywords) by prepending ``q_``. + """ # ANSI X3J11/88-090, 3.1.1 c89_words =3D set(['auto', 'break', 'case', 'char', 'const', 'continue= ', 'default', 'do', 'double', 'else', 'enum', 'extern', @@ -129,12 +151,16 @@ def decrease(self, amount: int =3D 4) -> None: self._level -=3D amount =20 =20 +#: Global, current indent level for code generation. indent =3D Indentation() =20 =20 -# Generate @code with @kwds interpolated. -# Obey indent, and strip EATSPACE. def cgen(code: str, **kwds: object) -> str: + """ + Generate ``code`` with ``kwds`` interpolated. + + Obey `indent`, and strip `EATSPACE`. + """ raw =3D code % kwds if indent: raw =3D re.sub(r'^(?!(#|$))', str(indent), raw, flags=3Dre.MULTILI= NE) --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261266; cv=none; d=zohomail.com; s=zohoarc; b=Hk87xi32G0xwBmjWBIOABVrrMXWmcs+vJ01jo3ZqsyLUDVDRaiCs8QNz3riGbrOzrqPxzi5L6tDrtrBWkBI9WzUIHctyppFaDdUX6aqTbYLoVJ6fDrtN70VQVcdqVt3F0yrq79sx5op+xCfwlNgJvNGmNVrDBRJRBYQy11yP4OQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261266; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rWIbXdxRs3lE+1KS0JUCPqOLY9xCWHxaIGU8gRTTZLo=; b=efWZWHyzF3zI8yZXv95C2N2yEKASh/AMXiAuoTpTXksP+HqFD7RfWtqwfqa+zmtCX1DRI9kAy4SBRhpnMrFmEoBxzq/+X6eF9pt9bp4zW4W2wDsTQMooOfkmu57vXMBlK/I6GZNlpL5eBaRX+yQTlLNIqVHVWHsBqCQ5fmBTSIY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261266650790.05268173242; Fri, 9 Oct 2020 09:34:26 -0700 (PDT) Received: from localhost ([::1]:60074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvLd-0003US-Dv for importer@patchew.org; Fri, 09 Oct 2020 12:34:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34588) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4L-0004DU-AR for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58710) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4G-0003I3-OL for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-hWHlvYSJPe6bRMt9Bp5DSQ-1; Fri, 09 Oct 2020 12:16:24 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8103A18829E4; Fri, 9 Oct 2020 16:16:23 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D6AF1A92A; Fri, 9 Oct 2020 16:16:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260186; 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=rWIbXdxRs3lE+1KS0JUCPqOLY9xCWHxaIGU8gRTTZLo=; b=H7TO3reQihn3poAy+VGR9B1vxMOGaSKCVO6h3btETtzjhVmr2MYygOIav6wz31T43ZZgF7 5lxFf39yaFG7gxFtw5GSorR6jWDnhLxDqUIFuBraBAIt8xCnEeuf18YjS90fXz5cxPvZiI zMV2CcRCk/WPTIHFl6CoBrf8fz+261M= X-MC-Unique: hWHlvYSJPe6bRMt9Bp5DSQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 17/36] qapi/common.py: move build_params into gen.py Date: Fri, 9 Oct 2020 12:15:39 -0400 Message-Id: <20201009161558.107041-18-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Including it in common.py creates a circular import dependency; schema relies on common, but common.build_params requires a type annotation from schema. To type this properly, it needs to be moved outside the cycle. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 9 +++++++-- scripts/qapi/common.py | 23 ----------------------- scripts/qapi/events.py | 9 ++------- scripts/qapi/gen.py | 29 +++++++++++++++++++++++++++-- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index cde0c1e7770..88ba11c40e1 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -13,8 +13,13 @@ See the COPYING file in the top-level directory. """ =20 -from .common import build_params, c_name, mcgen -from .gen import QAPIGenCCode, QAPISchemaModularCVisitor, ifcontext +from .common import c_name, mcgen +from .gen import ( + QAPIGenCCode, + QAPISchemaModularCVisitor, + build_params, + ifcontext, +) =20 =20 def gen_command_decl(name, arg_type, boxed, ret_type): diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 669e3829b34..11b86beeabe 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -210,26 +210,3 @@ def gen_endif(ifcond: Sequence[str]) -> str: #endif /* %(cond)s */ ''', cond=3Difc) return ret - - -def build_params(arg_type, - boxed: bool, - extra: Optional[str] =3D None) -> str: - ret =3D '' - sep =3D '' - if boxed: - assert arg_type - ret +=3D '%s arg' % arg_type.c_param_type() - sep =3D ', ' - elif arg_type: - assert not arg_type.variants - for memb in arg_type.members: - ret +=3D sep - sep =3D ', ' - if memb.optional: - ret +=3D 'bool has_%s, ' % c_name(memb.name) - ret +=3D '%s %s' % (memb.type.c_param_type(), - c_name(memb.name)) - if extra: - ret +=3D sep + extra - return ret if ret else 'void' diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 6b3afa14d72..f840a62ed92 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,13 +12,8 @@ See the COPYING file in the top-level directory. """ =20 -from .common import ( - build_params, - c_enum_const, - c_name, - mcgen, -) -from .gen import QAPISchemaModularCVisitor, ifcontext +from .common import c_enum_const, c_name, mcgen +from .gen import QAPISchemaModularCVisitor, build_params, ifcontext from .schema import QAPISchemaEnumMember from .types import gen_enum, gen_enum_lookup =20 diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 1fed712b43b..fff0c0acb6d 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -2,7 +2,7 @@ # # QAPI code generation # -# Copyright (c) 2018-2019 Red Hat Inc. +# Copyright (c) 2015-2019 Red Hat Inc. # # Authors: # Markus Armbruster @@ -15,16 +15,18 @@ import errno import os import re +from typing import Optional =20 from .common import ( c_fname, + c_name, gen_endif, gen_if, guardend, guardstart, mcgen, ) -from .schema import QAPISchemaVisitor +from .schema import QAPISchemaObjectType, QAPISchemaVisitor =20 =20 class QAPIGen: @@ -90,6 +92,29 @@ def _wrap_ifcond(ifcond, before, after): return out =20 =20 +def build_params(arg_type: Optional[QAPISchemaObjectType], + boxed: bool, + extra: Optional[str] =3D None) -> str: + ret =3D '' + sep =3D '' + if boxed: + assert arg_type + ret +=3D '%s arg' % arg_type.c_param_type() + sep =3D ', ' + elif arg_type: + assert not arg_type.variants + for memb in arg_type.members: + ret +=3D sep + sep =3D ', ' + if memb.optional: + ret +=3D 'bool has_%s, ' % c_name(memb.name) + ret +=3D '%s %s' % (memb.type.c_param_type(), + c_name(memb.name)) + if extra: + ret +=3D sep + extra + return ret if ret else 'void' + + class QAPIGenCCode(QAPIGen): =20 def __init__(self, fname): --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260938; cv=none; d=zohomail.com; s=zohoarc; b=Jy1vHXZtsdOG5LgGoWgViK8ASEOFrEiw+3+/A1GPFRMT8uobz+2qOkgWS8GhHxC9ZWqxETkVrDbXT917NZNd/atTmF+bWTeweTZ/RnDq4NOSiS7WDv+QzaTNe/vwptKbkhflsEP6AbqTW4tw5gq6n3rwQ5QmWOUrMTauXCAFNfI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260938; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7Fn4rIHXn3Ht1c7QtZt675CfXyCqWkqF59QFD/ZJ1fw=; b=JpPuJ33agZ2KWwqFVEKHtMb0PUWdwstX/JVAGtaoTyU78T5DNBvdUBEatZDPHzIVCuFu0ilCryNAvsxxYzfKAZ+8r4f3XhzSOWrMhWvVdZXpq1HLyPyRHb7ydYO+hALPsuhIsEVr28qmfMIcuJr27+S3NhJa6tBlqO5ypiAaqQk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260938991699.3104830407693; Fri, 9 Oct 2020 09:28:58 -0700 (PDT) Received: from localhost ([::1]:39096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvGL-0002y8-01 for importer@patchew.org; Fri, 09 Oct 2020 12:28:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4M-0004FB-6L for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52091) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4G-0003I7-O1 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-337-bFpI92mBPmyIy1C6_AxBNw-1; Fri, 09 Oct 2020 12:16:26 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0D6B91074641; Fri, 9 Oct 2020 16:16:25 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id C43441A92D; Fri, 9 Oct 2020 16:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260187; 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=7Fn4rIHXn3Ht1c7QtZt675CfXyCqWkqF59QFD/ZJ1fw=; b=CHWW78L2yVRKyyERs3DEdWk8zBKZ0nolDJn79Ea+N4zgnjRNSGCkHlBslo4SMtaTdo470k JtQ++UMX6B7PqdUpigt0E+NAtUvATj0eVxVYoGyxkXF8HFD8yA83iLRJVGWc5q3Dc2WDY7 1oBa8KXY7JsZVjRTCRvyvzguLVv56BM= X-MC-Unique: bFpI92mBPmyIy1C6_AxBNw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 18/36] qapi: establish mypy type-checking baseline Date: Fri, 9 Oct 2020 12:15:40 -0400 Message-Id: <20201009161558.107041-19-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Fix a minor typing issue, and then establish a mypy type-checking baseline. Like pylint, this should be run from the folder above: > mypy --config-file=3Dqapi/mypy.ini qapi/ This is designed and tested for mypy 0.770 or greater. Signed-off-by: John Snow Tested-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/mypy.ini | 60 ++++++++++++++++++++++++++++++++++++++++++ scripts/qapi/schema.py | 3 ++- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 scripts/qapi/mypy.ini diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini new file mode 100644 index 00000000000..00fac15dc6e --- /dev/null +++ b/scripts/qapi/mypy.ini @@ -0,0 +1,60 @@ +[mypy] +strict =3D True +strict_optional =3D False +disallow_untyped_calls =3D False +python_version =3D 3.6 + +[mypy-qapi.commands] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False + +[mypy-qapi.error] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False + +[mypy-qapi.events] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False + +[mypy-qapi.expr] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False + +[mypy-qapi.gen] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False + +[mypy-qapi.introspect] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False + +[mypy-qapi.parser] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False + +[mypy-qapi.schema] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False + +[mypy-qapi.source] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False + +[mypy-qapi.types] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False + +[mypy-qapi.visit] +disallow_untyped_defs =3D False +disallow_incomplete_defs =3D False +check_untyped_defs =3D False diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 7c015929569..720449feee4 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -17,6 +17,7 @@ from collections import OrderedDict import os import re +from typing import Optional =20 from .common import POINTER_SUFFIX, c_name from .error import QAPIError, QAPISemError @@ -25,7 +26,7 @@ =20 =20 class QAPISchemaEntity: - meta =3D None + meta: Optional[str] =3D None =20 def __init__(self, name, info, doc, ifcond=3DNone, features=3DNone): assert name is None or isinstance(name, str) --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261424; cv=none; d=zohomail.com; s=zohoarc; b=FUnpnmaC3WY5PYsy9YJy4UpzlB3y8aCZuXEdA949JPhbMHxhAU0gv93L2ZjCYrX/kCXYZouFGyKTImqSAPoiFNTrYn2z+Kiqf125r8/gcjF5pE3dv1oVi7ZmX5OfUm/1WqlL9+k1/pbrHO+Yu8y2yBvKQ4doCUUUlHGqO3FKj24= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261424; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=G+Kn6XtqHpHEa9JJiSv1EfA7CSF/2+1s5W2elp6o67g=; b=BsniDfTV6swfwAI24xLyRfomPuMfG/Rx6UdQQVZEycjYL4yx9Bx/dbmrginPXaHJf8cE1bzTliJNepgMElJ7/FM2IvkU23UQIcm6hRElCpfpF+FT2Q0fEprCNhWjZWvOAINLbq0thWUmYVv/BhCBJ1Rsw1WxQh7fzl6zShMLS2U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261424837358.04093212247585; Fri, 9 Oct 2020 09:37:04 -0700 (PDT) Received: from localhost ([::1]:40372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvOB-00072Z-K3 for importer@patchew.org; Fri, 09 Oct 2020 12:37:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4O-0004IG-1I for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33788) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4J-0003Ip-Cw for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-450-1f_BlYVOOu-cAQjNryK0ug-1; Fri, 09 Oct 2020 12:16:27 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 051CA1006701; Fri, 9 Oct 2020 16:16:26 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 427AC19936; Fri, 9 Oct 2020 16:16:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260190; 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=G+Kn6XtqHpHEa9JJiSv1EfA7CSF/2+1s5W2elp6o67g=; b=YVOj+5tIJUxWtLHBXCr4Fiz49JKRtSgY1IKfu9Vpst4zFzckOUswoMB60SLtJT+OqY2M5l y8yyI4C6gdhZ5GW40KwGoXeCPLMkwAY4iLoqzzSxysFalLY31S898ui4DiEipQhm4qTTgI VzgR6O+dwqq57/HyrxcZoK6YCfeIv+k= X-MC-Unique: 1f_BlYVOOu-cAQjNryK0ug-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 19/36] qapi/events.py: add type hint annotations Date: Fri, 9 Oct 2020 12:15:41 -0400 Message-Id: <20201009161558.107041-20-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Note: __init__ does not need its return type annotated, as it is special. https://mypy.readthedocs.io/en/stable/class_basics.html#annotating-init-met= hods Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/events.py | 46 ++++++++++++++++++++++++++++++++---------- scripts/qapi/mypy.ini | 5 ----- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index f840a62ed92..57e0939e963 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,19 +12,31 @@ See the COPYING file in the top-level directory. """ =20 +from typing import List + from .common import c_enum_const, c_name, mcgen from .gen import QAPISchemaModularCVisitor, build_params, ifcontext -from .schema import QAPISchemaEnumMember +from .schema import ( + QAPISchema, + QAPISchemaEnumMember, + QAPISchemaFeature, + QAPISchemaObjectType, +) +from .source import QAPISourceInfo from .types import gen_enum, gen_enum_lookup =20 =20 -def build_event_send_proto(name, arg_type, boxed): +def build_event_send_proto(name: str, + arg_type: QAPISchemaObjectType, + boxed: bool) -> str: return 'void qapi_event_send_%(c_name)s(%(param)s)' % { 'c_name': c_name(name.lower()), 'param': build_params(arg_type, boxed)} =20 =20 -def gen_event_send_decl(name, arg_type, boxed): +def gen_event_send_decl(name: str, + arg_type: QAPISchemaObjectType, + boxed: bool) -> str: return mcgen(''' =20 %(proto)s; @@ -33,7 +45,7 @@ def gen_event_send_decl(name, arg_type, boxed): =20 =20 # Declare and initialize an object 'qapi' using parameters from build_para= ms() -def gen_param_var(typ): +def gen_param_var(typ: QAPISchemaObjectType) -> str: assert not typ.variants ret =3D mcgen(''' %(c_name)s param =3D { @@ -61,7 +73,11 @@ def gen_param_var(typ): return ret =20 =20 -def gen_event_send(name, arg_type, boxed, event_enum_name, event_emit): +def gen_event_send(name: str, + arg_type: QAPISchemaObjectType, + boxed: bool, + event_enum_name: str, + event_emit: str) -> str: # FIXME: Our declaration of local variables (and of 'errp' in the # parameter list) can collide with exploded members of the event's # data type passed in as parameters. If this collision ever hits in @@ -137,15 +153,15 @@ def gen_event_send(name, arg_type, boxed, event_enum_= name, event_emit): =20 class QAPISchemaGenEventVisitor(QAPISchemaModularCVisitor): =20 - def __init__(self, prefix): + def __init__(self, prefix: str): super().__init__( prefix, 'qapi-events', ' * Schema-defined QAPI/QMP events', None, __doc__) self._event_enum_name =3D c_name(prefix + 'QAPIEvent', protect=3DF= alse) - self._event_enum_members =3D [] + self._event_enum_members: List[QAPISchemaEnumMember] =3D [] self._event_emit_name =3D c_name(prefix + 'qapi_event_emit') =20 - def _begin_user_module(self, name): + def _begin_user_module(self, name: str) -> None: events =3D self._module_basename('qapi-events', name) types =3D self._module_basename('qapi-types', name) visit =3D self._module_basename('qapi-visit', name) @@ -168,7 +184,7 @@ def _begin_user_module(self, name): ''', types=3Dtypes)) =20 - def visit_end(self): + def visit_end(self) -> None: self._add_system_module('emit', ' * QAPI Events emission') self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" @@ -189,7 +205,13 @@ def visit_end(self): event_emit=3Dself._event_emit_name, event_enum=3Dself._event_enum_name)) =20 - def visit_event(self, name, info, ifcond, features, arg_type, boxed): + def visit_event(self, + name: str, + info: QAPISourceInfo, + ifcond: List[str], + features: List[QAPISchemaFeature], + arg_type: QAPISchemaObjectType, + boxed: bool) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_event_send_decl(name, arg_type, boxed)) self._genc.add(gen_event_send(name, arg_type, boxed, @@ -200,7 +222,9 @@ def visit_event(self, name, info, ifcond, features, arg= _type, boxed): self._event_enum_members.append(QAPISchemaEnumMember(name, None)) =20 =20 -def gen_events(schema, output_dir, prefix): +def gen_events(schema: QAPISchema, + output_dir: str, + prefix: str) -> None: vis =3D QAPISchemaGenEventVisitor(prefix) schema.visit(vis) vis.write(output_dir) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 00fac15dc6e..5df11e53fd1 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -14,11 +14,6 @@ disallow_untyped_defs =3D False disallow_incomplete_defs =3D False check_untyped_defs =3D False =20 -[mypy-qapi.events] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False - [mypy-qapi.expr] disallow_untyped_defs =3D False disallow_incomplete_defs =3D False --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261067; cv=none; d=zohomail.com; s=zohoarc; b=W/Opcdd0oARyUtgTGEDbPDMK1jtzMR96X+EKb4GyDdDSHjpdbhfmWdzikXW8A6iwHLIwkKL5R5T9Wkhu2pLkFpCNZ0jXZz5lu+GHLyGi2G5P+1FANB3/WBIXKoMZUH09y+X61rJT8pc9u21KZM2STl6pOP8AqjhQCHJMQpRj//Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261067; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QpcPc0JJZjUHkmAfzfFumJ9LBKbWFBiymq5dslj7rHA=; b=JtN/MoOy3JYnuLlU0opjv9p4uzlT4++Y8fYQNLQnqhAfyfM/sq5r97RS1TJitdkdcpUO6Kazuiah1MSq0r8PVbAwr5TbPOw3bWyvm8uZc1gbRzWB0Obq7pbvM87GxwVhGkd0/V6qDEzxkJLIKUBWp7qpAcvtRkn0e0AGMKcgYMk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16022610673694.4593304942205805; Fri, 9 Oct 2020 09:31:07 -0700 (PDT) Received: from localhost ([::1]:47408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvIP-0006dL-Qy for importer@patchew.org; Fri, 09 Oct 2020 12:31:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4M-0004Fd-Db for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46877) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4I-0003IX-Fg for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:34 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-102-B_3sh4JkPw-kNMvRc2LQTA-1; Fri, 09 Oct 2020 12:16:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2C451007283; Fri, 9 Oct 2020 16:16:26 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CDF419936; Fri, 9 Oct 2020 16:16:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260189; 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=QpcPc0JJZjUHkmAfzfFumJ9LBKbWFBiymq5dslj7rHA=; b=fSd4078Sz0OyfI5bdNeCh2kiLZ8CWOtnriszBP99nbdr3p527MuST8Iym93Ec2P9+yAD1Y ubTMAnH+2YaHWUup2PzKdbmvqq/U4mBar3ZyjOXgsC+S1e8XQmnPoR9jqQCvZ5absBFZ2x jrYsqfrjxITMJHdoGZ547HUvAk8l5VI= X-MC-Unique: B_3sh4JkPw-kNMvRc2LQTA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 20/36] qapi/events.py: Move comments into docstrings Date: Fri, 9 Oct 2020 12:15:42 -0400 Message-Id: <20201009161558.107041-21-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Clarify them while we're here. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/events.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 57e0939e963..599f3d1f564 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -44,8 +44,12 @@ def gen_event_send_decl(name: str, proto=3Dbuild_event_send_proto(name, arg_type, boxed)) =20 =20 -# Declare and initialize an object 'qapi' using parameters from build_para= ms() def gen_param_var(typ: QAPISchemaObjectType) -> str: + """ + Generate a struct variable holding the event parameters. + + Initialize it with the function arguments defined in `gen_event_send`. + """ assert not typ.variants ret =3D mcgen(''' %(c_name)s param =3D { --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261898; cv=none; d=zohomail.com; s=zohoarc; b=M1SOJdinnGHIYEyHCwfKUW24ApwvXnvobhcDp+jQ9b1WY5Db0rcDJR/mbpOo5PdWy89gB47q6od5XtUuC7vOaFFsl3aqjHzaLUR4cvzLYKvv8zvV2XEPljrW7zArKzxYz9kYByQlu/jhhX/bMpdnU1XEqW1u+3OCXG+N6ge0xnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261898; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZSXFkRwHbPunRSzU+vUPOn8b7MbTz73+W8h9ko6/cig=; b=IdnGq5BcJ9NkHf8/6Vx552J1fGg2DRPpKo0XmhvP/iqooSreOWuVXWx3QrflbsdbHbDLfHqKBKajJtE2pwaKEXpLjRSTNSUVX+665IfbfY2kR0qgf54Zf8SoJnLhlx4DXaZK+11vNIbkB2TGRz9C1oS2YP23dIbQjYfI0lbjNIk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261898187926.2381597646068; Fri, 9 Oct 2020 09:44:58 -0700 (PDT) Received: from localhost ([::1]:37908 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvVm-00011D-UR for importer@patchew.org; Fri, 09 Oct 2020 12:44:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4O-0004Iv-AB for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40498) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4J-0003Ir-DS for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-545-f-fUpstTNae7kL9o2vKnKQ-1; Fri, 09 Oct 2020 12:16:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CB34364084; Fri, 9 Oct 2020 16:16:27 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 176982547D; Fri, 9 Oct 2020 16:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260190; 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=ZSXFkRwHbPunRSzU+vUPOn8b7MbTz73+W8h9ko6/cig=; b=CNXegZT+bNpzHQuQfQKi1PzqtTnhG3LmE8eftq5pdkwLI+h/6+Ssim+FmD7HK/gSP0LzRF HexWeKsiOuuvp1giQCQTrPUVdx9uFGYwoQRzc7e7wQdhQlFCFMn3Fbr8ziJNsHNnH45xNZ Ty8XJx1X6nRd0hWEA0rwbK+Q4l+jF5k= X-MC-Unique: f-fUpstTNae7kL9o2vKnKQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 21/36] qapi/commands.py: Don't re-bind to variable of different type Date: Fri, 9 Oct 2020 12:15:43 -0400 Message-Id: <20201009161558.107041-22-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Mypy isn't a fan of rebinding a variable with a new data type. It's easy enough to avoid. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 88ba11c40e1..b0abb985a4e 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -198,14 +198,12 @@ def gen_register_command(name, success_response, allo= w_oob, allow_preconfig, if not options: options =3D ['QCO_NO_OPTIONS'] =20 - options =3D " | ".join(options) - ret =3D mcgen(''' qmp_register_command(cmds, "%(name)s", qmp_marshal_%(c_name)s, %(opts)s); ''', name=3Dname, c_name=3Dc_name(name), - opts=3Doptions) + opts=3D" | ".join(options)) return ret =20 =20 --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602262083; cv=none; d=zohomail.com; s=zohoarc; b=ZTyItN4IGDWKNsjTgCC0Vj/TJCFXmfNi0uuCKAvY7SPtu890gQdxXgRZFmuonKHG/E/jsv6G0iu/mnfgWbeKZ1B1vfXYY7/v7d9fhEADTei7FgE7SoQIExENZ7CAtl7tWiRE6hxTJw03vl8mWhWgyimBb0+MLyxI9xdOuMgNUcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602262083; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8y5IqwoqPzympNicAEaK/dgPwhWEMXb+t9nQEo8TQcc=; b=hZth2g5l+fEeDgsH3gDJOveSXRhL7pmUQwAw84tFstXI5LEgRteu3WHEKd78KJgbl3TPhYhdW3JyUHtSM6E5ljErUBFmtiFzVl0VlKSTvrDEgMw7KkVzsXV0HDkrZCv9KCBDXzaDzFc8Wqdcxpw/LlLkLlutZi+kWQL9DWuJR0Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602262083313676.9123478701035; Fri, 9 Oct 2020 09:48:03 -0700 (PDT) Received: from localhost ([::1]:45934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvYn-0004Nb-VQ for importer@patchew.org; Fri, 09 Oct 2020 12:48:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34716) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4P-0004Kb-8z for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:51910) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4L-0003Ja-Fo for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:36 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-564-U1FjIQ8vOo6MAUDcLKhMTg-1; Fri, 09 Oct 2020 12:16:29 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7EED107464D; Fri, 9 Oct 2020 16:16:28 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1B7019936; Fri, 9 Oct 2020 16:16:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260192; 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=8y5IqwoqPzympNicAEaK/dgPwhWEMXb+t9nQEo8TQcc=; b=RdV6SqzPSZAAQ3nOemjkuCKZ91Tdwbq5LrvH+z0RYu4g+7vyU0DR8EBQ5UxqtHSbzSUyuC 25MtuvjjoMhB/TZBIz5I9Ij0lUnFVld99jzOjB8laNiGXKokUetq07kodg2rvP1cGeflNQ RK8oh1POzWsZ0/3ytyWMdUU7hslPaW8= X-MC-Unique: U1FjIQ8vOo6MAUDcLKhMTg-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 22/36] qapi/commands.py: add type hint annotations Date: Fri, 9 Oct 2020 12:15:44 -0400 Message-Id: <20201009161558.107041-23-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/commands.py | 74 ++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 18 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index b0abb985a4e..50978090b44 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -13,16 +13,34 @@ See the COPYING file in the top-level directory. """ =20 +from typing import ( + Dict, + List, + Optional, + Set, +) + from .common import c_name, mcgen from .gen import ( + QAPIGenC, QAPIGenCCode, QAPISchemaModularCVisitor, build_params, ifcontext, ) +from .schema import ( + QAPISchema, + QAPISchemaFeature, + QAPISchemaObjectType, + QAPISchemaType, +) +from .source import QAPISourceInfo =20 =20 -def gen_command_decl(name, arg_type, boxed, ret_type): +def gen_command_decl(name: str, + arg_type: Optional[QAPISchemaObjectType], + boxed: bool, + ret_type: Optional[QAPISchemaType]) -> str: return mcgen(''' %(c_type)s qmp_%(c_name)s(%(params)s); ''', @@ -31,7 +49,10 @@ def gen_command_decl(name, arg_type, boxed, ret_type): params=3Dbuild_params(arg_type, boxed, 'Error **errp')) =20 =20 -def gen_call(name, arg_type, boxed, ret_type): +def gen_call(name: str, + arg_type: Optional[QAPISchemaObjectType], + boxed: bool, + ret_type: Optional[QAPISchemaType]) -> str: ret =3D '' =20 argstr =3D '' @@ -67,7 +88,7 @@ def gen_call(name, arg_type, boxed, ret_type): return ret =20 =20 -def gen_marshal_output(ret_type): +def gen_marshal_output(ret_type: QAPISchemaType) -> str: return mcgen(''' =20 static void qmp_marshal_output_%(c_name)s(%(c_type)s ret_in, @@ -88,19 +109,22 @@ def gen_marshal_output(ret_type): c_type=3Dret_type.c_type(), c_name=3Dret_type.c_name()) =20 =20 -def build_marshal_proto(name): +def build_marshal_proto(name: str) -> str: return ('void qmp_marshal_%s(QDict *args, QObject **ret, Error **errp)' % c_name(name)) =20 =20 -def gen_marshal_decl(name): +def gen_marshal_decl(name: str) -> str: return mcgen(''' %(proto)s; ''', proto=3Dbuild_marshal_proto(name)) =20 =20 -def gen_marshal(name, arg_type, boxed, ret_type): +def gen_marshal(name: str, + arg_type: Optional[QAPISchemaObjectType], + boxed: bool, + ret_type: Optional[QAPISchemaType]) -> str: have_args =3D boxed or (arg_type and not arg_type.is_empty()) =20 ret =3D mcgen(''' @@ -182,8 +206,11 @@ def gen_marshal(name, arg_type, boxed, ret_type): return ret =20 =20 -def gen_register_command(name, success_response, allow_oob, allow_preconfi= g, - coroutine): +def gen_register_command(name: str, + success_response: bool, + allow_oob: bool, + allow_preconfig: bool, + coroutine: bool) -> str: options =3D [] =20 if not success_response: @@ -207,7 +234,7 @@ def gen_register_command(name, success_response, allow_= oob, allow_preconfig, return ret =20 =20 -def gen_registry(registry, prefix): +def gen_registry(registry: str, prefix: str) -> str: ret =3D mcgen(''' =20 void %(c_prefix)sqmp_init_marshal(QmpCommandList *cmds) @@ -224,15 +251,14 @@ def gen_registry(registry, prefix): =20 =20 class QAPISchemaGenCommandVisitor(QAPISchemaModularCVisitor): - - def __init__(self, prefix): + def __init__(self, prefix: str): super().__init__( prefix, 'qapi-commands', ' * Schema-defined QAPI/QMP commands', None, __doc__) self._regy =3D QAPIGenCCode(None) - self._visited_ret_types =3D {} + self._visited_ret_types: Dict[QAPIGenC, Set[QAPISchemaType]] =3D {} =20 - def _begin_user_module(self, name): + def _begin_user_module(self, name: str) -> None: self._visited_ret_types[self._genc] =3D set() commands =3D self._module_basename('qapi-commands', name) types =3D self._module_basename('qapi-types', name) @@ -256,7 +282,7 @@ def _begin_user_module(self, name): ''', types=3Dtypes)) =20 - def visit_end(self): + def visit_end(self) -> None: self._add_system_module('init', ' * QAPI Commands initialization') self._genh.add(mcgen(''' #include "qapi/qmp/dispatch.h" @@ -272,9 +298,19 @@ def visit_end(self): prefix=3Dself._prefix)) self._genc.add(gen_registry(self._regy.get_content(), self._prefix= )) =20 - def visit_command(self, name, info, ifcond, features, - arg_type, ret_type, gen, success_response, boxed, - allow_oob, allow_preconfig, coroutine): + def visit_command(self, + name: str, + info: QAPISourceInfo, + ifcond: List[str], + features: List[QAPISchemaFeature], + arg_type: Optional[QAPISchemaObjectType], + ret_type: Optional[QAPISchemaType], + gen: bool, + success_response: bool, + boxed: bool, + allow_oob: bool, + allow_preconfig: bool, + coroutine: bool) -> None: if not gen: return # FIXME: If T is a user-defined type, the user is responsible @@ -296,7 +332,9 @@ def visit_command(self, name, info, ifcond, features, coroutine)) =20 =20 -def gen_commands(schema, output_dir, prefix): +def gen_commands(schema: QAPISchema, + output_dir: str, + prefix: str) -> None: vis =3D QAPISchemaGenCommandVisitor(prefix) schema.visit(vis) vis.write(output_dir) --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602260982; cv=none; d=zohomail.com; s=zohoarc; b=aorqyYXIaIgpvUjl99Sgh6VLGb3oLa0XoJ3QSn3Qf6bY+iIieo1aL05Avy+wvXMrImuMuI4dqzm20vrU4F6CXlfLvMxKdZDhDchOjTNrJ94DWkORAj1vD74t97PmyBYwCkFxJAzYYJSJexrpj1SOSrfBNd3EMK1NWLc3xPxDm0k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602260982; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iLzIE3YsbPKP9FDVkEtcrn2UpHf4H0cbAdScAbS77Ko=; b=SrESjSs3GauloKjgkpUkIqMFjAxA23+xiwvroeisjs0et5PHagjVvijHCpCAliwjVnHO1di5yCQGqCaX+UWYUoQa5JcaWg8d1qVIbLJJzbPv238Yiob3DKhJsjSKTRZAKMbYPwpGhiS3A4k+a9Dor3JcjM6BCEzYbHHWM2qkUGY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602260982412356.72522385859577; Fri, 9 Oct 2020 09:29:42 -0700 (PDT) Received: from localhost ([::1]:41428 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvH3-000418-31 for importer@patchew.org; Fri, 09 Oct 2020 12:29:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34666) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4N-0004HW-N6 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36222) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4L-0003Jx-RX for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-577-B0Lvz9bGMPuMTgX8t3bQKw-1; Fri, 09 Oct 2020 12:16:30 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D90F1074657; Fri, 9 Oct 2020 16:16:29 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF9B51A925; Fri, 9 Oct 2020 16:16:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260193; 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=iLzIE3YsbPKP9FDVkEtcrn2UpHf4H0cbAdScAbS77Ko=; b=MVK6vNK8xaWyc2eIrdAnaRSl9fm8Lxr3IwrypYlsT34PoLqqGZ0XSz4CkjidDaocfJInze HYW2tZfSZSHl8gDmTMxdnIAdRQ5YSoyDSmYz5keTlIS43L0mPHzB5cZ733w0sZDGi0v/ba hNULiwQSZ80MJfyPCogxLTvEEgNWERg= X-MC-Unique: B0Lvz9bGMPuMTgX8t3bQKw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 23/36] qapi/commands.py: enable checking with mypy Date: Fri, 9 Oct 2020 12:15:45 -0400 Message-Id: <20201009161558.107041-24-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/mypy.ini | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 5df11e53fd1..8ab9ac52cc4 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -4,11 +4,6 @@ strict_optional =3D False disallow_untyped_calls =3D False python_version =3D 3.6 =20 -[mypy-qapi.commands] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False - [mypy-qapi.error] disallow_untyped_defs =3D False disallow_incomplete_defs =3D False --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261116; cv=none; d=zohomail.com; s=zohoarc; b=WXW1ipuNHSi6NV1PK283hApJithWR+r28uSIRDnYV+F52V0fC6798S6lYui501Cy/L7mtcHY0LkKrR3h8fZUZUycPsNLP4vnWBDOQ6LuGHtOOC2jAMweSyqPFDxfkh/W3aonSMAMr5HSUu3oes7lnIOVYTv0/VeccY2HXdxCGFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261116; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UJq+HLT6QYFG43guFEY7AAqwPzkZedXznbKiUUzhshA=; b=cZFKuPTLmHjRdJxRTQ6sm6OiOQCS/OENWpTl1qSU8cvj+3jCvRTgUlmNv7HqN+SiEKb3/x5YUu/f26+uxUzchSfYKwjQQnAQx0POFjKs/OQV+wYDv13a39ahpz1Ez0OWLYthDD0KH0uwqmubZ5b+lVn1vRw9Qjm1V1t9WukHpo0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261116993766.4371985690237; Fri, 9 Oct 2020 09:31:56 -0700 (PDT) Received: from localhost ([::1]:49814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvJC-0007gR-KC for importer@patchew.org; Fri, 09 Oct 2020 12:31:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4O-0004JN-Ih for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25923) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4M-0003K6-4a for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:36 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-595-olqv-7gDN0KvKlBTp9hzRA-1; Fri, 09 Oct 2020 12:16:31 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84CF280B713; Fri, 9 Oct 2020 16:16:30 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id C424219936; Fri, 9 Oct 2020 16:16:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260193; 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=UJq+HLT6QYFG43guFEY7AAqwPzkZedXznbKiUUzhshA=; b=PEz6FfcyHt4WBx4fqfgl8BxwNpPj3oEIZorELBTHcIIX2H4q28HgQADqjF4o3BOPSqYKdR IkMW+AE8Jm6KZAtYKrJfQtdVaL39STkNb+BGE3wnOLpxyjj0uFkbwwU9MDvR3mF1MHju91 I0HPcfwG4wI87ms/h9KW3MBRZDc35w8= X-MC-Unique: olqv-7gDN0KvKlBTp9hzRA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 24/36] qapi/source.py: add type hint annotations Date: Fri, 9 Oct 2020 12:15:46 -0400 Message-Id: <20201009161558.107041-25-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. A note on typing of __init__: mypy requires init functions with no parameters to document a return type of None to be considered fully typed. In the case when there are input parameters, None may be omitted. Since __init__ may never return any value, it is preferred to omit the return annotation whenever possible. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/mypy.ini | 5 ----- scripts/qapi/source.py | 32 +++++++++++++++++++------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 8ab9ac52cc4..1b8555dfa39 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -34,11 +34,6 @@ disallow_untyped_defs =3D False disallow_incomplete_defs =3D False check_untyped_defs =3D False =20 -[mypy-qapi.source] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False - [mypy-qapi.types] disallow_untyped_defs =3D False disallow_incomplete_defs =3D False diff --git a/scripts/qapi/source.py b/scripts/qapi/source.py index e97b9a8e15e..27af5295a85 100644 --- a/scripts/qapi/source.py +++ b/scripts/qapi/source.py @@ -11,37 +11,43 @@ =20 import copy import sys +from typing import List, Optional, TypeVar =20 =20 class QAPISchemaPragma: - def __init__(self): + def __init__(self) -> None: # Are documentation comments required? self.doc_required =3D False # Whitelist of commands allowed to return a non-dictionary - self.returns_whitelist =3D [] + self.returns_whitelist: List[str] =3D [] # Whitelist of entities allowed to violate case conventions - self.name_case_whitelist =3D [] + self.name_case_whitelist: List[str] =3D [] =20 =20 class QAPISourceInfo: - def __init__(self, fname, line, parent): + T =3D TypeVar('T', bound=3D'QAPISourceInfo') + + def __init__(self, fname: str, line: int, + parent: Optional['QAPISourceInfo']): self.fname =3D fname self.line =3D line self.parent =3D parent - self.pragma =3D parent.pragma if parent else QAPISchemaPragma() - self.defn_meta =3D None - self.defn_name =3D None + self.pragma: QAPISchemaPragma =3D ( + parent.pragma if parent else QAPISchemaPragma() + ) + self.defn_meta: Optional[str] =3D None + self.defn_name: Optional[str] =3D None =20 - def set_defn(self, meta, name): + def set_defn(self, meta: str, name: str) -> None: self.defn_meta =3D meta self.defn_name =3D name =20 - def next_line(self): + def next_line(self: T) -> T: info =3D copy.copy(self) info.line +=3D 1 return info =20 - def loc(self): + def loc(self) -> str: if self.fname is None: return sys.argv[0] ret =3D self.fname @@ -49,13 +55,13 @@ def loc(self): ret +=3D ':%d' % self.line return ret =20 - def in_defn(self): + def in_defn(self) -> str: if self.defn_name: return "%s: In %s '%s':\n" % (self.fname, self.defn_meta, self.defn_name) return '' =20 - def include_path(self): + def include_path(self) -> str: ret =3D '' parent =3D self.parent while parent: @@ -63,5 +69,5 @@ def include_path(self): parent =3D parent.parent return ret =20 - def __str__(self): + def __str__(self) -> str: return self.include_path() + self.in_defn() + self.loc() --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261750; cv=none; d=zohomail.com; s=zohoarc; b=YrAUHmhGY98ZyI1N+lRHYEv5ge2bYa2K3yQViY/elBbAMqpE2Wr+I0tNNbdrmPRj3B19PkgCfy7YobAOQPwZfSA9wfH+qqmUjroz8tzC1I1Olpz7pWN5/NyGDJahZJKFRovTF8COii+P2nqHKVzrmGmbaqMlSCga9irA6AJd2tw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261750; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ls855QKTFsJMuAE7yS3Rpb+00OSVPlAGFSZZEVl1vs8=; b=e8aGTxEHh0V6kiUTVzMOrCH/lauFNVTtY3l9p6loK4Acj2IEu3MZ5zlg4nZa86tdJpbV2eU+hHIZTCJnPjpT0jaUccqIehZDkVMvBYi6S28JKxu2D7XKNOu0KKeWai1+hRqFw77TTe2Gv7NzYI+sIFzRw8lw5eOLK7N4s8ELCcc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261750506766.1207979613787; Fri, 9 Oct 2020 09:42:30 -0700 (PDT) Received: from localhost ([::1]:56948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvTR-0005jv-5M for importer@patchew.org; Fri, 09 Oct 2020 12:42:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4P-0004M3-St for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26878) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4N-0003Kf-UU for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-89-5hYN68TIMb6YO_y_BOajgQ-1; Fri, 09 Oct 2020 12:16:32 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F05C64082; Fri, 9 Oct 2020 16:16:31 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC0521A925; Fri, 9 Oct 2020 16:16:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260195; 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=ls855QKTFsJMuAE7yS3Rpb+00OSVPlAGFSZZEVl1vs8=; b=Faxv3I2VusIiDkhiOBn5KApH3QqYdByDBOsPa09Wprc0rNnBigIMs1DsxLZ3ZVp5Zq8nJo 3pfWtkRRximdjqI8LG/1OttVtUeo9vDKX2ooiXtEDGsi8mNX9JxBveQ9OJUbT3o14h2CQG WDQkCcjgaXry/tLuExdDsCY68KSFjHc= X-MC-Unique: 5hYN68TIMb6YO_y_BOajgQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 25/36] qapi/source.py: delint with pylint Date: Fri, 9 Oct 2020 12:15:47 -0400 Message-Id: <20201009161558.107041-26-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Shush an error and leave a hint for future cleanups when we're allowed to use Python 3.7+. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/pylintrc | 1 - scripts/qapi/source.py | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index 507f15537ab..d840b150313 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -7,7 +7,6 @@ ignore-patterns=3Derror.py, gen.py, parser.py, schema.py, - source.py, types.py, visit.py, =20 diff --git a/scripts/qapi/source.py b/scripts/qapi/source.py index 27af5295a85..d7a79a9b8ae 100644 --- a/scripts/qapi/source.py +++ b/scripts/qapi/source.py @@ -15,6 +15,9 @@ =20 =20 class QAPISchemaPragma: + # Replace with @dataclass in Python 3.7+ + # pylint: disable=3Dtoo-few-public-methods + def __init__(self) -> None: # Are documentation comments required? self.doc_required =3D False --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261603; cv=none; d=zohomail.com; s=zohoarc; b=Z2X3DzKayuM/4U/3rqvOyZUp5TlWCsGm03RlfskyP1G57uOKAgB/QPn5zUArpT7j0k+X0ImTz4XeRc7QFgbwC3++B3+xEx8BzKSL+tDrQ2xUfOwOHAI+oj1Wo0CcquJkVjqWqG0FI0si7NX5OwQ/Jiouf+2YHuyQfSOqhuUoB3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261603; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=n3N4mPMHgUZTr8lAXsgIb6MRzPVaBP0Td8bTolrv8EU=; b=apm+trvCuxA4xd0hwIvh2CPN9wKFiPBd3r6QdnFYKBRbtGujKfMjYrv2fV1lGEc8CFkxuzVVzOkkyQ72aye0O1fW48bdaY4lnPzXvsk8cwtQTWihABBK8CBEw078IeRJb7e7X3rp7BhsqMW7FCTNhshaVeZnoer+VwdliWC+crk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261603354175.23415824532935; Fri, 9 Oct 2020 09:40:03 -0700 (PDT) Received: from localhost ([::1]:48664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvR3-0002Al-2G for importer@patchew.org; Fri, 09 Oct 2020 12:40:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34730) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4Q-0004Ma-29 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35700) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4O-0003Kd-7K for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-478-NMlJbmitPp-tvIcSjKhqCw-1; Fri, 09 Oct 2020 12:16:33 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6977318829D5; Fri, 9 Oct 2020 16:16:32 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9645F19936; Fri, 9 Oct 2020 16:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260195; 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=n3N4mPMHgUZTr8lAXsgIb6MRzPVaBP0Td8bTolrv8EU=; b=fzU2CS0BkClitKG4KCJkiwO5fTzy8qecjHNEcqU2HgFYAlZfj2NhRD2qe7lvIcO22mW2/A HM4L8+VKY0PIERehyvrMW+GXbUG26nBif9DCBaq3ZADAa1tlm0L9Ck6+zTGcFqVrC5gPdV G8ZwwN7FCJ7zycUbNx7B97HkRSUvXl4= X-MC-Unique: NMlJbmitPp-tvIcSjKhqCw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 26/36] qapi/gen.py: Fix edge-case of _is_user_module Date: Fri, 9 Oct 2020 12:15:48 -0400 Message-Id: <20201009161558.107041-27-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , John Snow , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) The edge case is that if the name is '', this expression returns a string instead of a bool, which violates our declared type. In practice, module names are not allowed to be the empty string, but this constraint is not modeled for the type system. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index fff0c0acb6d..2c305c4f82c 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -241,7 +241,7 @@ def __init__(self, prefix, what, user_blurb, builtin_bl= urb, pydoc): =20 @staticmethod def _is_user_module(name): - return name and not name.startswith('./') + return bool(name and not name.startswith('./')) =20 @staticmethod def _is_builtin_module(name): --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261222; cv=none; d=zohomail.com; s=zohoarc; b=eFre/AUUAFjusXGOyJIgzwYukzM2GOVRPeFgXIGlTO6mBFk50gkhIxzbwg96zleGfY5I72YRdeDZtH0oQLuN7IPVWB3YLeK99ycigBeLQ9HWImaYetVO3ar4EVeSg15gNv3XpX7FNIlzuzjcTRQmPJcL/siTja/8YU1rbXEj9Uw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261222; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IsDKDkgExvu7y3hn9COPAwhXOGkQ3b8Eei+wplqK5i8=; b=LOd5t99Dfc/6z/sXQoWHUCWTptQweBGYoVcxonfC/HKIxpRSrFbYAY3M5XErAKpqkl13xm5Bpr58Raje0LA6FjUI+ZArg3m+gWk3aCnaK/B8tNU8RBNcoWVhsVWPONFP2/p5xOBbsZ4Z0zjfGUkKUjixJCKHZcS/pbO7aWo4jl4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261222586474.2926993720289; Fri, 9 Oct 2020 09:33:42 -0700 (PDT) Received: from localhost ([::1]:55876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvKv-0001o0-7t for importer@patchew.org; Fri, 09 Oct 2020 12:33:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4W-0004O2-ON for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22947) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4O-0003LB-Sb for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-587-iB7XsAPMMP2jyc9C3hMNWA-1; Fri, 09 Oct 2020 12:16:34 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57673100746C; Fri, 9 Oct 2020 16:16:33 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9444E19936; Fri, 9 Oct 2020 16:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260196; 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=IsDKDkgExvu7y3hn9COPAwhXOGkQ3b8Eei+wplqK5i8=; b=MQWWHToOdnjLPLrlvAS4tSiz9f9leEBOlbcBSXKJ1mYKvCB50FDwgUAgbX4bdmtSbDlQfQ z7Y+o6mSfEi2Ua3TbX97cfJvczP6sCcvd9jpDcE0VqcOCIpfqzg8MPUcTqM6tmsVFU0X3D xO7HapYnbSzWrw9kxjS6yM8VsI5jtN0= X-MC-Unique: iB7XsAPMMP2jyc9C3hMNWA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 27/36] qapi/gen.py: add type hint annotations Date: Fri, 9 Oct 2020 12:15:49 -0400 Message-Id: <20201009161558.107041-28-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 104 ++++++++++++++++++++++++-------------------- 1 file changed, 57 insertions(+), 47 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 2c305c4f82c..6b1007a0351 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -15,7 +15,13 @@ import errno import os import re -from typing import Optional +from typing import ( + Dict, + Iterator, + List, + Optional, + Tuple, +) =20 from .common import ( c_fname, @@ -27,31 +33,31 @@ mcgen, ) from .schema import QAPISchemaObjectType, QAPISchemaVisitor +from .source import QAPISourceInfo =20 =20 class QAPIGen: - - def __init__(self, fname): + def __init__(self, fname: Optional[str]): self.fname =3D fname self._preamble =3D '' self._body =3D '' =20 - def preamble_add(self, text): + def preamble_add(self, text: str) -> None: self._preamble +=3D text =20 - def add(self, text): + def add(self, text: str) -> None: self._body +=3D text =20 - def get_content(self): + def get_content(self) -> str: return self._top() + self._preamble + self._body + self._bottom() =20 - def _top(self): + def _top(self) -> str: return '' =20 - def _bottom(self): + def _bottom(self) -> str: return '' =20 - def write(self, output_dir): + def write(self, output_dir: str) -> None: # Include paths starting with ../ are used to reuse modules of the= main # schema in specialised schemas. Don't overwrite the files that are # already generated for the main schema. @@ -76,7 +82,7 @@ def write(self, output_dir): f.close() =20 =20 -def _wrap_ifcond(ifcond, before, after): +def _wrap_ifcond(ifcond: List[str], before: str, after: str) -> str: if before =3D=3D after: return after # suppress empty #if ... #endif =20 @@ -116,40 +122,38 @@ def build_params(arg_type: Optional[QAPISchemaObjectT= ype], =20 =20 class QAPIGenCCode(QAPIGen): - - def __init__(self, fname): + def __init__(self, fname: Optional[str]): super().__init__(fname) - self._start_if =3D None + self._start_if: Optional[Tuple[List[str], str, str]] =3D None =20 - def start_if(self, ifcond): + def start_if(self, ifcond: List[str]) -> None: assert self._start_if is None self._start_if =3D (ifcond, self._body, self._preamble) =20 - def end_if(self): + def end_if(self) -> None: assert self._start_if self._wrap_ifcond() self._start_if =3D None =20 - def _wrap_ifcond(self): + def _wrap_ifcond(self) -> None: self._body =3D _wrap_ifcond(self._start_if[0], self._start_if[1], self._body) self._preamble =3D _wrap_ifcond(self._start_if[0], self._start_if[2], self._preamble) =20 - def get_content(self): + def get_content(self) -> str: assert self._start_if is None return super().get_content() =20 =20 class QAPIGenC(QAPIGenCCode): - - def __init__(self, fname, blurb, pydoc): + def __init__(self, fname: str, blurb: str, pydoc: str): super().__init__(fname) self._blurb =3D blurb self._copyright =3D '\n * '.join(re.findall(r'^Copyright .*', pydo= c, re.MULTILINE)) =20 - def _top(self): + def _top(self) -> str: return mcgen(''' /* AUTOMATICALLY GENERATED, DO NOT MODIFY */ =20 @@ -165,7 +169,7 @@ def _top(self): ''', blurb=3Dself._blurb, copyright=3Dself._copyright) =20 - def _bottom(self): + def _bottom(self) -> str: return mcgen(''' =20 /* Dummy declaration to prevent empty .o file */ @@ -175,16 +179,15 @@ def _bottom(self): =20 =20 class QAPIGenH(QAPIGenC): - - def _top(self): + def _top(self) -> str: return super()._top() + guardstart(self.fname) =20 - def _bottom(self): + def _bottom(self) -> str: return guardend(self.fname) =20 =20 @contextmanager -def ifcontext(ifcond, *args): +def ifcontext(ifcond: List[str], *args: QAPIGenCCode) -> Iterator[None]: """ A with-statement context manager that wraps with `start_if()` / `end_i= f()`. =20 @@ -212,8 +215,11 @@ def ifcontext(ifcond, *args): =20 =20 class QAPISchemaMonolithicCVisitor(QAPISchemaVisitor): - - def __init__(self, prefix, what, blurb, pydoc): + def __init__(self, + prefix: str, + what: str, + blurb: str, + pydoc: str): self._prefix =3D prefix self._what =3D what self._genc =3D QAPIGenC(self._prefix + self._what + '.c', @@ -221,38 +227,42 @@ def __init__(self, prefix, what, blurb, pydoc): self._genh =3D QAPIGenH(self._prefix + self._what + '.h', blurb, pydoc) =20 - def write(self, output_dir): + def write(self, output_dir: str) -> None: self._genc.write(output_dir) self._genh.write(output_dir) =20 =20 class QAPISchemaModularCVisitor(QAPISchemaVisitor): - - def __init__(self, prefix, what, user_blurb, builtin_blurb, pydoc): + def __init__(self, + prefix: str, + what: str, + user_blurb: str, + builtin_blurb: Optional[str], + pydoc: str): self._prefix =3D prefix self._what =3D what self._user_blurb =3D user_blurb self._builtin_blurb =3D builtin_blurb self._pydoc =3D pydoc - self._genc =3D None - self._genh =3D None - self._module =3D {} - self._main_module =3D None + self._genc: Optional[QAPIGenC] =3D None + self._genh: Optional[QAPIGenH] =3D None + self._module: Dict[Optional[str], Tuple[QAPIGenC, QAPIGenH]] =3D {} + self._main_module: Optional[str] =3D None =20 @staticmethod - def _is_user_module(name): + def _is_user_module(name: Optional[str]) -> bool: return bool(name and not name.startswith('./')) =20 @staticmethod - def _is_builtin_module(name): + def _is_builtin_module(name: Optional[str]) -> bool: return not name =20 - def _module_dirname(self, what, name): + def _module_dirname(self, what: str, name: Optional[str]) -> str: if self._is_user_module(name): return os.path.dirname(name) return '' =20 - def _module_basename(self, what, name): + def _module_basename(self, what: str, name: Optional[str]) -> str: ret =3D '' if self._is_builtin_module(name) else self._prefix if self._is_user_module(name): basename =3D os.path.basename(name) @@ -264,27 +274,27 @@ def _module_basename(self, what, name): ret +=3D re.sub(r'-', '-' + name + '-', what) return ret =20 - def _module_filename(self, what, name): + def _module_filename(self, what: str, name: Optional[str]) -> str: return os.path.join(self._module_dirname(what, name), self._module_basename(what, name)) =20 - def _add_module(self, name, blurb): + def _add_module(self, name: Optional[str], blurb: str) -> None: basename =3D self._module_filename(self._what, name) genc =3D QAPIGenC(basename + '.c', blurb, self._pydoc) genh =3D QAPIGenH(basename + '.h', blurb, self._pydoc) self._module[name] =3D (genc, genh) self._genc, self._genh =3D self._module[name] =20 - def _add_user_module(self, name, blurb): + def _add_user_module(self, name: str, blurb: str) -> None: assert self._is_user_module(name) if self._main_module is None: self._main_module =3D name self._add_module(name, blurb) =20 - def _add_system_module(self, name, blurb): + def _add_system_module(self, name: Optional[str], blurb: str) -> None: self._add_module(name and './' + name, blurb) =20 - def write(self, output_dir, opt_builtins=3DFalse): + def write(self, output_dir: str, opt_builtins: bool =3D False) -> None: for name in self._module: if self._is_builtin_module(name) and not opt_builtins: continue @@ -292,13 +302,13 @@ def write(self, output_dir, opt_builtins=3DFalse): genc.write(output_dir) genh.write(output_dir) =20 - def _begin_system_module(self, name): + def _begin_system_module(self, name: None) -> None: pass =20 - def _begin_user_module(self, name): + def _begin_user_module(self, name: str) -> None: pass =20 - def visit_module(self, name): + def visit_module(self, name: Optional[str]) -> None: if name is None: if self._builtin_blurb: self._add_system_module(None, self._builtin_blurb) @@ -312,7 +322,7 @@ def visit_module(self, name): self._add_user_module(name, self._user_blurb) self._begin_user_module(name) =20 - def visit_include(self, name, info): + def visit_include(self, name: str, info: QAPISourceInfo) -> None: relname =3D os.path.relpath(self._module_filename(self._what, name= ), os.path.dirname(self._genh.fname)) self._genh.preamble_add(mcgen(''' --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261350; cv=none; d=zohomail.com; s=zohoarc; b=VxwplnRDJKnHcs5zrXClnIksfq2Lx03glx76URVsu3QeYNvH4bQMNgskzGqWHASwE1epikKjtiba6SW7qYm93kEaaeOXI1knO62tt0rmhRaSVvie/lUrTmhWouncOL1QfC8gcTKhlcUckWEYNiClAyemduW0stcYxazRCJvtPBA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261350; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NokZjup1s/JJJLtM1cjZYz1WaakVYpJE4WuZHADWMxE=; b=nPGovB5uLuRFGwhbm5E4mVM8qt7Bh2o1t9WWfdjBv5sS50ikc1759oGs43kvOb10hPGnc1swDxSozt3jjtoKK42TFaiur4PTaUC3f9GOzyg+b2HwCNIsbpxrmsEBvlVRAD+F5NvPpqf1jlrNk9Dc0Byg9biEtyVBUbz2ytzNvh0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261350834297.9468494174497; Fri, 9 Oct 2020 09:35:50 -0700 (PDT) Received: from localhost ([::1]:36080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvMz-0005IT-El for importer@patchew.org; Fri, 09 Oct 2020 12:35:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4X-0004Pu-En for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42794) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4P-0003LR-L2 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:45 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-311-xhhzAJ5kPO60m1UEoG-M9A-1; Fri, 09 Oct 2020 12:16:35 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 41A3318829D4; Fri, 9 Oct 2020 16:16:34 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F9961A925; Fri, 9 Oct 2020 16:16:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260196; 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=NokZjup1s/JJJLtM1cjZYz1WaakVYpJE4WuZHADWMxE=; b=XAasKlE16s4hmnlWJCW2Xpp3tawfMAoa9F8eLmRHQ5xBhyQ5GiXJ3DFRIkzoxdglW5Sjun uEbgpMeJT6oSrk4cLJBumx0b3RmF6YrEXbRgJIVc79P6Un+6EEsqY8OfF0Qb8cKbedeUuI JhfWsQGLmi+I1Xvqk0AL7Bfb+fWV59Q= X-MC-Unique: xhhzAJ5kPO60m1UEoG-M9A-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 28/36] qapi/gen.py: Enable checking with mypy Date: Fri, 9 Oct 2020 12:15:50 -0400 Message-Id: <20201009161558.107041-29-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/mypy.ini | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 1b8555dfa39..c6960ff2dbd 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -14,11 +14,6 @@ disallow_untyped_defs =3D False disallow_incomplete_defs =3D False check_untyped_defs =3D False =20 -[mypy-qapi.gen] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False - [mypy-qapi.introspect] disallow_untyped_defs =3D False disallow_incomplete_defs =3D False --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602262320; cv=none; d=zohomail.com; s=zohoarc; b=gRmVMLZyBb+VRWs9zH/64SODP173BL7+KmMUjp4M9TIacJsZDUDXVd4QMFXa57h/ATVj0mim/lQ4k7h9bMbSCCZECKGbfMLoHPIjbU01JNAUHmxzNeSKOXtdptTSEKv0hYK9T/UGwtYXiABllg0kAS5H1QLBwLptH7SkXigWObo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602262320; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=F5apthK+JxyMfvvIZd6yAMPltzFKRI+88ZPYYQLfkSM=; b=cyVn2/XGVojpqT18WpLX/h7Ciy4dWlyTDY6DC8XYW78ZvLA2+ku3YTqxT7Hghyjrm6m3QSfhNhpiv48ZmJOzgpIr7HSEXSeVHyzTDU6rT4UDrleXvmy6WZ8Znv0HJYojMAPRVHm0hsd5JQqrYcVNB3pm6OrVTLLhCcYH9nAu11o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602262320609256.556283567934; Fri, 9 Oct 2020 09:52:00 -0700 (PDT) Received: from localhost ([::1]:59566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvcd-0001WC-A5 for importer@patchew.org; Fri, 09 Oct 2020 12:51:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4a-0004Wc-Ea for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4W-0003Ln-CT for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-1wW5w32kNH28MOcjANO1OA-1; Fri, 09 Oct 2020 12:16:36 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 26B5D100746B; Fri, 9 Oct 2020 16:16:35 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A2B119936; Fri, 9 Oct 2020 16:16:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260197; 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=F5apthK+JxyMfvvIZd6yAMPltzFKRI+88ZPYYQLfkSM=; b=arOuAeVSkxJlwDeB3Pl6/9vfynGazsOedFuz1gTX2me5AE2UeGmujxSceABUmUK+HqVYav xKu0esGjT96V+/6q+W9OgRjeVWxzt/iEvDMB/czE7np2D9yLQY8MfxfHScNYA/qZlCCZce TMLXLFuzIZyqVJCYTscCtvs+0o3kki8= X-MC-Unique: 1wW5w32kNH28MOcjANO1OA-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 29/36] qapi/gen.py: Remove unused parameter Date: Fri, 9 Oct 2020 12:15:51 -0400 Message-Id: <20201009161558.107041-30-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" _module_dirname doesn't use the 'what' argument, so remove it. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 6b1007a0351..8b851c6262a 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -257,7 +257,7 @@ def _is_user_module(name: Optional[str]) -> bool: def _is_builtin_module(name: Optional[str]) -> bool: return not name =20 - def _module_dirname(self, what: str, name: Optional[str]) -> str: + def _module_dirname(self, name: Optional[str]) -> str: if self._is_user_module(name): return os.path.dirname(name) return '' @@ -275,7 +275,7 @@ def _module_basename(self, what: str, name: Optional[st= r]) -> str: return ret =20 def _module_filename(self, what: str, name: Optional[str]) -> str: - return os.path.join(self._module_dirname(what, name), + return os.path.join(self._module_dirname(name), self._module_basename(what, name)) =20 def _add_module(self, name: Optional[str], blurb: str) -> None: --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602262183; cv=none; d=zohomail.com; s=zohoarc; b=Vp9A9kLJd5ms/VSUwA4waN+AO14JeZImKeby/L+cLR6uPuULvC139AkEefnywDaPNUOuFrKSO/gAK2OU6HZO+DjoNY9OPcKjbQaMiqO/V9KYB7XHVK2hApGNDcwAr6vasoV/mTR0f7Ze1A0qBw9M1rHTwnS3d5dR2dX3mURy6/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602262183; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sPjifP2+5n1lXhEe2k7KoPcz05HQPVwHmBY5e5Aozlg=; b=S/kFpKauRgv7thtIQzkNnICiVNK+OiaYNM6wr6oGD2Kl4Ac2b0nBYUKvXK0uBOlxHLpIQ5ebmNtoGq7tm8dG6lB9XukhDrFompJnMqSfUiEPrVIPbGHzWKy5KXRiSd1p7zOzlSz9ToASBufFOMtJRLw2NbRbq3wHiMUjkp+KeeE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602262183142238.23532203674336; Fri, 9 Oct 2020 09:49:43 -0700 (PDT) Received: from localhost ([::1]:52388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvaP-0006xq-UY for importer@patchew.org; Fri, 09 Oct 2020 12:49:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4Y-0004Rj-8e for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30915) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4W-0003M9-7t for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:45 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-189-2eAcXdxlMRGPjEaEzUM8HQ-1; Fri, 09 Oct 2020 12:16:37 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E85418829D4; Fri, 9 Oct 2020 16:16:36 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FC6C1A925; Fri, 9 Oct 2020 16:16:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260199; 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=sPjifP2+5n1lXhEe2k7KoPcz05HQPVwHmBY5e5Aozlg=; b=fNAa2rd0iirVRI3VGCtwWl5IvIg5+eJ0jVnjgPj4bTOwroG9zhriKQzaPvETlEfBh6AdGB lWy0iEXRCZPB1MAkDGnr+jSqtZfK1YCu5AoGZmLbypWRmdcOxu6PZ+uR1X+1LTcC+m3dRZ 5dYy+PdRQWKmVfd/lUXwiQs3x8Y9XCI= X-MC-Unique: 2eAcXdxlMRGPjEaEzUM8HQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 30/36] qapi/gen.py: update write() to be more idiomatic Date: Fri, 9 Oct 2020 12:15:52 -0400 Message-Id: <20201009161558.107041-31-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Make the file handling here just a tiny bit more idiomatic. (I realize this is heavily subjective.) Use exist_ok=3DTrue for os.makedirs and remove the exception, use fdopen() to wrap the file descriptor in a File-like object, and use a context manager for managing the file pointer. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 8b851c6262a..670c21e2109 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -12,7 +12,6 @@ # See the COPYING file in the top-level directory. =20 from contextlib import contextmanager -import errno import os import re from typing import ( @@ -65,21 +64,19 @@ def write(self, output_dir: str) -> None: return pathname =3D os.path.join(output_dir, self.fname) odir =3D os.path.dirname(pathname) + if odir: - try: - os.makedirs(odir) - except os.error as e: - if e.errno !=3D errno.EEXIST: - raise + os.makedirs(odir, exist_ok=3DTrue) + + # use os.open for O_CREAT to create and read a non-existant file fd =3D os.open(pathname, os.O_RDWR | os.O_CREAT, 0o666) - f =3D open(fd, 'r+', encoding=3D'utf-8') - text =3D self.get_content() - oldtext =3D f.read(len(text) + 1) - if text !=3D oldtext: - f.seek(0) - f.truncate(0) - f.write(text) - f.close() + with os.fdopen(fd, 'r+', encoding=3D'utf-8') as fp: + text =3D self.get_content() + oldtext =3D fp.read(len(text) + 1) + if text !=3D oldtext: + fp.seek(0) + fp.truncate(0) + fp.write(text) =20 =20 def _wrap_ifcond(ifcond: List[str], before: str, after: str) -> str: --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602262213; cv=none; d=zohomail.com; s=zohoarc; b=a8EAY3syVMcfwWKGsHJ5ix+w7f0FzJzQXxZncwsjJa6SAd/o6ntIoOvFXrm+3Bg0WFoV+nWOaZp8FnA7aDpklPIv243QynTh86liIz+yOgu4oBryKzxAKt9X9GCnopQTdWOANX9GpLR8AwzKEA2x6VudYKnYRyYvTkabGoKV8Iw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602262213; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gh01B+eg56jBQVpBi1Ly30SmFT5vOt+tVC7lOZ4m4M0=; b=jhoMNoKesa4ES0EoMY40AR6ktkATCHdsDpdHnY8Yug34mnEApefPOwRGCxXJpSuSJT25PgoqxMPwEV0RzJTwDC9MAs+NRN8eWk/iip76XYtEeGvDLaXfkaIh2AiMMBZAj2p0SVbFIRPHn21zRCLO5rC+Hd77R0U+XQA+1WUMonM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602262213772678.0737365968998; Fri, 9 Oct 2020 09:50:13 -0700 (PDT) Received: from localhost ([::1]:53822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvau-0007Wm-Er for importer@patchew.org; Fri, 09 Oct 2020 12:50:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4d-0004f1-Ux for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46213) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4W-0003MF-9U for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:51 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-568-sAL4McZPNOC4Lby6ozEA7g-1; Fri, 09 Oct 2020 12:16:38 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F405764082; Fri, 9 Oct 2020 16:16:36 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4287019936; Fri, 9 Oct 2020 16:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260199; 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=gh01B+eg56jBQVpBi1Ly30SmFT5vOt+tVC7lOZ4m4M0=; b=NaNgH/FEacRdHge9/L3Z9JojrQw0bopATQs5Af8PhGbvFiZeE8TCwq/U8IckzECFjX3mC0 gJVi1ix41SoAt2t4bAjDKVce88GgLbUPP1AnTfmCAC8WaDZbUbpab3XSbSMFyVCeXuj6l4 42CBg68xb9q7DPy/GqR+sHcGIaN/Z2c= X-MC-Unique: sAL4McZPNOC4Lby6ozEA7g-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 31/36] qapi/gen.py: delint with pylint Date: Fri, 9 Oct 2020 12:15:53 -0400 Message-Id: <20201009161558.107041-32-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 'fp' and 'fd' are self-evident in context, add them to the list of OK names. _top and _bottom also need to stay standard methods because some users override the method and need to use `self`. Tell pylint to shush. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/gen.py | 2 ++ scripts/qapi/pylintrc | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 670c21e2109..b40f18eee3c 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -51,9 +51,11 @@ def get_content(self) -> str: return self._top() + self._preamble + self._body + self._bottom() =20 def _top(self) -> str: + # pylint: disable=3Dno-self-use return '' =20 def _bottom(self) -> str: + # pylint: disable=3Dno-self-use return '' =20 def write(self, output_dir: str) -> None: diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index d840b150313..8badcb11cda 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -4,7 +4,6 @@ # The regex matches against base names, not paths. ignore-patterns=3Derror.py, expr.py, - gen.py, parser.py, schema.py, types.py, @@ -45,7 +44,9 @@ good-names=3Di, k, ex, Run, - _ + _, + fp, # fp =3D open(...) + fd, # fd =3D os.open(...) =20 [VARIABLES] =20 --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261525; cv=none; d=zohomail.com; s=zohoarc; b=HqcPYHgQTihJfzHruNlIWD6ej8NwCei9sTouNsanSMlDtXPzV5AKCmC0Q56wX+HP3PldMSZUiISlqlf2UtXKVZHJjsO/qTZOrKMivCvjvbCfUcuWDXXjfjOjwIiO8Ui+miGIo8xZ4CEhCFHXE2H1izZBll5VWTB50KuK4swEec0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261525; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ai836Tc//oISII4mpE7O+u/DNSmqEHANrNBrGtG3ZXw=; b=c3PKqcixCfXWwIkmu0Qp4+eIxVK22YLg6BhWHfK1jTtakNChFx8NTHCi018SY+kP0hVmpiMGEjDNFUVb+UgEd0V52tlLTKqiSpxwZ7zAlMcB5f8INHhptyRAkgGb1ziGlRiMOddzoDJqkDU6P4M7JQo8L3ie4AWDOt3BLsSJqfE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261525552506.5622935376673; Fri, 9 Oct 2020 09:38:45 -0700 (PDT) Received: from localhost ([::1]:44570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvPo-0000NP-1F for importer@patchew.org; Fri, 09 Oct 2020 12:38:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4b-0004Zh-JQ for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49024) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4W-0003MJ-D1 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-594-s5IBrpdjPWq2Avc3uJHd0Q-1; Fri, 09 Oct 2020 12:16:38 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DD91A80B70A; Fri, 9 Oct 2020 16:16:37 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2606419936; Fri, 9 Oct 2020 16:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260200; 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=Ai836Tc//oISII4mpE7O+u/DNSmqEHANrNBrGtG3ZXw=; b=FRtAP5+PlIrpIjtSFbGXvaIJVzxejZgnIdbVt9quqc886t7G1vRbH3vuJzAXVjoipVbexw 4D0Bk5gR8uzAVwFQjKrmrREku47cXOnH9op6j4BvybbOtjht3a8W20BFHIoNXK2DfTr18f kG1botyRAmgs2ux6INdJveDq7Shfw1k= X-MC-Unique: s5IBrpdjPWq2Avc3uJHd0Q-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 32/36] qapi/types.py: add type hint annotations Date: Fri, 9 Oct 2020 12:15:54 -0400 Message-Id: <20201009161558.107041-33-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/mypy.ini | 5 --- scripts/qapi/types.py | 86 ++++++++++++++++++++++++++++++++----------- 2 files changed, 64 insertions(+), 27 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index c6960ff2dbd..83f19813553 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -29,11 +29,6 @@ disallow_untyped_defs =3D False disallow_incomplete_defs =3D False check_untyped_defs =3D False =20 -[mypy-qapi.types] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False - [mypy-qapi.visit] disallow_untyped_defs =3D False disallow_incomplete_defs =3D False diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 53b47f9e58a..766822feb3a 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -13,6 +13,8 @@ # See the COPYING file in the top-level directory. """ =20 +from typing import List, Optional + from .common import ( c_enum_const, c_name, @@ -21,7 +23,16 @@ mcgen, ) from .gen import QAPISchemaModularCVisitor, ifcontext -from .schema import QAPISchemaEnumMember, QAPISchemaObjectType +from .schema import ( + QAPISchema, + QAPISchemaEnumMember, + QAPISchemaFeature, + QAPISchemaObjectType, + QAPISchemaObjectTypeMember, + QAPISchemaType, + QAPISchemaVariants, +) +from .source import QAPISourceInfo =20 =20 # variants must be emitted before their container; track what has already @@ -29,7 +40,9 @@ objects_seen =3D set() =20 =20 -def gen_enum_lookup(name, members, prefix=3DNone): +def gen_enum_lookup(name: str, + members: List[QAPISchemaEnumMember], + prefix: Optional[str] =3D None) -> str: ret =3D mcgen(''' =20 const QEnumLookup %(c_name)s_lookup =3D { @@ -54,7 +67,9 @@ def gen_enum_lookup(name, members, prefix=3DNone): return ret =20 =20 -def gen_enum(name, members, prefix=3DNone): +def gen_enum(name: str, + members: List[QAPISchemaEnumMember], + prefix: Optional[str] =3D None) -> str: # append automatically generated _MAX value enum_members =3D members + [QAPISchemaEnumMember('_MAX', None)] =20 @@ -88,7 +103,7 @@ def gen_enum(name, members, prefix=3DNone): return ret =20 =20 -def gen_fwd_object_or_array(name): +def gen_fwd_object_or_array(name: str) -> str: return mcgen(''' =20 typedef struct %(c_name)s %(c_name)s; @@ -96,7 +111,7 @@ def gen_fwd_object_or_array(name): c_name=3Dc_name(name)) =20 =20 -def gen_array(name, element_type): +def gen_array(name: str, element_type: QAPISchemaType) -> str: return mcgen(''' =20 struct %(c_name)s { @@ -107,7 +122,7 @@ def gen_array(name, element_type): c_name=3Dc_name(name), c_type=3Delement_type.c_type()) =20 =20 -def gen_struct_members(members): +def gen_struct_members(members: List[QAPISchemaObjectTypeMember]) -> str: ret =3D '' for memb in members: ret +=3D gen_if(memb.ifcond) @@ -124,7 +139,10 @@ def gen_struct_members(members): return ret =20 =20 -def gen_object(name, ifcond, base, members, variants): +def gen_object(name: str, ifcond: List[str], + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> str: if name in objects_seen: return '' objects_seen.add(name) @@ -178,7 +196,7 @@ def gen_object(name, ifcond, base, members, variants): return ret =20 =20 -def gen_upcast(name, base): +def gen_upcast(name: str, base: QAPISchemaObjectType) -> str: # C makes const-correctness ugly. We have to cast away const to let # this function work for both const and non-const obj. return mcgen(''' @@ -191,7 +209,7 @@ def gen_upcast(name, base): c_name=3Dc_name(name), base=3Dbase.c_name()) =20 =20 -def gen_variants(variants): +def gen_variants(variants: QAPISchemaVariants) -> str: ret =3D mcgen(''' union { /* union tag is @%(c_name)s */ ''', @@ -215,7 +233,7 @@ def gen_variants(variants): return ret =20 =20 -def gen_type_cleanup_decl(name): +def gen_type_cleanup_decl(name: str) -> str: ret =3D mcgen(''' =20 void qapi_free_%(c_name)s(%(c_name)s *obj); @@ -225,7 +243,7 @@ def gen_type_cleanup_decl(name): return ret =20 =20 -def gen_type_cleanup(name): +def gen_type_cleanup(name: str) -> str: ret =3D mcgen(''' =20 void qapi_free_%(c_name)s(%(c_name)s *obj) @@ -247,12 +265,12 @@ def gen_type_cleanup(name): =20 class QAPISchemaGenTypeVisitor(QAPISchemaModularCVisitor): =20 - def __init__(self, prefix): + def __init__(self, prefix: str): super().__init__( prefix, 'qapi-types', ' * Schema-defined QAPI types', ' * Built-in QAPI types', __doc__) =20 - def _begin_system_module(self, name): + def _begin_system_module(self, name: None) -> None: self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "qapi/dealloc-visitor.h" @@ -263,7 +281,7 @@ def _begin_system_module(self, name): #include "qapi/util.h" ''')) =20 - def _begin_user_module(self, name): + def _begin_user_module(self, name: str) -> None: types =3D self._module_basename('qapi-types', name) visit =3D self._module_basename('qapi-visit', name) self._genc.preamble_add(mcgen(''' @@ -277,27 +295,43 @@ def _begin_user_module(self, name): #include "qapi/qapi-builtin-types.h" ''')) =20 - def visit_begin(self, schema): + def visit_begin(self, schema: QAPISchema) -> None: # gen_object() is recursive, ensure it doesn't visit the empty type objects_seen.add(schema.the_empty_object_type.name) =20 - def _gen_type_cleanup(self, name): + def _gen_type_cleanup(self, name: str) -> None: self._genh.add(gen_type_cleanup_decl(name)) self._genc.add(gen_type_cleanup(name)) =20 - def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): + def visit_enum_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: List[str], + features: List[QAPISchemaFeature], + members: List[QAPISchemaEnumMember], + prefix: Optional[str]) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.preamble_add(gen_enum(name, members, prefix)) self._genc.add(gen_enum_lookup(name, members, prefix)) =20 - def visit_array_type(self, name, info, ifcond, element_type): + def visit_array_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: List[str], + element_type: QAPISchemaType) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.preamble_add(gen_fwd_object_or_array(name)) self._genh.add(gen_array(name, element_type)) self._gen_type_cleanup(name) =20 - def visit_object_type(self, name, info, ifcond, features, - base, members, variants): + def visit_object_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: List[str], + features: List[QAPISchemaFeature], + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> None: # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return @@ -313,7 +347,12 @@ def visit_object_type(self, name, info, ifcond, featur= es, # implicit types won't be directly allocated/freed self._gen_type_cleanup(name) =20 - def visit_alternate_type(self, name, info, ifcond, features, variants): + def visit_alternate_type(self, + name: str, + info: QAPISourceInfo, + ifcond: List[str], + features: List[QAPISchemaFeature], + variants: QAPISchemaVariants) -> None: with ifcontext(ifcond, self._genh): self._genh.preamble_add(gen_fwd_object_or_array(name)) self._genh.add(gen_object(name, ifcond, None, @@ -322,7 +361,10 @@ def visit_alternate_type(self, name, info, ifcond, fea= tures, variants): self._gen_type_cleanup(name) =20 =20 -def gen_types(schema, output_dir, prefix, opt_builtins): +def gen_types(schema: QAPISchema, + output_dir: str, + prefix: str, + opt_builtins: bool) -> None: vis =3D QAPISchemaGenTypeVisitor(prefix) schema.visit(vis) vis.write(output_dir, opt_builtins) --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261874; cv=none; d=zohomail.com; s=zohoarc; b=I7polCTHYzoQTG6WgxKX0ZpH9SmNwMNZb+e+M1OdJ90pf4ZrPOF/It9gKOd44BfNBgfS3YDyX9qr8tHA7MdQCx4N4qfkoKWdJZ9c3ogawCWavb7/Cmgvws3ZtUySANV93OaV8kHxWfGyw8sAqbBWBietOh5LEf867BpmcxCoUH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261874; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=edHWZnJQ4Fsw6XkPUsdCVTYrr6N4Ak6QIKowrvZQCtY=; b=IHvcOXTNEDjuMD0pz/H4AEy2dx2hzoxZfNEw0eok6o95ubFXtTNs+CDvKe8rXUb5Tg0r8CU2bg5VkNVPtFpGjSaTC+gbsvA5g6DrZsjNGhWFG2C6+GQjlew+IY4UqXBVn43QzkzaqIrnxGWOBVr/ZLP0iOb5G3e1CJyC+34ROwk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261874854299.7639158975635; Fri, 9 Oct 2020 09:44:34 -0700 (PDT) Received: from localhost ([::1]:36466 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvVR-0000Or-F5 for importer@patchew.org; Fri, 09 Oct 2020 12:44:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4Z-0004TQ-0S for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42259) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4W-0003MQ-9l for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-497-rfAv_eQMN--rv7Xp5USuiQ-1; Fri, 09 Oct 2020 12:16:39 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C680064082; Fri, 9 Oct 2020 16:16:38 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id 11D611A925; Fri, 9 Oct 2020 16:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260202; 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=edHWZnJQ4Fsw6XkPUsdCVTYrr6N4Ak6QIKowrvZQCtY=; b=ixrote3ZiTe8yBBvpVF+A3VPOLFb0Ia1ynKxVo+ldFH0clM+tizV+2c9YANC2HvlWLG9Y8 JnnnHg6lEqRrgFI185WSTvKlpmIGY5jCtXZxR2y263bP4xY59l4E29OUJQZPYo3INsPKQu tL/HKuRW5yBo4xOXRi+BTctjwFu7/aQ= X-MC-Unique: rfAv_eQMN--rv7Xp5USuiQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 33/36] qapi/types.py: remove one-letter variables Date: Fri, 9 Oct 2020 12:15:55 -0400 Message-Id: <20201009161558.107041-34-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:37 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" "John, if pylint told you to jump off a bridge, would you?" Hey, if it looked like fun, I might. Now that this file is clean, enable pylint checks on this file. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/pylintrc | 1 - scripts/qapi/types.py | 29 +++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index 8badcb11cda..b3c4cf46dbf 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -6,7 +6,6 @@ ignore-patterns=3Derror.py, expr.py, parser.py, schema.py, - types.py, visit.py, =20 =20 diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 766822feb3a..2b4916cdaa1 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -49,14 +49,14 @@ def gen_enum_lookup(name: str, .array =3D (const char *const[]) { ''', c_name=3Dc_name(name)) - for m in members: - ret +=3D gen_if(m.ifcond) - index =3D c_enum_const(name, m.name, prefix) + for memb in members: + ret +=3D gen_if(memb.ifcond) + index =3D c_enum_const(name, memb.name, prefix) ret +=3D mcgen(''' [%(index)s] =3D "%(name)s", ''', - index=3Dindex, name=3Dm.name) - ret +=3D gen_endif(m.ifcond) + index=3Dindex, name=3Dmemb.name) + ret +=3D gen_endif(memb.ifcond) =20 ret +=3D mcgen(''' }, @@ -79,13 +79,13 @@ def gen_enum(name: str, ''', c_name=3Dc_name(name)) =20 - for m in enum_members: - ret +=3D gen_if(m.ifcond) + for memb in enum_members: + ret +=3D gen_if(memb.ifcond) ret +=3D mcgen(''' %(c_enum)s, ''', - c_enum=3Dc_enum_const(name, m.name, prefix)) - ret +=3D gen_endif(m.ifcond) + c_enum=3Dc_enum_const(name, memb.name, prefix)) + ret +=3D gen_endif(memb.ifcond) =20 ret +=3D mcgen(''' } %(c_name)s; @@ -148,11 +148,12 @@ def gen_object(name: str, ifcond: List[str], objects_seen.add(name) =20 ret =3D '' - if variants: - for v in variants.variants: - if isinstance(v.type, QAPISchemaObjectType): - ret +=3D gen_object(v.type.name, v.type.ifcond, v.type.bas= e, - v.type.local_members, v.type.variants) + for var in variants.variants if variants else (): + obj =3D var.type + if not isinstance(obj, QAPISchemaObjectType): + continue + ret +=3D gen_object(obj.name, obj.ifcond, obj.base, + obj.local_members, obj.variants) =20 ret +=3D mcgen(''' =20 --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602262432; cv=none; d=zohomail.com; s=zohoarc; b=CB+hwumLRUTgEUPeJIOXiPsciIm83j3H+sXmeoOyPQR9fmOBhaHIbuLMxmWWKYYIF6Jkm1aFxRiPv6egc3PkuKgaky6YEcgVk8ReRsZ4smjTh4RZ6WgCUAXrwV4LOjKyJiBrFrfMkzxmYZkzbCEIgJbDa8VhB1i8IonwwiuzxkU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602262432; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=THLjB+nqUST3VSx1phmjeHAFHIBVHY5eQx5Gg5vz534=; b=EBGTcKCabch89ppOObAPlap3LXucJJacGQ8xzU2TEMbnAxZhPh5vazqmnz4cow/D2bWI1iaDIU9T2hSuMdW176/Lzo+fQ+nzXPPJ7GaX0RS24PCAmWyLyZDJVNZkS428DZupf2XZ8h0Rx9EU4/AoN7EbN+ezOHdT9KcHVCsiLSk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602262432512592.1169645110139; Fri, 9 Oct 2020 09:53:52 -0700 (PDT) Received: from localhost ([::1]:38684 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQveR-0004UA-43 for importer@patchew.org; Fri, 09 Oct 2020 12:53:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4a-0004Xs-VR for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48485) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4W-0003Mj-CH for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-154-Cai5p_K_OtKfcq4wSS9fhQ-1; Fri, 09 Oct 2020 12:16:40 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AC2BA64086; Fri, 9 Oct 2020 16:16:39 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDEC419936; Fri, 9 Oct 2020 16:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260203; 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=THLjB+nqUST3VSx1phmjeHAFHIBVHY5eQx5Gg5vz534=; b=inQsSZOSKnLRK0dgvw9JBVutjXBcB4htn+uSWV6iI0RrPRMsiWSebSmi8Z1v5Kupev1PRb 91+tl0LVIFN/fPndcnx0Kgqml2rTy+7v5HtP0yKoBLFaXm7/d6FX428aVTyG7ctF4GS2BL ggQuE2/uMTk9iWuZGtrmblK5OZbtt5c= X-MC-Unique: Cai5p_K_OtKfcq4wSS9fhQ-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 34/36] qapi/visit.py: assert tag_member contains a QAPISchemaEnumType Date: Fri, 9 Oct 2020 12:15:56 -0400 Message-Id: <20201009161558.107041-35-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is true by design, but not presently able to be expressed in the type system. An assertion helps mypy understand our constraints. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/visit.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 708f72c4a1e..e00f2a09d75 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -22,7 +22,7 @@ mcgen, ) from .gen import QAPISchemaModularCVisitor, ifcontext -from .schema import QAPISchemaObjectType +from .schema import QAPISchemaEnumType, QAPISchemaObjectType =20 =20 def gen_visit_decl(name, scalar=3DFalse): @@ -84,15 +84,17 @@ def gen_visit_object_members(name, base, members, varia= nts): ret +=3D gen_endif(memb.ifcond) =20 if variants: + tag_member =3D variants.tag_member + assert isinstance(tag_member.type, QAPISchemaEnumType) + ret +=3D mcgen(''' switch (obj->%(c_name)s) { ''', - c_name=3Dc_name(variants.tag_member.name)) + c_name=3Dc_name(tag_member.name)) =20 for var in variants.variants: - case_str =3D c_enum_const(variants.tag_member.type.name, - var.name, - variants.tag_member.type.prefix) + case_str =3D c_enum_const(tag_member.type.name, var.name, + tag_member.type.prefix) ret +=3D gen_if(var.ifcond) if var.type.name =3D=3D 'q_empty': # valid variant and nothing to do --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602262100; cv=none; d=zohomail.com; s=zohoarc; b=OZ+Y67XC671uS1joPQYKpHbAgpQQ3Alm3KkVJ7Jghrgw/M+7ZzltmaDdVT98L8XZ3sIoXtZ/CSz3FhWkX4HKCQyy2OCelo1rTiA73PBt9IwbxWX8B8iAwdYu7yTPFfQ4fGcXUMc91DeDK6cGiZnfShOUYhyVGyQn+rxe3SxglmY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602262100; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tdn05DNwF+o4+GQORBUXpIfhhHZKPHGKMbVPTrsDm7Q=; b=VkTNh7lxZXPtQ6/0ST9VgbjlzKSDVaeIEI5+UUA87Ro9BFjAQtbCTTw66jJDjb064E6G/K736invsU/Emy/DJxusPiG4wRKn7YlvcFOyB21TeX54e/wl7glPi5CX2lnf/vpbxLLRQbkKR1xa2cOLCwvX2uR/xE4KqsRz/e+6Mqo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602262100431633.1976542729598; Fri, 9 Oct 2020 09:48:20 -0700 (PDT) Received: from localhost ([::1]:47382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvZ4-0004yZ-Tp for importer@patchew.org; Fri, 09 Oct 2020 12:48:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4Z-0004V8-OL for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:50355) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4W-0003Ml-Bo for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-184-5NoNN2_hOv2lPRWOTRjPgw-1; Fri, 09 Oct 2020 12:16:41 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A5BC3802B75; Fri, 9 Oct 2020 16:16:40 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id D228119936; Fri, 9 Oct 2020 16:16:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260203; 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=tdn05DNwF+o4+GQORBUXpIfhhHZKPHGKMbVPTrsDm7Q=; b=hL6nqcKiWS3OdNAELp6VaWAEucWVzw4ibH7uwex4HSv7/vabWeK3SZzClvXM/uvTJedasD yk5Xet0U+ksqrWeYtD6eztD8CFBOyn41DHdKGSxcLcns7Zh/Z9uxTg3yJ82xsgyvyvQxEJ IJ1lTEgcgB/qHRnDvkSfAhZczv3+HCQ= X-MC-Unique: 5NoNN2_hOv2lPRWOTRjPgw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 35/36] qapi/visit.py: remove unused parameters from gen_visit_object Date: Fri, 9 Oct 2020 12:15:57 -0400 Message-Id: <20201009161558.107041-36-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , John Snow , Michael Roth , Markus Armbruster , Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) And this fixes the pylint report for this file, so make sure we check this in the future, too. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster --- scripts/qapi/pylintrc | 1 - scripts/qapi/visit.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index b3c4cf46dbf..b9e077a1642 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -6,7 +6,6 @@ ignore-patterns=3Derror.py, expr.py, parser.py, schema.py, - visit.py, =20 =20 [MESSAGES CONTROL] diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index e00f2a09d75..8699e5c09c6 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -250,7 +250,7 @@ def gen_visit_alternate(name, variants): return ret =20 =20 -def gen_visit_object(name, base, members, variants): +def gen_visit_object(name): return mcgen(''' =20 bool visit_type_%(c_name)s(Visitor *v, const char *name, @@ -343,7 +343,7 @@ def visit_object_type(self, name, info, ifcond, feature= s, if not name.startswith('q_'): # only explicit types need an allocating visit self._genh.add(gen_visit_decl(name)) - self._genc.add(gen_visit_object(name, base, members, varia= nts)) + self._genc.add(gen_visit_object(name)) =20 def visit_alternate_type(self, name, info, ifcond, features, variants): with ifcontext(ifcond, self._genh, self._genc): --=20 2.26.2 From nobody Tue May 14 01:19:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1602261664; cv=none; d=zohomail.com; s=zohoarc; b=YjqzGTGuqJa/Hz63QRhvVU6X5wjH6ABAqZkIfxwUC/pwZk5dDNt9E3G7nK2Rg2+r4MJVcULDsspXWF9oKxHHiv8xywT1O1G+QEZ2stswn5ybUQq+0F3np50fQUfYazhIxfyma/ET6v2sZisAb2Rl5MwBR1vKSYIGV9zy3ppBbNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602261664; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=xfLHFOeSxVhEBa0V5rzKpvO9KzbAZlKvh/1PPXfZ3Wc=; b=YPg/6PfLpbGKUkKnLtIY/PrNih2A08EVR+tYK2IhlT41J5RSpApIZHoiVfrDmf6F0ITCy3FhwSxNfQyt67gnZ9JzoCyuo/VPZG0ODnsMPVLfxMAHra7N8NoVKah7oRpaVFV1uzpKq0HoE4H9nIyvp+5w8uvG4rqoYP9el92/Bts= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602261664169995.5710727232286; Fri, 9 Oct 2020 09:41:04 -0700 (PDT) Received: from localhost ([::1]:52884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQvS1-000446-Ij for importer@patchew.org; Fri, 09 Oct 2020 12:41:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQv4c-0004cO-M7 for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:25717) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kQv4X-0003My-6f for qemu-devel@nongnu.org; Fri, 09 Oct 2020 12:16:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-338-KUmJUotTPd-My3KArqdUNw-1; Fri, 09 Oct 2020 12:16:42 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 88D7780B70D; Fri, 9 Oct 2020 16:16:41 +0000 (UTC) Received: from scv.redhat.com (ovpn-112-203.rdu2.redhat.com [10.10.112.203]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBE6521E95; Fri, 9 Oct 2020 16:16:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602260204; 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=xfLHFOeSxVhEBa0V5rzKpvO9KzbAZlKvh/1PPXfZ3Wc=; b=BwlbWNW+88ILG984iEtLaDcaqdnvS84tMRziRzj45Wx9YNWEYGno1+ll7lpui7wFHZ2r4H S/3qwT19fcHOwSp++Pv2tvispCbnGKnYdx9M/lX96xNM3ul1PjxtBaoqnkh5zpB3Url8u7 Zi2I+xKgRsnPgr0527hY2I5U1vewlJ4= X-MC-Unique: KUmJUotTPd-My3KArqdUNw-1 From: John Snow To: qemu-devel@nongnu.org Subject: [PATCH v6 36/36] qapi/visit.py: add type hint annotations Date: Fri, 9 Oct 2020 12:15:58 -0400 Message-Id: <20201009161558.107041-37-jsnow@redhat.com> In-Reply-To: <20201009161558.107041-1-jsnow@redhat.com> References: <20201009161558.107041-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/09 02:34:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Markus Armbruster , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Reviewed-by: Markus Armbruster --- scripts/qapi/mypy.ini | 5 --- scripts/qapi/visit.py | 73 +++++++++++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 22 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 83f19813553..74fc6c82153 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -28,8 +28,3 @@ check_untyped_defs =3D False disallow_untyped_defs =3D False disallow_incomplete_defs =3D False check_untyped_defs =3D False - -[mypy-qapi.visit] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 8699e5c09c6..339f1521524 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -13,6 +13,8 @@ See the COPYING file in the top-level directory. """ =20 +from typing import List, Optional + from .common import ( c_enum_const, c_name, @@ -22,10 +24,20 @@ mcgen, ) from .gen import QAPISchemaModularCVisitor, ifcontext -from .schema import QAPISchemaEnumType, QAPISchemaObjectType +from .schema import ( + QAPISchema, + QAPISchemaEnumMember, + QAPISchemaEnumType, + QAPISchemaFeature, + QAPISchemaObjectType, + QAPISchemaObjectTypeMember, + QAPISchemaType, + QAPISchemaVariants, +) +from .source import QAPISourceInfo =20 =20 -def gen_visit_decl(name, scalar=3DFalse): +def gen_visit_decl(name: str, scalar: bool =3D False) -> str: c_type =3D c_name(name) + ' *' if not scalar: c_type +=3D '*' @@ -37,7 +49,7 @@ def gen_visit_decl(name, scalar=3DFalse): c_name=3Dc_name(name), c_type=3Dc_type) =20 =20 -def gen_visit_members_decl(name): +def gen_visit_members_decl(name: str) -> str: return mcgen(''' =20 bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **er= rp); @@ -45,7 +57,10 @@ def gen_visit_members_decl(name): c_name=3Dc_name(name)) =20 =20 -def gen_visit_object_members(name, base, members, variants): +def gen_visit_object_members(name: str, + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> st= r: ret =3D mcgen(''' =20 bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **er= rp) @@ -125,7 +140,7 @@ def gen_visit_object_members(name, base, members, varia= nts): return ret =20 =20 -def gen_visit_list(name, element_type): +def gen_visit_list(name: str, element_type: QAPISchemaType) -> str: return mcgen(''' =20 bool visit_type_%(c_name)s(Visitor *v, const char *name, @@ -159,7 +174,7 @@ def gen_visit_list(name, element_type): c_name=3Dc_name(name), c_elt_type=3Delement_type.c_name()) =20 =20 -def gen_visit_enum(name): +def gen_visit_enum(name: str) -> str: return mcgen(''' =20 bool visit_type_%(c_name)s(Visitor *v, const char *name, @@ -174,7 +189,7 @@ def gen_visit_enum(name): c_name=3Dc_name(name)) =20 =20 -def gen_visit_alternate(name, variants): +def gen_visit_alternate(name: str, variants: QAPISchemaVariants) -> str: ret =3D mcgen(''' =20 bool visit_type_%(c_name)s(Visitor *v, const char *name, @@ -250,7 +265,7 @@ def gen_visit_alternate(name, variants): return ret =20 =20 -def gen_visit_object(name): +def gen_visit_object(name: str) -> str: return mcgen(''' =20 bool visit_type_%(c_name)s(Visitor *v, const char *name, @@ -285,12 +300,12 @@ def gen_visit_object(name): =20 class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): =20 - def __init__(self, prefix): + def __init__(self, prefix: str): super().__init__( prefix, 'qapi-visit', ' * Schema-defined QAPI visitors', ' * Built-in QAPI visitors', __doc__) =20 - def _begin_system_module(self, name): + def _begin_system_module(self, name: None) -> None: self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "qapi/error.h" @@ -302,7 +317,7 @@ def _begin_system_module(self, name): =20 ''')) =20 - def _begin_user_module(self, name): + def _begin_user_module(self, name: str) -> None: types =3D self._module_basename('qapi-types', name) visit =3D self._module_basename('qapi-visit', name) self._genc.preamble_add(mcgen(''' @@ -319,18 +334,34 @@ def _begin_user_module(self, name): ''', types=3Dtypes)) =20 - def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): + def visit_enum_type(self, + name: str, + info: QAPISourceInfo, + ifcond: List[str], + features: List[QAPISchemaFeature], + members: List[QAPISchemaEnumMember], + prefix: Optional[str]) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name, scalar=3DTrue)) self._genc.add(gen_visit_enum(name)) =20 - def visit_array_type(self, name, info, ifcond, element_type): + def visit_array_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: List[str], + element_type: QAPISchemaType) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_list(name, element_type)) =20 - def visit_object_type(self, name, info, ifcond, features, - base, members, variants): + def visit_object_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: List[str], + features: List[QAPISchemaFeature], + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> None: # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return @@ -345,13 +376,21 @@ def visit_object_type(self, name, info, ifcond, featu= res, self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_object(name)) =20 - def visit_alternate_type(self, name, info, ifcond, features, variants): + def visit_alternate_type(self, + name: str, + info: QAPISourceInfo, + ifcond: List[str], + features: List[QAPISchemaFeature], + variants: QAPISchemaVariants) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_alternate(name, variants)) =20 =20 -def gen_visit(schema, output_dir, prefix, opt_builtins): +def gen_visit(schema: QAPISchema, + output_dir: str, + prefix: str, + opt_builtins: bool) -> None: vis =3D QAPISchemaGenVisitVisitor(prefix) schema.visit(vis) vis.write(output_dir, opt_builtins) --=20 2.26.2