From nobody Thu Apr 18 14:32:38 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=1600209757; cv=none; d=zohomail.com; s=zohoarc; b=S61szdwp0Jb6HUgYg/UohYpQ2bzTiPvbez/M66jXkuZFHh/1Ap8JsV/VTsWPlo4QxIPWi+lZvCTp650duKxYeHQ8QPajxl8ORr2lK+h8QVOFlhZ6S1YIduN/a4SPQHqcW8pSYYp+D08pqggHLf88ERIpOOEqThCHbb/pR5Eiuy4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600209757; 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=LERjw7jE23yWXtnh82ssGumspChAbbGgfKmaV5CO6KU=; b=ngbUNcCbAuZ+k70qJHLClCfLdVSlnBGQVCFl/Y+sn2qmUvBS4VTYDjMA5kUdaGId61Y9hG04MPItFdYG21J71LVnZAPuhIGkP4fqGUKRBqRs4kPu+qeIJqFqqMxpAHVB/CCi1GlmoBFWFpQdYQ+GmrdOWD8JGucaMBcU8Ubf68A= 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 1600209757709736.9714129189642; Tue, 15 Sep 2020 15:42:37 -0700 (PDT) Received: from localhost ([::1]:51002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJel-00085H-Oz for importer@patchew.org; Tue, 15 Sep 2020 18:42:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59060) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJcw-0006Ex-1V for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:40:43 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:40451 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJct-0002Vo-Kg for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:40:41 -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-362-7b3j0tMjNV-5Vo47KFx7ag-1; Tue, 15 Sep 2020 18:40:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CCA9D1891E8A; Tue, 15 Sep 2020 22:40:30 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8F6C81C54; Tue, 15 Sep 2020 22:40:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209636; 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=LERjw7jE23yWXtnh82ssGumspChAbbGgfKmaV5CO6KU=; b=SZiE/VgdF1FPf5d6V6BaVm0t6gppnU1SKd3ECyG8K0TbBjrTe8AQRRNQjs04Op8I6riSTh EoaHfzPKw7hWe7IpnjGIaihEMEuzXlC7fHjs3+DQiKIkgEg2RTwtKMQHe7+G+xup4AdThu /Bp5/cWKiTXpcfzVA/WMXyYFlYGQr1A= X-MC-Unique: 7b3j0tMjNV-5Vo47KFx7ag-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 01/37] python: Require 3.6+ Date: Tue, 15 Sep 2020 18:39:51 -0400 Message-Id: <20200915224027.2529813-2-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:40:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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" Python 3.5 is now EOL. Python 3.6 brings with it several nice things: - Literal string interpolation (PEP 498) - Syntax for variable annotations (PEP 526) - Preserving keyword argument order (PEP 468) * PEP 526 in particular will allow us to convert the QAPI module to the statically typed subset of the Python language. These static type hints improve the interactive editing experience in IDEs and help make refactoring and adding new features faster, easier and safer. *Note: **kwargs is now guaranteed to preserve keyword ordering, but dict itself is still allowed to have an arbitrary order based on implementation. It is not until Python 3.7 that the dict type guarantees insertion order. Signed-off-by: John Snow --- docs/conf.py | 4 ++-- configure | 6 +++--- .readthedocs.yml | 2 +- .travis.yml | 8 -------- tests/qemu-iotests/iotests.py | 2 -- 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 0dbd90dc11..8aeac40124 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -36,9 +36,9 @@ # In newer versions of Sphinx this will display nicely; in older versions # Sphinx will also produce a Python backtrace but at least the information # gets printed... -if sys.version_info < (3,5): +if sys.version_info < (3,6): raise ConfigError( - "QEMU requires a Sphinx that uses Python 3.5 or better\n") + "QEMU requires a Sphinx that uses Python 3.6 or better\n") =20 # The per-manual conf.py will set qemu_docdir for a single-manual build; # otherwise set it here if this is an entire-manual-set build. diff --git a/configure b/configure index ce27eafb0a..33292500e7 100755 --- a/configure +++ b/configure @@ -913,7 +913,7 @@ fi =20 : ${make=3D${MAKE-make}} =20 -# We prefer python 3.x. A bare 'python' is traditionally +# We prefer python 3.6+. A bare 'python' is traditionally # python 2.x, but some distros have it as python 3.x, so # we check that too python=3D @@ -1961,8 +1961,8 @@ fi =20 # Note that if the Python conditional here evaluates True we will exit # with status 1 which is a shell 'false' value. -if ! $python -c 'import sys; sys.exit(sys.version_info < (3,5))'; then - error_exit "Cannot use '$python', Python >=3D 3.5 is required." \ +if ! $python -c 'import sys; sys.exit(sys.version_info < (3,6))'; then + error_exit "Cannot use '$python', Python >=3D 3.6 is required." \ "Use --python=3D/path/to/python to specify a supported Python." fi =20 diff --git a/.readthedocs.yml b/.readthedocs.yml index 8355dbc634..7fb7b8dd61 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -17,4 +17,4 @@ formats: all # we require for other Python in our codebase (our conf.py # enforces this, and some code needs it.) python: - version: 3.5 + version: 3.6 diff --git a/.travis.yml b/.travis.yml index 65341634d0..0dca15a5e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -267,14 +267,6 @@ jobs: =20 =20 # Python builds - - name: "GCC Python 3.5 (x86_64-softmmu)" - env: - - CONFIG=3D"--target-list=3Dx86_64-softmmu" - - CACHE_NAME=3D"${TRAVIS_BRANCH}-linux-gcc-default" - language: python - python: 3.5 - - - name: "GCC Python 3.6 (x86_64-softmmu)" env: - CONFIG=3D"--target-list=3Dx86_64-softmmu" diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 91e4a57126..f48460480a 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -40,8 +40,6 @@ from qemu import qtest from qemu.qmp import QMPMessage =20 -assert sys.version_info >=3D (3, 6) - # Use this logger for logging messages directly from the iotests module logger =3D logging.getLogger('qemu.iotests') logger.addHandler(logging.NullHandler()) --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600209757; cv=none; d=zohomail.com; s=zohoarc; b=ETSut0hJYg/iZavKA6PJT1kQCEOa9NzfjxIk4ytBBI1lvemR9h6L/hNhJwCAkRnN/kGglq3Wmpgw9xWdMXxf8SWqG+EJP8lTvaRKDQEU03dak11sUfjhTWZEpp6t3pkvwT4s+5IdWfslkW0555wK1L6j8KdZbcgdE8xSGTO7l4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600209757; 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=mZWXq7GO5mx558feE0Kb1/8jgJE3wrTyvSY41kIzuWY=; b=HwAuiz0DEQ7590H+szJZes/Z84MhOILJWyfSp2AkrEunDbqO512NgTRmNHmTR3osC67+k6OI0gB8Hxkjad06JX3LOw7edt+ACu8MznYr9QucTaJDy8nLktXEP6qJv4kmO1IodiatbvbYL917ApKA2XNcKkLYj1ja1DMhirQbLVk= 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 160020975785527.490355714052498; Tue, 15 Sep 2020 15:42:37 -0700 (PDT) Received: from localhost ([::1]:51076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJem-00087E-GT for importer@patchew.org; Tue, 15 Sep 2020 18:42:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59062) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJcw-0006F8-Al for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:40:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJcu-0002Vj-0k for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:40:41 -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-88-SHta24QrMUuihamPPzCRvA-1; Tue, 15 Sep 2020 18:40:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0172C64090; Tue, 15 Sep 2020 22:40:32 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C2DF81C54; Tue, 15 Sep 2020 22:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209634; 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=mZWXq7GO5mx558feE0Kb1/8jgJE3wrTyvSY41kIzuWY=; b=Z3FNkb3aCOSn//V/w5/KOK8WbI6ff2yFJrCZqpqypgTpv6lRQhE3BTtMPuw8og6h0L5XkO e4g6f2zPklUlAsAbcLc14N2K/gJs0kiO8EDfZ+vYKF9doHJSDxpflR3KiPIni8ilTZ7zfJ vXyTY0hhb6wF9wTi4Ec6F7lRT+qxA2Y= X-MC-Unique: SHta24QrMUuihamPPzCRvA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 02/37] [DO-NOT-MERGE] qapi: add debugging tools Date: Tue, 15 Sep 2020 18:39:52 -0400 Message-Id: <20200915224027.2529813-3-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.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/09/15 18:01:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 adds some really childishly simple debugging tools. Maybe they're interesting for someone else, too? Signed-off-by: John Snow --- scripts/qapi/debug.py | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 scripts/qapi/debug.py diff --git a/scripts/qapi/debug.py b/scripts/qapi/debug.py new file mode 100644 index 0000000000..bacf5ee180 --- /dev/null +++ b/scripts/qapi/debug.py @@ -0,0 +1,78 @@ +""" +Small debugging facilities for mypy static analysis work. +(C) 2020 John Snow, for Red Hat, Inc. +""" + +import inspect +import json +from typing import Dict, List, Any +from types import FrameType + + +OBSERVED_TYPES: Dict[str, List[str]] =3D {} + + +# You have no idea how long it took to find this return type... +def caller_frame() -> FrameType: + """ + Returns the stack frame of the caller's caller. + e.g. foo() -> caller() -> caller_frame() return's foo's stack frame. + """ + stack =3D inspect.stack() + caller =3D stack[2].frame + if caller is None: + msg =3D "Python interpreter does not support stack frame inspectio= n" + raise RuntimeError(msg) + return caller + + +def _add_type_record(name: str, typestr: str) -> None: + seen =3D OBSERVED_TYPES.setdefault(name, []) + if typestr not in seen: + seen.append(typestr) + + +def record_type(name: str, value: Any, dict_names: bool =3D False) -> None: + """ + Record the type of a variable. + + :param name: The name of the variable + :param value: The value of the variable + """ + _add_type_record(name, str(type(value))) + + try: + for key, subvalue in value.items(): + subname =3D f"{name}.{key}" if dict_names else f"{name}.[dict_= value]" + _add_type_record(subname, str(type(subvalue))) + return + except AttributeError: + # (Wasn't a dict or anything resembling one.) + pass + + # str is iterable, but not in the way we want! + if isinstance(value, str): + return + + try: + for elem in value: + _add_type_record(f"{name}.[list_elem]", str(type(elem))) + except TypeError: + # (Wasn't a list or anything else iterable.) + pass + + +def show_types() -> None: + """ + Print all of the currently known variable types to stdout. + """ + print(json.dumps(OBSERVED_TYPES, indent=3D2)) + + +def record_locals(show: bool =3D False, dict_names: bool =3D False) -> Non= e: + caller =3D caller_frame() + name =3D caller.f_code.co_name + for key, value in caller.f_locals.items(): + record_type(f"{name}.{key}", value, dict_names=3Ddict_names) + if show: + show_types() --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600209888; cv=none; d=zohomail.com; s=zohoarc; b=GCr+L1VG0gDSw4Ys0cV1cdosgEr+D95A0LdTA+wF4JImiZ4N6psbc9p6jMr/DJj3XveEkT8WI8DwTEzjh1eDOpIRDWeRHEkuQyiLABh4LFzsrSeBgNae9rYu3gCwO4HbsVSM8+MuxBqtk1SR/Yv70vP0NTx3ugMlEZ7K+Ch8YyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600209888; 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=637LJ33Schjo+rVEoXhJzcj6gHuGoz/oUV2e76R0FyM=; b=a4kbLxMLSwbfmHVu6mbcOSiJ7LOP4FIwDNZgRp9w+0o6yf1x7a1oecqSwxbeqWvAvAJjJ7l7VNJjQuwS1cBBS+ifWLhWPwZnGjePcqMjTiVv0qBzLQFGENGGm8dqcUOfE2sI202udBoM0/HZllT0VtkbLHNnAgFuaksalj/JV9Y= 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 1600209888963902.619900584913; Tue, 15 Sep 2020 15:44:48 -0700 (PDT) Received: from localhost ([::1]:59662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJgt-0003Bm-TR for importer@patchew.org; Tue, 15 Sep 2020 18:44:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJd5-0006N9-Hu for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:40:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21978) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJd3-0002Xw-JR for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:40: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-57-smTw4yi4NJOAlBsZcbdyvQ-1; Tue, 15 Sep 2020 18:40:44 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DF6678712F6; Tue, 15 Sep 2020 22:40:42 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D33C81C43; Tue, 15 Sep 2020 22:40:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209648; 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=637LJ33Schjo+rVEoXhJzcj6gHuGoz/oUV2e76R0FyM=; b=EoT+NBBKztcG5EH1IwcaHs7PnqjMJhvIzZXZsMBKuH2qayiY4PhiOEUTKMCGiSm9xvIQi4 dIsyONqY2xXittaYK1OFQb1llAlLYJ1b/dt/rspYgS5PlhWGVyWYCw8hX0jB5+D+bKPPu5 +UcG1RuTqVIPDtG775dBeSfqD7C1KuQ= X-MC-Unique: smTw4yi4NJOAlBsZcbdyvQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 03/37] qapi-gen: Separate arg-parsing from generation Date: Tue, 15 Sep 2020 18:39:53 -0400 Message-Id: <20200915224027.2529813-4-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi-gen.py | 87 ++++++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 24 deletions(-) diff --git a/scripts/qapi-gen.py b/scripts/qapi-gen.py index 4b03f7d53b..59becba3e1 100644 --- a/scripts/qapi-gen.py +++ b/scripts/qapi-gen.py @@ -1,9 +1,13 @@ #!/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 script is the main entry point for generating C code from the QAPI sc= hema. +""" =20 import argparse import re @@ -11,21 +15,65 @@ =20 from qapi.commands import gen_commands from qapi.doc import gen_doc +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): +DEFAULT_OUTPUT_DIR =3D '' +DEFAULT_PREFIX =3D '' + + +def generate(schema_file: str, + output_dir: str, + prefix: str, + unmask: bool =3D False, + builtins: bool =3D False) -> None: + """ + generate uses a given schema to produce C code in 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. + """ + match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', prefix) + if match and match.end() !=3D len(prefix): + msg =3D "funny character '{:s}' in prefix '{:s}'".format( + prefix[match.end()], prefix) + raise QAPIError('', None, msg) + + 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) + gen_doc(schema, output_dir, prefix) + + +def main() -> int: + """ + gapi-gen shell script entrypoint. + 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=3DDEFAULT_OUTPUT_DIR, 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=3DDEFAULT_PREFIX, help=3D"prefix for symbols") parser.add_argument('-u', '--unmask-non-abi-names', action=3D'store_tr= ue', dest=3D'unmask', @@ -33,26 +81,17 @@ 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) - 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) - gen_doc(schema, args.output_dir, args.prefix) + 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 Thu Apr 18 14:32:38 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=1600209765; cv=none; d=zohomail.com; s=zohoarc; b=BJvNWDhNAXnMWe/bn2R0ucj4usg0CJd+8k353XUWmkmWeHo2pD4vBXr14at2GRV8UkO4mj72TF+MBTEjXFNYFUgHJQpb3r6WARP+PbpnAlVOkCgaoANfq7NlltZ9pV9wj9FZh42OcyZ57ldkAcWkUoPdgdXQ3dU5rH7iQ65dD7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600209765; 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=pKWXybqPMTufCJpdDD0MNwo0LrgnbAsBE/Dw/0uGbLY=; b=oJ7jC8MqgyKloIwxpMywBRctKm+/MN+wCT0g2j0pPAiUyjLoarOlV5jDwk9GCkRNKfitPsEhF19TVeWI3tJkOKyQycO+o3pmtUulP5TFXhOPwYprAdyhuw/NcjDYXX7vL2ZIi/w2TQLSNP/Yv9F/vaQHdnn/uqt07BrW5MJlTHc= 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 1600209765717617.986268303137; Tue, 15 Sep 2020 15:42:45 -0700 (PDT) Received: from localhost ([::1]:51912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJeu-0008Rj-H9 for importer@patchew.org; Tue, 15 Sep 2020 18:42:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdA-0006Wx-L5 for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:40:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58037) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJd7-0002Ze-Fp for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:40:56 -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-281-U612FO2aOfSTQoSKjOmwXg-1; Tue, 15 Sep 2020 18:40:50 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 68A4D8B5DE1; Tue, 15 Sep 2020 22:40:45 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15FB581C43; Tue, 15 Sep 2020 22:40:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209652; 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=pKWXybqPMTufCJpdDD0MNwo0LrgnbAsBE/Dw/0uGbLY=; b=Ni9fraw6MxyiopUaUD2VCpaeKXLsBGhmCls97NNN7A5ErIFUgwr3vC3CYVnFaFEO0kgfhg DJGMihNTQyejpTqDQgJVcXYNgBvbUGoTz7pi/qLOHytf94+J8Cp4W7DqpTenJHlfiwQfJ0 sb5kbaO1kacG+KSt9fPGwnRgyIwf4w0= X-MC-Unique: U612FO2aOfSTQoSKjOmwXg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 04/37] qapi: move generator entrypoint into module Date: Tue, 15 Sep 2020 18:39:54 -0400 Message-Id: <20200915224027.2529813-5-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 module, only leaving a very tiny entrypoint shim outside of the module. As a result, all of the include statements are reworked to be module-aware, as explicit relative imports. This is done primarily for the benefit of python tooling (pylint, mypy, flake8, et al) which otherwise has trouble consistently resolving "qapi.x" to mean "a sibling file in this folder." Signed-off-by: John Snow --- scripts/qapi-gen.py | 94 +++----------------------------------- scripts/qapi/commands.py | 4 +- scripts/qapi/doc.py | 2 +- scripts/qapi/events.py | 8 ++-- scripts/qapi/expr.py | 4 +- scripts/qapi/gen.py | 4 +- scripts/qapi/introspect.py | 8 ++-- scripts/qapi/parser.py | 4 +- scripts/qapi/schema.py | 8 ++-- scripts/qapi/script.py | 91 ++++++++++++++++++++++++++++++++++++ scripts/qapi/types.py | 6 +-- scripts/qapi/visit.py | 6 +-- 12 files changed, 124 insertions(+), 115 deletions(-) create mode 100644 scripts/qapi/script.py diff --git a/scripts/qapi-gen.py b/scripts/qapi-gen.py index 59becba3e1..e649f8dd44 100644 --- a/scripts/qapi-gen.py +++ b/scripts/qapi-gen.py @@ -1,97 +1,15 @@ #!/usr/bin/env python3 - -# 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 +QAPI code generation execution shim. =20 -This script is the main entry point for generating C code from the QAPI sc= hema. +This file exists primarily to facilitate the running of the QAPI code +generator without needing to install the python module to the current +execution environment. """ =20 -import argparse -import re import sys =20 -from qapi.commands import gen_commands -from qapi.doc import gen_doc -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 - - -DEFAULT_OUTPUT_DIR =3D '' -DEFAULT_PREFIX =3D '' - - -def generate(schema_file: str, - output_dir: str, - prefix: str, - unmask: bool =3D False, - builtins: bool =3D False) -> None: - """ - generate uses a given schema to produce C code in 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. - """ - match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', prefix) - if match and match.end() !=3D len(prefix): - msg =3D "funny character '{:s}' in prefix '{:s}'".format( - prefix[match.end()], prefix) - raise QAPIError('', None, msg) - - 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) - gen_doc(schema, output_dir, prefix) - - -def main() -> int: - """ - gapi-gen shell script entrypoint. - 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=3DDEFAULT_OUTPUT_DIR, - help=3D"write output to directory OUTPUT_DIR") - parser.add_argument('-p', '--prefix', action=3D'store', - default=3DDEFAULT_PREFIX, - 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() - - 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 - +from qapi import script =20 if __name__ =3D=3D '__main__': - sys.exit(main()) + sys.exit(script.main()) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 3cf9e1110b..ce5926146a 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/doc.py b/scripts/qapi/doc.py index 92f584edcf..cbf7076ed9 100644 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -5,7 +5,7 @@ """This script produces the documentation of a qapi schema in texinfo form= at""" =20 import re -from qapi.gen import QAPIGenDoc, QAPISchemaVisitor +from .gen import QAPIGenDoc, QAPISchemaVisitor =20 =20 MSG_FMT =3D """ diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index b544af5a1c..0467272438 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 2942520399..03b31ecfc1 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 bf5552a4e7..8df19a0df0 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 23652be810..2a34cd1e8e 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/parser.py b/scripts/qapi/parser.py index 165925ca72..327cf05736 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 78309a00f0..a835ee6fde 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/script.py b/scripts/qapi/script.py new file mode 100644 index 0000000000..3f8338ade8 --- /dev/null +++ b/scripts/qapi/script.py @@ -0,0 +1,91 @@ +# 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 .commands import gen_commands +from .doc import gen_doc +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 + + +DEFAULT_OUTPUT_DIR =3D '' +DEFAULT_PREFIX =3D '' + + +def generate(schema_file: str, + output_dir: str, + prefix: str, + unmask: bool =3D False, + builtins: bool =3D False) -> None: + """ + generate uses a given schema to produce C code in 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. + """ + match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', prefix) + if match and match.end() !=3D len(prefix): + msg =3D "funny character '{:s}' in prefix '{:s}'".format( + prefix[match.end()], prefix) + raise QAPIError('', None, msg) + + 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) + gen_doc(schema, output_dir, prefix) + + +def main() -> int: + """ + gapi-gen shell script entrypoint. + 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=3DDEFAULT_OUTPUT_DIR, + help=3D"write output to directory OUTPUT_DIR") + parser.add_argument('-p', '--prefix', action=3D'store', + default=3DDEFAULT_PREFIX, + 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() + + 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 diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 3640f17cd6..ca9a5aacb3 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 cdabc5fa28..7850f6e848 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 Thu Apr 18 14:32:38 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=1600210022; cv=none; d=zohomail.com; s=zohoarc; b=Gf/IZfIJ4R0wwfwkqDvvPcae+iH8Sqa4XmG4VxOLIHIbiKxYg65Umzb3lbi8pT9FUlGJ7t3xmGRERzT+OyUE98LrjaJSVSfIRoBKivCNMkDrlyidwdBi6beJZGlYL3CQajigE2SOcSzF0SO+7FF/sbDkYZBQEpIu8WQ+CZQsOUU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210022; 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=2CGutam314veshLM3LV7R/XJUvm4PgxBvYBceBQuyHM=; b=n80uJPvWp6DbvHa+rF2eR1h6YPNgMQWI4amMGVbRHl5hvkWfPjQ+BKoefe5n5agTTRaeykmEFGspJQKylP3EeYqZ4Py3u7v9sNzLSn6oOeudLw3Bw7dKoFvSJVzT3FPzpaEgKkkRq4/allbxzUlhtLA0gktuECbLsWbVVI0+jos= 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 16002100226651013.7451748372172; Tue, 15 Sep 2020 15:47:02 -0700 (PDT) Received: from localhost ([::1]:39686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJj3-0006bR-FO for importer@patchew.org; Tue, 15 Sep 2020 18:47:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdC-0006Zh-7D for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:40:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdA-0002ag-5a for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:40:57 -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-S0YOFtolO6yoCsc-sxjpRg-1; Tue, 15 Sep 2020 18:40:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F2571902ED1; Tue, 15 Sep 2020 22:40:46 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 92B2A81C43; Tue, 15 Sep 2020 22:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209655; 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=2CGutam314veshLM3LV7R/XJUvm4PgxBvYBceBQuyHM=; b=fLWr+OQEICQjhOklF8kqmfibNY7+qitaq1uVTNWMjdR04OnqNfwh5qJ2wb9FOU/zoMEdOG ZQqHQGh7cozvtspUju7ZRze5fezXTFC8V81zhNvBY2laUHR/RBKtueyK1ZORkCMHayWbxP 0WjN5A/ryzS4rNzFie2xLSw+4x2Sldg= X-MC-Unique: S0YOFtolO6yoCsc-sxjpRg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 05/37] qapi: Remove wildcard includes Date: Tue, 15 Sep 2020 18:39:55 -0400 Message-Id: <20200915224027.2529813-6-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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" Wildcard includes become hard to manage when refactoring and dealing with circular dependencies with strictly typed mypy. Remove them and include things explicitly by name instead. Signed-off-by: John Snow --- scripts/qapi/commands.py | 6 +++++- 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, 42 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index ce5926146a..e1df0e341f 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -13,7 +13,11 @@ 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 0467272438..6b3afa14d7 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 8df19a0df0..11472ba043 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 2a34cd1e8e..b036fcf9ce 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 ca9a5aacb3..53b47f9e58 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 7850f6e848..ea277e7704 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 Thu Apr 18 14:32:38 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=1600209900; cv=none; d=zohomail.com; s=zohoarc; b=EyhpB8hP2qWLEv1BJAzqZtGWP2hfjnzlJPl0extdL+RGb5Qzm3KUpnL8Fyb9p6PFcsTtrPiLcMYFNCCeSkQYn0LedOP4MGgXGpw9ZnY+Muy2V0cXwRE0xO07t3PzXqpHxrFkMaffsVQnJZEhnzSgmADs+oQoJ38t1V/8JbF5q7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600209900; 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=sV7DeP8u+LoeKvhOOaEL4L2bfZhEJsCamxKagVcd3e4=; b=G7KA7S+RW4SbtNGYmtJIOUAJiTdQCJfQxMAh+/W/oxg9we1FkgkPN2N7QedQBMANmeN8k1AXvs6rHOZJdZOJcy2CwAiqqn1vgPD8fxaXCfWLiQjTxwwj4vhzWz8iN03KMlGaEwWHnbFUUFJHbEdCKot+1IZqG7A0opbKPyJT1xU= 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 1600209900858817.9694092149963; Tue, 15 Sep 2020 15:45:00 -0700 (PDT) Received: from localhost ([::1]:60284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJh5-0003RB-Mm for importer@patchew.org; Tue, 15 Sep 2020 18:44:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdG-0006cg-Bk for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:03 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:24532 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdE-0002cS-3f for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:01 -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-235-zMokrybSP1mCeGy44QhRrA-1; Tue, 15 Sep 2020 18:40:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 96A49191E2A6; Tue, 15 Sep 2020 22:40:47 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id A95A581C43; Tue, 15 Sep 2020 22:40:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209657; 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=sV7DeP8u+LoeKvhOOaEL4L2bfZhEJsCamxKagVcd3e4=; b=Swayl9bM7Ih7vdyxWtvBMm3eq/Q2BhjAt9t/tOkaud4oyerUUGH+PmN30/R7gciHtGbJgh hYxouHa6SfnlPGp+XK2aDcN5HLA8afbc4Nc7lQBWX0x8O2aQGPsX+r/oEqJJq1auHa3xoF hNF9Cy+UX6KBsjx0mR2GzpM6jMol228= X-MC-Unique: zMokrybSP1mCeGy44QhRrA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 06/37] qapi: delint using flake8 Date: Tue, 15 Sep 2020 18:39:56 -0400 Message-Id: <20200915224027.2529813-7-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:40:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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. Signed-off-by: John Snow --- scripts/qapi/.flake8 | 2 ++ scripts/qapi/commands.py | 3 ++- scripts/qapi/schema.py | 8 +++++--- scripts/qapi/visit.py | 15 ++++++++++----- 4 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 scripts/qapi/.flake8 diff --git a/scripts/qapi/.flake8 b/scripts/qapi/.flake8 new file mode 100644 index 0000000000..45d8146f3f --- /dev/null +++ b/scripts/qapi/.flake8 @@ -0,0 +1,2 @@ +[flake8] +extend-ignore =3D E722 # Pylint handles this, but smarter. \ No newline at end of file diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index e1df0e341f..2e4b4de0fa 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -69,7 +69,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 a835ee6fde..b77e0e56b2 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 @@ -821,7 +821,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() @@ -965,7 +965,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 ea277e7704..31bf46e7f7 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -31,7 +31,8 @@ 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 +126,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 +160,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 +175,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 +251,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 Thu Apr 18 14:32:38 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=1600209884; cv=none; d=zohomail.com; s=zohoarc; b=Wak+OTzEnHunNI9gXO5iTlZjO3hvur0bZyas4YDR1YYVrMmK/aUd2B3Aq5kDwGWqGx4aU5ObSRBMXGNNXwUWRg0A90yavd/qerbtFo4MbvUxzTyXxRCx8h7on1RUUWcZ8oVWQ7BHIjvWJX4pE5udcBgbvIUU5rZCcy/G6JP6Q2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600209884; 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=lHVjiYIhCkWZfXxIpMKrKBC9TmoiCUk3ue91mlAbbaU=; b=SNXD2PVYQRGCkQY4mtg6OYjXzL5SbwtupfXCOvWJahxLXR1odQl25urafpZJENKyss5PmkmfXU423PnJMa0yfYc/z077ayumh9LljxSoO+iVTkciCLvvkVjZMJU0s+DoR/Kw/qKlMCUTh0QQhcBhzCUch79E4GOOT6Gig3HvGxI= 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 1600209884562719.2588490796688; Tue, 15 Sep 2020 15:44:44 -0700 (PDT) Received: from localhost ([::1]:59266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJgp-0002zp-BG for importer@patchew.org; Tue, 15 Sep 2020 18:44:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdL-0006iH-Pr for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:08 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:53078 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdE-0002ck-6C for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:07 -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-282-7gylv0gjNwa4Qj59-JM-8g-1; Tue, 15 Sep 2020 18:40:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DDADF89153D; Tue, 15 Sep 2020 22:40:48 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id C15FF81C43; Tue, 15 Sep 2020 22:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209659; 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=lHVjiYIhCkWZfXxIpMKrKBC9TmoiCUk3ue91mlAbbaU=; b=GHwtqBngZGvFHF2Wc8bPE7xqnl+Tx0f6sRTYkDANUHXq747PsbU9Yaomg/+fJf1iYSSwJj +3Og9KeiSH2vWvXvtUcjW4SD8seoLhTCiwxao/6vVY5dVq+SE5Pm2GxcdfmfW7XFSLnXTs 7UUFZlF3fUQw1wdP+hnl4AFfH0E7Mc4= X-MC-Unique: 7gylv0gjNwa4Qj59-JM-8g-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 07/37] qapi: add pylintrc Date: Tue, 15 Sep 2020 18:39:57 -0400 Message-Id: <20200915224027.2529813-8-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:40:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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" Add a skeleton pylintrc file. Right now, it ignores quite a few things. Files 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 now. Due to some bugs in different versions of pylint (2.5.x), pylint does not correctly recognize when it is being run from "inside" a module, and must be run *outside* of the module. Therefore, to run it, you must: > cd :/qemu/scripts > pylint qapi/ --rcfile=3Dqapi/pylintrc Signed-off-by: John Snow --- scripts/qapi/pylintrc | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 scripts/qapi/pylintrc diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc new file mode 100644 index 0000000000..c2bbb8e8e1 --- /dev/null +++ b/scripts/qapi/pylintrc @@ -0,0 +1,74 @@ +[MASTER] + +# Add files or directories matching the regex patterns to the blacklist. T= he +# regex matches against base names, not paths. +ignore-patterns=3Dcommon.py, + doc.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 imports when computing similarities. +ignore-imports=3Dyes + +[TYPECHECK] + +[CLASSES] + +[IMPORTS] + +[DESIGN] + +[EXCEPTIONS] --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600210040; cv=none; d=zohomail.com; s=zohoarc; b=gCYr70yObD3Te5lk4wIYmPybpURiz68nKurpMgTvIVcie7OttBEPJEGoFlgCEhborzWm3vIZUYagtmUu6kdY+rT4fLWmfYQJA0v3j05VzHLAm35IHA1Xl4XLvoonzwX+sj+Rt5Um4KZ9pE1mew/VTF2bblTQdSCiD9yj5c70GBA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210040; 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=aRdnMxUZCvKhJFEyktCZRDxLPoMbsyt4W46aFVj7qDo=; b=LLs/x71Lvw1vvtCYnGhMrVGnsJmQ0Fy81+TNURi3CF5jZispLafqjZv3rkichdtOOy2UIRZxMWl1I9bXVNOdSGtl1hUltfhEySU1rbiLfTvuWChnocIFRQPDweQw7OwJ/qMwfN5+ibYvaUt671JTJFmQiH3VGmfeqAIn9ys5LfU= 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 1600210040302716.394884446029; Tue, 15 Sep 2020 15:47:20 -0700 (PDT) Received: from localhost ([::1]:40456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJjL-0006uC-7J for importer@patchew.org; Tue, 15 Sep 2020 18:47:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59254) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdK-0006hS-W0 for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:07 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:52646 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdE-0002cP-5v for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:06 -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-307-vpfynQVbMNCWonMnEZYyCw-1; Tue, 15 Sep 2020 18:40:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 875FE884E45; Tue, 15 Sep 2020 22:40:50 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2388B81C4E; Tue, 15 Sep 2020 22:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209657; 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=aRdnMxUZCvKhJFEyktCZRDxLPoMbsyt4W46aFVj7qDo=; b=A/C6/ylKPhXLWwmtP1XlRdcTVl42Fv2bR63jThZfjshtLW/HuRg82Si1WqNgv9VPUiaC+/ Grj6sPdoKmWzD873Xnpl8GbWeTscX2kzLYu8+yX+2a8pdjjbn5tdeRQAwANd+/lf3tNCIL Qi1AI0vgpTlUZfvGV9hryP4F8hnazQg= X-MC-Unique: vpfynQVbMNCWonMnEZYyCw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 08/37] qapi/common.py: Remove python compatibility workaround Date: Tue, 15 Sep 2020 18:39:58 -0400 Message-Id: <20200915224027.2529813-9-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:40:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- 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 ba35abea47..4fb265a8bf 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.subn(r'^(?!(#|$))', indent, raw, flags=3Dre.MULTILIN= E) return re.sub(re.escape(eatspace) + r' *', '', raw) =20 =20 --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600210248; cv=none; d=zohomail.com; s=zohoarc; b=gvYwdk6mwDLxwGxEPLauo6AaNrzMmQVUgcNuEJmW0MCjg7BAJdXNbYmguDSzbgzgcqtVthOkgknPvQ8WwA6ZRWegkR5KoRcD/FzB9pgKl+eaY2EGs5PtMy72KTNRTeLu0FaJEoJ4fqskgsssh7oYmQpneRdtZooIucJ+ghfbe9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210248; 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=RlAkE9kUDll+q9FsJF+IR9C8l5y0+4+kpYdf5/twi0U=; b=XlisOngqd8poAUHzuLuZ95mWg0z5v02P8OBfSnbjrVwDyxY2ilWnYsQrwtFl7UJtARi75f5xViccReXKHABKeY5oz2HR0+5gn+TtO5XSGAMB2QuZRFT8sbQTsX629ERQj9hx7Nxdiv3r7KN1h/s0NiVHHAm00g9Uk1mXtp3fRGU= 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 1600210248006414.0314085841625; Tue, 15 Sep 2020 15:50:48 -0700 (PDT) Received: from localhost ([::1]:48660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJmg-0001sh-Lr for importer@patchew.org; Tue, 15 Sep 2020 18:50:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdN-0006ji-2L for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdH-0002e7-M2 for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:08 -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-453-F9vyMH9pP2i1nZs6E7WRIw-1; Tue, 15 Sep 2020 18:40:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EAEC98B5DED; Tue, 15 Sep 2020 22:40:51 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id B10C781C43; Tue, 15 Sep 2020 22:40:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209662; 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=RlAkE9kUDll+q9FsJF+IR9C8l5y0+4+kpYdf5/twi0U=; b=Y/qmoZ1KQzN17/w3o1jKjDAR+F2nH1IMBtsSHxRgS9A34AVd5VDdys/xrzBjcKrltvraTA yZ9YICCZWWdcFhgCKmUrx+teOG/1TUftgP6zxKr+IKzpn2LQK0VbSzHPE5NjHL8OR01x5A 7qCfG5iEBfF4G0prkI92kVyVWjdNwLk= X-MC-Unique: F9vyMH9pP2i1nZs6E7WRIw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 09/37] qapi/common.py: Add indent manager Date: Tue, 15 Sep 2020 18:39:59 -0400 Message-Id: <20200915224027.2529813-10-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/common.py | 50 +++++++++++++++++++++++++++++------------- scripts/qapi/visit.py | 7 +++--- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 4fb265a8bf..87d87b95e5 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -93,33 +93,53 @@ 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 Indent: + """ + Indent-level management. =20 + :param initial: Initial value, default 0. + """ + def __init__(self, initial: int =3D 0) -> None: + self._level =3D initial =20 -indent_level =3D 0 + def __int__(self) -> int: + """Return the indent as an integer.""" + 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 indent as a string.""" + return ' ' * self._level =20 + def __bool__(self) -> bool: + """True when there is a non-zero indent.""" + return bool(self._level) =20 -def pop_indent(indent_amount=3D4): - global indent_level - indent_level -=3D indent_amount + def push(self, amount: int =3D 4) -> int: + """Push `amount` spaces onto the indent, default four.""" + self._level +=3D amount + return self._level + + def pop(self, amount: int =3D 4) -> int: + """Pop `amount` spaces off of the indent, default four.""" + if self._level < amount: + raise ArithmeticError( + "Can't pop {:d} spaces from {:s}".format(amount, repr(self= ))) + self._level -=3D amount + return self._level + + +INDENT =3D Indent(0) =20 =20 # Generate @code with @kwds interpolated. # Obey indent_level, and strip eatspace. def cgen(code, **kwds): raw =3D code % kwds - if indent_level: - indent =3D genindent(indent_level) - raw, _ =3D re.subn(r'^(?!(#|$))', indent, raw, flags=3Dre.MULTILIN= E) + if INDENT: + raw, _ =3D re.subn(r'^(?!(#|$))', str(INDENT), raw, flags=3Dre.MUL= TILINE) return re.sub(re.escape(eatspace) + r' *', '', raw) =20 =20 diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 31bf46e7f7..66ce3dc52e 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -19,8 +19,7 @@ gen_endif, gen_if, mcgen, - pop_indent, - push_indent, + INDENT, ) from .gen import QAPISchemaModularCVisitor, ifcontext from .schema import QAPISchemaObjectType @@ -68,7 +67,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.push() ret +=3D mcgen(''' if (!visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, errp)) { return false; @@ -77,7 +76,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.pop() ret +=3D mcgen(''' } ''') --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600209886; cv=none; d=zohomail.com; s=zohoarc; b=iFsj6bygFYNSgXFpKticgsnsNXJxeuAdkGu+tKFbw6w5iVHYbMo3EMbi0ZUfpN3v3m3Xm4wPXWGvzsUZJ5Hs7xTjj5z3bvmfSYT6/QXm126OmozqbhiSEB0Iq0x6YvXN4euaJ8XugzzHY9psnXOSUmuMRjrBeHg3ZRgp1GnlJFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600209886; 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=8IBSY3vRRizP/txez2W/6YCzAC6dhjWjy9VZXC09qPI=; b=PWoKIZbSceE0d3PwpIJTsVNOqV78Fpv2znnyW9XyBMBBPNV6h6Oc5uUjnXiCf7tm+CXtGgus/42A2fG7+7R+GNvM055SpuUU8yMz+72axRRJ2Cb4R4khbrDQr4leigWhumCYcEyPm9xxENLkf/Te8shHU2AyfkpolAhHn3LGqDo= 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 1600209886367519.7097376851415; Tue, 15 Sep 2020 15:44:46 -0700 (PDT) Received: from localhost ([::1]:59368 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJgr-00033p-8h for importer@patchew.org; Tue, 15 Sep 2020 18:44:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdR-0006pg-VJ for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:13 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:59564 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdO-0002eb-6d for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:13 -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-563-4CdUYcH_P3iUQQWbe56TmQ-1; Tue, 15 Sep 2020 18:41:05 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A7D001966320; Tue, 15 Sep 2020 22:40:53 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4444F7EEA7; Tue, 15 Sep 2020 22:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209669; 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=8IBSY3vRRizP/txez2W/6YCzAC6dhjWjy9VZXC09qPI=; b=Gu+/a2MuVd20qxvtEGK9I9w2EUIRNuzJwu6AdKotPoj0940mfbWc7NUVmNhASm2dFj/bxU 3neU3hPiB1qgmVQJf0OVOqRt22funz3g3UWkZY0TcrVjC3bCSHWiU45dT/bAy7vfrWjkFT W4JlhCcizEOfNoCf4PsQTywoBwhQHbg= X-MC-Unique: 4CdUYcH_P3iUQQWbe56TmQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 10/37] qapi/common.py: delint with pylint Date: Tue, 15 Sep 2020 18:40:00 -0400 Message-Id: <20200915224027.2529813-11-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:40:43 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/common.py | 16 +++++++--------- scripts/qapi/schema.py | 14 +++++++------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 87d87b95e5..c665e67495 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_'. @@ -89,10 +91,6 @@ def c_name(name, protect=3DTrue): return name =20 =20 -eatspace =3D '\033EATSPACE.' -pointer_suffix =3D ' *' + eatspace - - class Indent: """ Indent-level management. @@ -135,12 +133,12 @@ def pop(self, amount: int =3D 4) -> int: =20 =20 # Generate @code with @kwds interpolated. -# Obey indent_level, and strip eatspace. +# Obey INDENT level, and strip EATSPACE. def cgen(code, **kwds): raw =3D code % kwds if INDENT: raw, _ =3D re.subn(r'^(?!(#|$))', str(INDENT), raw, flags=3Dre.MUL= TILINE) - 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 b77e0e56b2..b4921b46c9 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -18,7 +18,7 @@ import re from collections import OrderedDict =20 -from .common import c_name, pointer_suffix +from .common import c_name, POINTER_SUFFIX 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' @@ -896,7 +896,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'), @@ -909,8 +909,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 Thu Apr 18 14:32:38 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=1600210217; cv=none; d=zohomail.com; s=zohoarc; b=QwJHNRNGY6QxNcmGhJckFaPEEILVOGjWHP8DllNnojen4iAs54bWRWBj3ChQlCM8rvcNtwlYU0dvRF+2imTPgsuMu3fnGOlr2PQ+9Ej1XUhecwXiImkDF79fZ2UA5o+YhfQwG4Mz7qnf8RYKpxj2TufJVF71CwRXSU/95/wwPn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210217; 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=K8bVzKpDcKoTPv50ydKSwWjwSfGqGLmnkcNroffJC0E=; b=i0gP2ZbWT2VTeTAokqn74qwJxSGprQ+wjnhaCu8Cb5WoYUnQgc5SLGnV8LBrueTg9FH+AGNm57QX1BUxZvNeQ9CKszPIqKYfC2cLfGcAnAH4J08UUELP+crF0tc5bTZzwrfzNZxtMbZy4WCOW0CSgnY+V4EWrCmYwAslyetvyJA= 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 1600210217536546.8629877945943; Tue, 15 Sep 2020 15:50:17 -0700 (PDT) Received: from localhost ([::1]:47834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJmC-0001Xm-CO for importer@patchew.org; Tue, 15 Sep 2020 18:50:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59328) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdQ-0006n3-Oq for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23232) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdO-0002ec-3V for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-245-l-zWGfOXPquDLekDMwPDMw-1; Tue, 15 Sep 2020 18:41:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EFDEC8BF88D; Tue, 15 Sep 2020 22:40:54 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED3E87EEA7; Tue, 15 Sep 2020 22:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209669; 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=K8bVzKpDcKoTPv50ydKSwWjwSfGqGLmnkcNroffJC0E=; b=gEmrhjsVXpLie8LeOJUEB0e1Gpm7zPcsIeUqETOaONDcQBtPfLp9g7yV9LIarCo2tcMOco BllohmZaomzuPCUAOLuBjQdD1LgkqQqkY914CTDEXF5glY80u7Szd2gO++V1vDAcaHxFGV y8ViGalxAkvRmpOoHAhEBT4ymK8w0n0= X-MC-Unique: l-zWGfOXPquDLekDMwPDMw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 11/37] qapi/common.py: Replace one-letter 'c' variable Date: Tue, 15 Sep 2020 18:40:01 -0400 Message-Id: <20200915224027.2529813-12-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- 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 c665e67495..4c079755d3 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 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 Thu Apr 18 14:32:38 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=1600210427; cv=none; d=zohomail.com; s=zohoarc; b=kxfukrOS/SJdqtL8/DjUMPq7EUs0DATUYJ4ZL6Juz0fZZnd67kk3ope6W3sKyWPOkulB0oRx+EuJlLbN6m6BHQoi0XyO4jLPAxIfFghg/aQLK4t+gw9dqiiGWDi9LIddVKvVJnaNfF3TE8J6KRaSLrbjCvvwFJJkR9IvQnXqLCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210427; 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=f7xduPIQChib2LGjmWXF/DvwCEymePmAzFOmm84aMSk=; b=klmeo8xesN32ZnXsHqVuP7GaQ4mAncZv+45CBc9uqd2n7cMXTUFIoX1oU+lmVJeCHGxTtXRLIAiqjO+eCI7UPS9sPBfDKPYaCc0DoNXcf2DmPaMQHWCdyOf5yl+4UNV9XvDSecIMJcgRugKfABKalzN5wG3e6FVsn1JJooH+RVo= 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 1600210427316744.3669338747922; Tue, 15 Sep 2020 15:53:47 -0700 (PDT) Received: from localhost ([::1]:56690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJpa-0005IC-36 for importer@patchew.org; Tue, 15 Sep 2020 18:53:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdS-0006qe-GO for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56622) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdQ-0002ew-4J for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-53-DgnVAChNPyK4m27GNdAfLw-1; Tue, 15 Sep 2020 18:41:06 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6DC4D884DF3; Tue, 15 Sep 2020 22:40:56 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 20E7576E16; Tue, 15 Sep 2020 22:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209671; 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=f7xduPIQChib2LGjmWXF/DvwCEymePmAzFOmm84aMSk=; b=bxg4WX+xdVW+DVSqf99bk7dw2HnyZV9BPVseoqaM+Kem/ifFnvlnLAKqutdeI6sQfptsIg dpmA3MOIq9PXhHkd2r9Taeb4b0irzzZjB9smEB1asCjBwEqgvPq9vT+BNttPbXJ2hqnLrp K8bYLvakHfbDBJnwqoXcWxXL42II7Us= X-MC-Unique: DgnVAChNPyK4m27GNdAfLw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 12/37] qapi/common.py: check with pylint Date: Tue, 15 Sep 2020 18:40:02 -0400 Message-Id: <20200915224027.2529813-13-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/pylintrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index c2bbb8e8e1..c800055589 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -2,8 +2,7 @@ =20 # Add files or directories matching the regex patterns to the blacklist. T= he # regex matches against base names, not paths. -ignore-patterns=3Dcommon.py, - doc.py, +ignore-patterns=3Ddoc.py, error.py, expr.py, gen.py, --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600210019; cv=none; d=zohomail.com; s=zohoarc; b=PWReUoQQS7CRPIBZjlmBoJDyWL0JOMvzJ/Wth7JKvxVRmNdmOUGS5XYL24QK4QQAiM52UlNw3xjK9QWuLolMdRs4PpJ5Pd8wQLmrdtHMIF5wvFg3/JbZCyisnOaMnYuAW+PVAbEqfMd3J746h9Vf6mBaLrHIXrbzlErnW7CKajo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210019; 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=zrBk6YK6MU8V9BbMDwXymbJJzmJpFy5SUCQcQwKspTA=; b=Sysn3b8GbkubDIbCGPjS/PeKDGS4qcKWcayKAs1XtxXcJgVisH7ufu6+OudYLNo889ePk4OoVUy/I40g1qTV+VLwqRCZuD2Vx8rHFnThj+5OwphkfBbkRLXmghhmIUN+qrG7+8C+lSKDk9VFwmu2F3GIIvLTGtgzxpMOYEQbDtw= 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 1600210019781383.2422946131693; Tue, 15 Sep 2020 15:46:59 -0700 (PDT) Received: from localhost ([::1]:39444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJj0-0006Va-J6 for importer@patchew.org; Tue, 15 Sep 2020 18:46:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59388) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdY-00073y-2W for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:20 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:49182 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdV-0002fb-V5 for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-170-p2VRsBsIMMeuzBJw4FCttQ-1; Tue, 15 Sep 2020 18:41:15 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 22F1718B9EDF; Tue, 15 Sep 2020 22:40:58 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1EC376E16; Tue, 15 Sep 2020 22:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209676; 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=zrBk6YK6MU8V9BbMDwXymbJJzmJpFy5SUCQcQwKspTA=; b=gnKYuVgsHkehmsljpykhlvph7twzCO6MNjHlnidQslTbmIIblWIlDjJlVsGN6Qwb2M/fR2 uq/KVB2IHtUIE4cuhSs8H2cUeSxMK3Qq1JUsNIpN1g40ucb0xQEZ9EqtheA87Ton5JUgoV j9RUxc25DTrn5Ya3zYCyI0KmT8XwOp4= X-MC-Unique: p2VRsBsIMMeuzBJw4FCttQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 13/37] qapi/common.py: add notational type hints Date: Tue, 15 Sep 2020 18:40:03 -0400 Message-Id: <20200915224027.2529813-14-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:40:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- 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 4c079755d3..af01348b35 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, Union, 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', @@ -134,24 +137,24 @@ def pop(self, amount: int =3D 4) -> int: =20 # Generate @code with @kwds interpolated. # Obey INDENT level, and strip EATSPACE. -def cgen(code, **kwds): +def cgen(code: str, **kwds: Union[str, int]) -> str: raw =3D code % kwds if INDENT: raw, _ =3D re.subn(r'^(?!(#|$))', str(INDENT), raw, flags=3Dre.MUL= TILINE) return re.sub(re.escape(EATSPACE) + r' *', '', raw) =20 =20 -def mcgen(code, **kwds): +def mcgen(code: str, **kwds: Union[str, int]) -> 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 @@ -160,7 +163,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 */ @@ -168,7 +171,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(''' @@ -177,7 +180,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(''' @@ -186,7 +189,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 Thu Apr 18 14:32:38 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=1600210019; cv=none; d=zohomail.com; s=zohoarc; b=VodxkaaH7FFioKFsWu8bQvxi/SbbHdHbigJDc0xl9yh7159ReJXT4NUJVmBe7nc6Ebfcv7Ql74UpFNbFV/JJGIn5rucej3l9O/ASmik3ilcfyKKD7JJxmmsfGB2F77ljckwGIFgkEVtJHiXBpYmltFdP+oTewT+Q/pBE00sUWBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210019; 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=k8F3PRPOv5qdJJMtR8tcJX1mXWdNflxU9VYtL7zeGu8=; b=OpZFQOhYv10xwcgNJkNS+HTAcLLgYznYOZ1T9a8PEx4nT38YD3OZ42NMme1pFkqdS7GztvsBtcze4yY5ePI9tGwcKJN7K4cFdORPBUApRVVuP8zHRWY24T2cq+upI/D/UIQxALAguoj6wChMJyINsBHBKVuwispj4buJybizeqE= 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 1600210019531559.5949493999781; Tue, 15 Sep 2020 15:46:59 -0700 (PDT) Received: from localhost ([::1]:39416 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJj0-0006Ux-7X for importer@patchew.org; Tue, 15 Sep 2020 18:46:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdW-0006zI-2o for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27046) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdT-0002fU-TB for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-408-Na1KkeLxPI2PxfN8PSk5Kg-1; Tue, 15 Sep 2020 18:41:13 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 801AF100A44D; Tue, 15 Sep 2020 22:40:59 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29ED4838B7; Tue, 15 Sep 2020 22:40:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209675; 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=k8F3PRPOv5qdJJMtR8tcJX1mXWdNflxU9VYtL7zeGu8=; b=ee2wBD38GaNtJlQ2tQKvPhRAyur5/6YMVn0doRrcPT/wuIOCgRxRGsPZWBq2zC0TLEhsug CuhXXZBcr3qsk7WmM6GS14eemCtRTnf7ChhUNSFjb1odjedDIPrFhmHEwyWjobEkvp7XV2 l3mE/Vp2uCLXThoxkgBe6+AAVlY2A4Q= X-MC-Unique: Na1KkeLxPI2PxfN8PSk5Kg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 14/37] qapi/common.py: Move comments into docstrings Date: Tue, 15 Sep 2020 18:40:04 -0400 Message-Id: <20200915224027.2529813-15-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.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/09/15 18:01:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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. Signed-off-by: John Snow --- scripts/qapi/common.py | 50 ++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index af01348b35..38d380f0a9 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -20,10 +20,18 @@ 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 +53,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', @@ -135,9 +155,11 @@ def pop(self, amount: int =3D 4) -> int: INDENT =3D Indent(0) =20 =20 -# Generate @code with @kwds interpolated. -# Obey INDENT level, and strip EATSPACE. def cgen(code: str, **kwds: Union[str, int]) -> str: + """ + Generate `code` with `kwds` interpolated. + Obey `INDENT`, and strip `EATSPACE`. + """ raw =3D code % kwds if INDENT: raw, _ =3D re.subn(r'^(?!(#|$))', str(INDENT), raw, flags=3Dre.MUL= TILINE) --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600210215; cv=none; d=zohomail.com; s=zohoarc; b=oLQFcHJ4NWJrdODCLqtjX1sMb/64vKO68lF/OiXVgkqibVdlfQiI1Hbv7PJDMcWPVF1PU1U54SwuIad6/W6BIzTYwwTTfCl1nQH7SfgKbJZhm5BYZgSwO2+UbxbgFjXHjsX026PGk2vve6nZAqZUmd7FWX3+ZVoBvL4gKxmDA/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210215; 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=25L+LP3sg7a08ioNc1kdJFCC3fyjobquHZgeT+XNhAE=; b=Zr2jsfDB18Fupb6Kqb5CBz+79XfDYJQ5N4jtJ4ZmZVg65YqjBTQcZ8dptu5E760bRPof29rTUFo/a9nTavRYre1UrQ6tGLuFQrmWXX709DZV+G+lZzUkAVhd4kgpEmG5sKex5wAvvyykpAvq/ZTOtkWtwdyGwV9xC/6CW5hM97o= 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 1600210215360131.81273608997174; Tue, 15 Sep 2020 15:50:15 -0700 (PDT) Received: from localhost ([::1]:47664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJmA-0001TV-50 for importer@patchew.org; Tue, 15 Sep 2020 18:50:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdZ-00076l-82 for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:28168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdW-0002ff-2h for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:20 -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-286-9aKqX1YgM4aq0jXXWYGKpQ-1; Tue, 15 Sep 2020 18:41:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 12311427F2; Tue, 15 Sep 2020 22:41:01 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id C75257EEB4; Tue, 15 Sep 2020 22:40:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209677; 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=25L+LP3sg7a08ioNc1kdJFCC3fyjobquHZgeT+XNhAE=; b=eUzQBu2NmASl3LkY9leQhQ3F02Yz+RnkE0hOBUhz0sXibSQsYoY2v0Le5HRZXxLR89OvXl tCX4FAuFDZywoEt7mFY98a9kU480lGs57stPKcFDJeJniTRdxP9w/7tWuIY1OWa9YWBiCl EfiQraMOzbXSvyzFqCXTKcHtwC2/tts= X-MC-Unique: 9aKqX1YgM4aq0jXXWYGKpQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 15/37] qapi/common.py: split build_params into new file Date: Tue, 15 Sep 2020 18:40:05 -0400 Message-Id: <20200915224027.2529813-16-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 18:01:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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, because schema relies on common.py. To type build_params properly, it needs to be moved outside of the chain. Signed-off-by: John Snow --- scripts/qapi/commands.py | 2 +- scripts/qapi/common.py | 23 ----------------------- scripts/qapi/events.py | 2 +- scripts/qapi/params.py | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 scripts/qapi/params.py diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 2e4b4de0fa..0c0fe854fe 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -14,10 +14,10 @@ """ =20 from .common import ( - build_params, c_name, mcgen, ) +from .params import build_params from .gen import QAPIGenCCode, QAPISchemaModularCVisitor, ifcontext =20 =20 diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 38d380f0a9..0b1af694e6 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -209,26 +209,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 6b3afa14d7..75eda72534 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -13,11 +13,11 @@ """ =20 from .common import ( - build_params, c_enum_const, c_name, mcgen, ) +from .params import build_params from .gen import QAPISchemaModularCVisitor, ifcontext from .schema import QAPISchemaEnumMember from .types import gen_enum, gen_enum_lookup diff --git a/scripts/qapi/params.py b/scripts/qapi/params.py new file mode 100644 index 0000000000..4d4b02f60d --- /dev/null +++ b/scripts/qapi/params.py @@ -0,0 +1,40 @@ +# +# QAPI helper library +# +# Copyright IBM, Corp. 2011 +# Copyright (c) 2013-2018 Red Hat Inc. +# +# Authors: +# Anthony Liguori +# Markus Armbruster +# +# This work is licensed under the terms of the GNU GPL, version 2. +# See the COPYING file in the top-level directory. + +from typing import Optional + +from .common import c_name +from .schema import QAPISchemaObjectType + + +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' --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600210399; cv=none; d=zohomail.com; s=zohoarc; b=FdoXF0OsnaGiy4pGiyd85CuCrfnPtl/KECKyd5D2kUsZvVEKUsmLcBMYOiXLQX2RbwCIJLlsyjCTBye1u+1lBkBDglvT6njncZL4cXei/zO2GGPQkBGbuAYT9ghHmcfXu5DSLx6Ywkksmulzke8lOLpkekAns7tL96EWyFqAfs8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210399; 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=yk7qdnfo2EkoVtbV2vkLhMfyH9Zy0jgdEoRibxlIgcE=; b=RwVgR7pAzug7pkBijvcMM41BqoE0/6DaJWFrVaVPFBtO1gGiQJQKczZF5ByL8Q412oVqFPww0nRvHsSEODGNHxVhbR3tgC0a5824hhQak5cGyS73OXaUuj9I7v+Dz5YLnaEVsuQAsOVYnJfx9jyyAgMbJ8eKo5JBnSrpY160Cj0= 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 1600210399790212.75980736414544; Tue, 15 Sep 2020 15:53:19 -0700 (PDT) Received: from localhost ([::1]:56082 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJp8-000537-KG for importer@patchew.org; Tue, 15 Sep 2020 18:53:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdd-0007G0-58 for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20259) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdb-0002gT-2g for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:24 -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-469-ia1w7tamPdOejf3_fwA3rw-1; Tue, 15 Sep 2020 18:41:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 05C8718BE19A; Tue, 15 Sep 2020 22:41:02 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1704D81F4F; Tue, 15 Sep 2020 22:41:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209682; 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=yk7qdnfo2EkoVtbV2vkLhMfyH9Zy0jgdEoRibxlIgcE=; b=Wairr/ttjzROSbvkXNn7+lryeOpiSf9+l77WqjRWDuGtdNlHBnPPvd/lhfm0xVy9W4bW4Z 6d12M4fOEZoz4SibaCfejvJCm968sNeIm7RxOFNfKxuZDnM9qvt/Mdd7o8G6uxgQfnNSbB rW1/dQ7Oos7HJgq76uIUx1ylqG5MU5Y= X-MC-Unique: ia1w7tamPdOejf3_fwA3rw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 16/37] qapi: establish mypy type-checking baseline Date: Tue, 15 Sep 2020 18:40:06 -0400 Message-Id: <20200915224027.2529813-17-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 two very minor issues, 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/ Signed-off-by: John Snow --- scripts/qapi/doc.py | 3 +- scripts/qapi/mypy.ini | 65 ++++++++++++++++++++++++++++++++++++++++++ scripts/qapi/schema.py | 3 +- 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 scripts/qapi/mypy.ini diff --git a/scripts/qapi/doc.py b/scripts/qapi/doc.py index cbf7076ed9..70f7cdfaa6 100644 --- a/scripts/qapi/doc.py +++ b/scripts/qapi/doc.py @@ -5,7 +5,8 @@ """This script produces the documentation of a qapi schema in texinfo form= at""" =20 import re -from .gen import QAPIGenDoc, QAPISchemaVisitor +from .gen import QAPIGenDoc +from .schema import QAPISchemaVisitor =20 =20 MSG_FMT =3D """ diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini new file mode 100644 index 0000000000..a0f2365a53 --- /dev/null +++ b/scripts/qapi/mypy.ini @@ -0,0 +1,65 @@ +[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.doc] +disallow_subclassing_any =3D False +disallow_untyped_defs =3D False +disallow_incomplete_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 b4921b46c9..bb0cd717f1 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -17,6 +17,7 @@ import os import re from collections import OrderedDict +from typing import Optional =20 from .common import c_name, POINTER_SUFFIX 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 Thu Apr 18 14:32:38 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=1600210759; cv=none; d=zohomail.com; s=zohoarc; b=I7h5m5ozpPS/HdrCatBzP8O/q2pUlH66GL9WnxtQyvrpvr7Li1P2uL/29jaUlerek2neT6egB9tqqdzSF7S4+GeGOHH6HVoTfRc3ybuYnIDW8ukmi8Efwh+QNJCMnsY84MEU28bErBE2ck36Wf28KkgrQLGotvjciUHRTkkaMhs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210759; 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=v3gegnBF5zofs+QZa2ez/AKs4UefDcZxDn5vlHJB0wk=; b=VGnYaGZtbqUffFYP8AZaHxRts9lzIHNb8nnqF1zlEwNswMzdRZ32ksAgKLdrtzdIOUNNoNxVQmzPGJxV6ugEZmvyne9xDPli2wijm+PSGfS0R9b13F5M6YomFCLRMcSyO+eS7NqQ4fFKM1G5M24dEddx9VqsqXAez1juVGl3Ls4= 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 1600210759340585.3341449127217; Tue, 15 Sep 2020 15:59:19 -0700 (PDT) Received: from localhost ([::1]:44402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJuv-0003Rk-Vk for importer@patchew.org; Tue, 15 Sep 2020 18:59:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdf-0007KQ-5c for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:27 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:57467 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdb-0002gb-Hh for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:26 -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-298--R75IBdIO7iIaPjqIqFvoQ-1; Tue, 15 Sep 2020 18:41:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A94881019658; Tue, 15 Sep 2020 22:41:03 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 318FF60BE5; Tue, 15 Sep 2020 22:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209682; 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=v3gegnBF5zofs+QZa2ez/AKs4UefDcZxDn5vlHJB0wk=; b=Y8XnJjXpMtaH9uowcouPEUI1jDzEnZo9p7zAvDDN9v8QLL9dFjd0r7MLnbRKWoI6vcgzLb sHu98EZXiaoj4O4PjBhJwlsh4kIyRWgWCkAeF26qfkxMT/wMyYcNBzbWlhnf7ZLR0O1Le8 D0QAUSEidTHIQm+Ctl5uGfRZVAa/EAE= X-MC-Unique: -R75IBdIO7iIaPjqIqFvoQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 17/37] qapi/events.py: add notational type hints Date: Tue, 15 Sep 2020 18:40:07 -0400 Message-Id: <20200915224027.2529813-18-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:41:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 enough to enable type-checking on events.py, so enable that in this patch, too. Signed-off-by: John Snow --- 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 75eda72534..449a700ffe 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -12,6 +12,8 @@ See the COPYING file in the top-level directory. """ =20 +from typing import List + from .common import ( c_enum_const, c_name, @@ -19,17 +21,27 @@ ) from .params import build_params from .gen import QAPISchemaModularCVisitor, 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; @@ -38,7 +50,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 { @@ -66,7 +78,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 @@ -142,15 +158,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) @@ -173,7 +189,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" @@ -194,7 +210,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, @@ -205,7 +227,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 a0f2365a53..b668776d94 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -19,11 +19,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 Thu Apr 18 14:32:38 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=1600210484; cv=none; d=zohomail.com; s=zohoarc; b=UmaGQp948o6pxw0jJQ/R4vHlilo4Y6OtHsw1pEAOnMlzrsfqGWZuKRwJXJMTshqKwLDlYlLFRSmShInjBE6iIm0pBSFqXDY1tZVU3LMeV2Metj+VjINgxB+lmlpiINpnKXgejSLbU093mEptH2T09UM9j9stANMP3Y7RK0BfmSs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210484; 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=y3r34QObNsxvwj9/f1rHkZzBwW9z7veDY3xIUve+M20=; b=mBYXn2rh5RT1mGcFyW5KFkdcddgcO2RZmUXktw97aYEgYknvma3St1I2balbVhnsdH1Qzqw2wBjuqmK9VlgBQEmfgSVnHBddKeoU1v0iABrfDvCOGtqi1tYpjxXDGa45U7IxObjxrrNAAoA0z7yFf4hDPI/RsYt32niCpFZSUJU= 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 1600210484793391.44180808654016; Tue, 15 Sep 2020 15:54:44 -0700 (PDT) Received: from localhost ([::1]:58680 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJqV-00066z-Jc for importer@patchew.org; Tue, 15 Sep 2020 18:54:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdd-0007HC-Lb for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20096) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdb-0002gX-Fe for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-588-lI9mg-QJMq2M4yQB1krjOA-1; Tue, 15 Sep 2020 18:41:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01E21871807; Tue, 15 Sep 2020 22:41:05 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7E5D76E16; Tue, 15 Sep 2020 22:41:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209682; 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=y3r34QObNsxvwj9/f1rHkZzBwW9z7veDY3xIUve+M20=; b=bJ+jBOXn2erApp675tTYAj2ZeEnHw16Sx+cDfhGQimIbYotUtZcNjt85C6HSFTJqIHE3Ku RzYUen8Ls/9NeRwQgB9dDdl/BICUyq0EZvLMoB/8MaOCMyIUCAMx+mI3tiqrvAjAYAWB8c wpqRZVE7ysvb9KLdeXJkVSR8ORZ734A= X-MC-Unique: lI9mg-QJMq2M4yQB1krjOA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 18/37] qapi/events.py: Move comments into docstrings Date: Tue, 15 Sep 2020 18:40:08 -0400 Message-Id: <20200915224027.2529813-19-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 18:01:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/events.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index 449a700ffe..0b49cf5fea 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -49,8 +49,10 @@ 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: + """ + Declare and initialize a qapi object, using parameters from `build_par= ams`. + """ assert not typ.variants ret =3D mcgen(''' %(c_name)s param =3D { --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600210648; cv=none; d=zohomail.com; s=zohoarc; b=eXsNY+0zFi0PWXoQMWOdv/gToypWBd29e0UZ5h38jBljF0jPHctvl3tb/oLW1P7vQUwC9uvC1AlCdRCFqj1CTzWIZcVyuUP1mYNAh0YszdK/6x0mGA9eLeff/kEwNG01eOvIzbNp37eY9izIT8y4nXBy70QjWQIS/JP63MpNCxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210648; 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=lCBWH7ww/F2U1GEJ/7lO2ThPoC9ILZgmOP9LylhpqZU=; b=NhMXuG8gpwtaxVKLu579766U/Y/vZ5CvfMJMUCfFwjZ9TRFVF056NcHAKmNJq71tqg0nxFZpgmC4ikvuOqlq8QOOJbTc5/x5PBkR+/A5YWPSG+LJ5NBDelwiJyDOYvkmJ6wAXCRdro4nc1kD4bX41c2o0scYYW8+26A38jXuKaY= 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 1600210648964841.8104532190396; Tue, 15 Sep 2020 15:57:28 -0700 (PDT) Received: from localhost ([::1]:38694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJt9-000193-Sg for importer@patchew.org; Tue, 15 Sep 2020 18:57:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJde-0007JV-OU for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26768) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdc-0002gw-V2 for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:26 -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-402-lIVEs0wVOmGs6vo5BPaZ-w-1; Tue, 15 Sep 2020 18:41:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 21D60102120E; Tue, 15 Sep 2020 22:41:06 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D13B60BE5; Tue, 15 Sep 2020 22:41:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209683; 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=lCBWH7ww/F2U1GEJ/7lO2ThPoC9ILZgmOP9LylhpqZU=; b=itXFBi36oYE7otFdAi3whI90pF+KnVI1d1VZtY/mnrPCfeJkO8b0L+Hp1N2a3kGBpIGtBv /+zlEn7KjdKFYZ1j97gCeVjx7s9zAkuS67beFbgMwAZdp7utv7s9fFlpmP9PUWtHFMeV+1 tXNPj1zv15Lyhi3d6fPiLEuUUOwLDTQ= X-MC-Unique: lIVEs0wVOmGs6vo5BPaZ-w-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 19/37] qapi/commands.py: Don't re-bind to variable of different type Date: Tue, 15 Sep 2020 18:40:09 -0400 Message-Id: <20200915224027.2529813-20-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 18:01:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- 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 0c0fe854fe..b215e58357 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -194,14 +194,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 Thu Apr 18 14:32:38 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=1600210934; cv=none; d=zohomail.com; s=zohoarc; b=M/057VBMWNc1BjgJKXBvfisyuENWxYFWuIGhZ4LriR6Btlepp9W2V+RsDB8acxUsPUPduk+BrLKOssKcTjoDvCVRNQi4GTzIuJZ1WsGRXyhmI/dnUwdc92OVRPzoSsym3870RAnMyy7jFior06i3VyL6hb/j0hUMT3mtP0s0NiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210934; 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=uahw5VxJvg7Mg8Xm/z24kEFUIYO2j5wRgaa8KzHDdqg=; b=BaOsoDDLmvxpMmDKLUIjVIdPY7u/Vd9cxiihHbOcm+epR1tJUWLhDEFGfuvjxvDqQxyBlk7okv7rVNI3VnEtpMDOJvzEVNvVuKO4VnWF6r7HpvzedUvfAVTdZoA1qAby3DBnyB1u2Iu7xZ2zndgpif/lPuLvXqR70HC5N5UOl78= 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 1600210934680865.3474060569561; Tue, 15 Sep 2020 16:02:14 -0700 (PDT) Received: from localhost ([::1]:52976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJxg-00073v-1L for importer@patchew.org; Tue, 15 Sep 2020 19:02:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdf-0007Mx-VO for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52356) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdd-0002hC-Qf for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:27 -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-174-MV7n_buzOn-IWI2rVs1pJQ-1; Tue, 15 Sep 2020 18:41:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5815918C8C20; Tue, 15 Sep 2020 22:41:07 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4518A76E16; Tue, 15 Sep 2020 22:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209684; 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=uahw5VxJvg7Mg8Xm/z24kEFUIYO2j5wRgaa8KzHDdqg=; b=Wh5nrD0+eQ3/SWTc6XRAVHfXdHzOjugsnaG+ISaTWWXM5nJOZAAlvp8gpkOOZMX/xg+TNW EyMHeZvVRufr8yAh/dcVcfKDwIdClDvklgp+EST4VllxsPe06i9wKKF+Cu2bapr9TfudGU ouXhiianHFG0aDXaWmUbBds52s53qG8= X-MC-Unique: MV7n_buzOn-IWI2rVs1pJQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 20/37] qapi/commands.py: add notational type hints Date: Tue, 15 Sep 2020 18:40:10 -0400 Message-Id: <20200915224027.2529813-21-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 18:01:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/commands.py | 72 ++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index b215e58357..3c950da10a 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -13,15 +13,32 @@ See the COPYING file in the top-level directory. """ =20 +from typing import Dict, Optional, List, Set + from .common import ( c_name, mcgen, ) +from .gen import ( + QAPIGenC, + QAPIGenCCode, + QAPISchemaModularCVisitor, + ifcontext, +) from .params import build_params -from .gen import QAPIGenCCode, QAPISchemaModularCVisitor, 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); ''', @@ -30,7 +47,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 '' @@ -66,7 +86,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, QObject **ret= _out, @@ -87,19 +107,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(''' @@ -181,7 +204,10 @@ 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): +def gen_register_command(name: str, + success_response: bool, + allow_oob: bool, + allow_preconfig: bool) -> str: options =3D [] =20 if not success_response: @@ -203,7 +229,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) @@ -220,15 +246,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) @@ -252,7 +277,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" @@ -268,9 +293,18 @@ 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): + 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) -> None: if not gen: return # FIXME: If T is a user-defined type, the user is responsible @@ -291,7 +325,9 @@ def visit_command(self, name, info, ifcond, features, allow_oob, allow_preconfig= )) =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 Thu Apr 18 14:32:38 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=1600210776; cv=none; d=zohomail.com; s=zohoarc; b=f/UaRjV6plinL9VLdJPt5FIAnlJRMkakJMlVoa16ZuBiMz0yCioHfDfqGDmRt9CesOgJ3Ax6Z8PpOkjziKxpNMCA2mSeYxUnhSyQkRm6wJopccH2VP1WWpcmQddOrdcpOyWAgye1pnCeGWCNDraRw9VL3/gjZ9yF4mfhUKkp30g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210776; 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=4l/3d0xTEcbRJVVaJwBBpYyQeeCVHepqPpm5Wt13v60=; b=mLsy/+Ibg1BQIZ8ouhpSv5weLiQ2X4vUiyNO78eq4sLnCB2BrMZj8L7S2WQ97A5v1iQp8gWmmD8Gj+z/fUF5L4z7FqYaVpKCimvkkI0zoJXnwepDgNHItsbykuycziCVIs7chaseTHO5NY6WBbakmNObPEP5A6FkXTxO4iczNXc= 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 1600210776981806.3259210153153; Tue, 15 Sep 2020 15:59:36 -0700 (PDT) Received: from localhost ([::1]:45056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJvD-0003jM-Li for importer@patchew.org; Tue, 15 Sep 2020 18:59:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59434) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdc-0007Do-7o for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:24 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:28270 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdZ-0002gA-D5 for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:23 -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-18-gFYpBL1TNbKmJIn3EiOq0g-1; Tue, 15 Sep 2020 18:41:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 59E33807351; Tue, 15 Sep 2020 22:41:08 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6609B81C51; Tue, 15 Sep 2020 22:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209680; 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=4l/3d0xTEcbRJVVaJwBBpYyQeeCVHepqPpm5Wt13v60=; b=UwaQi3OQK+a//TOe3Hk/wpgk8P7+e2M/m79Th/Q6tc36KfL1NHtKuldVUMIOPh6eNowlDG xCdvJ6qfF8AGRo7Tz0nR9IMWdDKncRnQeKDOC1eFKRJFeRlCw5gsvDonWXdNTJ3fW9Sw4R VycHy+Jyz2gxGxIvUGam8LF3lj6cxBE= X-MC-Unique: gFYpBL1TNbKmJIn3EiOq0g-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 21/37] qapi/commands.py: enable checking with mypy Date: Tue, 15 Sep 2020 18:40:11 -0400 Message-Id: <20200915224027.2529813-22-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:41:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/mypy.ini | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index b668776d94..9da1dccef4 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.doc] disallow_subclassing_any =3D False disallow_untyped_defs =3D False --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600210615; cv=none; d=zohomail.com; s=zohoarc; b=Rz09xLKg9CovIKvJ2+D7k5xMX8BT21qx733dl1+3DM0xTO9fcgNQWPdo6d0NSxvwVRAFsVwGTB+eD41fHeNBzoZ3c66ssA/KPRAN+IinMMIMQpEg18ppUqukzaffOjTdBcp2SH2LyM06qmvBG9T0knT9HkelKFokNCpLD/tRrLg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210615; 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=+b/LM6qgtOjOvIPjkC5uq7a/4WuPsZj3/8utO8BNNmY=; b=WPmPDiAwVu56h1KDTk3Vnh9qN6oXS1qtOV/fkry5QfjaVZLPrnYHEpitTb17KuoTumrpmSKpDSb7MuKNx6ak86+x3iF5QAqxynd4kE7B/nQnbWyOrUJsXU6X3uHlt72XchGc1MGN6+V2Uyaj5SndoFIixca9NgwJbdmlWfYFUuQ= 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 1600210615354101.35466555507423; Tue, 15 Sep 2020 15:56:55 -0700 (PDT) Received: from localhost ([::1]:36068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJsb-0008Vl-U1 for importer@patchew.org; Tue, 15 Sep 2020 18:56:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdd-0007Hm-Vq for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdb-0002gf-LF for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-515-Pj1B2fNoOoyQYra9a6WYkw-1; Tue, 15 Sep 2020 18:41:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6E692AD682; Tue, 15 Sep 2020 22:41:09 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84D597BE76; Tue, 15 Sep 2020 22:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209683; 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=+b/LM6qgtOjOvIPjkC5uq7a/4WuPsZj3/8utO8BNNmY=; b=g5sFAfM+zxfTtpIUPDCxO7zi2wyKL46etCrWzJGdhyLfMs+YSYZKGNt91ok05bpXaaT4zs uJul6S0bU0pspSYVL0kRzUanTy5+Fqmdk3dcOIrZxLGlcJYj9kvsRjcfeZzdLikkvveTvN m4hebCmR8i6U3bj1zAGNkHxEybyXZEw= X-MC-Unique: Pj1B2fNoOoyQYra9a6WYkw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 22/37] qapi/source.py: add notational type hints Date: Tue, 15 Sep 2020 18:40:12 -0400 Message-Id: <20200915224027.2529813-23-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/mypy.ini | 5 ----- scripts/qapi/source.py | 31 ++++++++++++++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 9da1dccef4..43c8bd1973 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -39,11 +39,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 e97b9a8e15..1cc6a5b82d 100644 --- a/scripts/qapi/source.py +++ b/scripts/qapi/source.py @@ -11,37 +11,42 @@ =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: T, fname: str, line: int, parent: Optional[T]): 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 +54,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 +68,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 Thu Apr 18 14:32:38 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=1600210213; cv=none; d=zohomail.com; s=zohoarc; b=ezWoKPop1sYxRzkd6hKpp4kYpOiHNgSZSPEuHwTPlyzc0MwGbJ0d/eXi4XY4vRDSow7a1CGNcGqGj3/XmSGjlxRi3ekJ101O3Th1Q7Ku6NHibBgV/mEi7KdGEaK1WRFTX65axNBlDqHERaDniM5oN2iifYGNYpjZcRtC3g6wwY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210213; 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=6DuOI9lXbtpcnnokzlrE4kBUEAbmpC50cXB1sV/i6pw=; b=i9wvKVul7y3awaXzCQ4Cp7dV8cR1lsW0gg3QFGLOBelDgg7yI7Ws9+egpdYUvIcLGY7qGha3vuqmu/VayXPNZ6aNpK18MdlMtoMOQgHk3yHYZZ6s1z7Rb8aJnDp+YyoeXUgczTWGiDhtOkoJCsmK9SV3fDJXEI0fPyOu448yqwM= 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 1600210213903183.81311570443427; Tue, 15 Sep 2020 15:50:13 -0700 (PDT) Received: from localhost ([::1]:47572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJm8-0001RA-NM for importer@patchew.org; Tue, 15 Sep 2020 18:50:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdh-0007RF-OF for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48825) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdf-0002hU-9z for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-85-AeP2nEKBORKukQ0qNNzN5w-1; Tue, 15 Sep 2020 18:41:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B61818C9F6F; Tue, 15 Sep 2020 22:41:10 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98B537BE76; Tue, 15 Sep 2020 22:41:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209686; 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=6DuOI9lXbtpcnnokzlrE4kBUEAbmpC50cXB1sV/i6pw=; b=T6HvMcthVSHESwmRy7uRQSoQm8Q266kwHEKIar3rnFXPJXZC1RULa/+K+00Br0n9/Cibdq Rt8Wq2aasU1dm0WSwzct7XAVFY6T2o/MN4SGEQCP6zu4nS+CQPE2MTeJI+tlpstCPf73ly CC32rDejrEwNgDVWEkbPL9GVR3cXLK8= X-MC-Unique: AeP2nEKBORKukQ0qNNzN5w-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 23/37] qapi/source.py: delint with pylint Date: Tue, 15 Sep 2020 18:40:13 -0400 Message-Id: <20200915224027.2529813-24-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- 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 c800055589..c50a6656b7 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -8,7 +8,6 @@ ignore-patterns=3Ddoc.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 1cc6a5b82d..ba991d798f 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 Thu Apr 18 14:32:38 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=1600210621; cv=none; d=zohomail.com; s=zohoarc; b=J3pwL3TVdvDMFMh/Nzs2c1YqoB8A/GF/2TlN3b3jiUMMXki1xxMe6mH+Cas7jX58zDxvwhlfgfAxK6wHsM5Z5pvQljJjwRjlO0dKDbPHkH9KkT8/jFM13Wv5SJHZu5tgOYyMy7FRznZWMazGRe3xYqJYVlaUBkFNWDGh4WZko/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210621; 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=8ePgfCWByzRQmi2cnicC+aWlpeOGUB52vpyZeuE5ow4=; b=JJzOsoImlW6SXvufrxPZie5QQUk31Y792b/ctMwCFhgu15pdh27sEXMpL2TyuC2BrsURJBtB3XefihNXI7R0/SB/3jiV76nBbq7QjZxcO4yp1/4IqyDZLEKkQPRaZ06J7MF/w7sVzkhaiYHbgs8BvPpTnNqZk0YOet0omyKUHWE= 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 1600210621336819.0460016065082; Tue, 15 Sep 2020 15:57:01 -0700 (PDT) Received: from localhost ([::1]:36766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJsi-0000Ly-1s for importer@patchew.org; Tue, 15 Sep 2020 18:57:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59416) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdb-0007BC-4T for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:23 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:39049 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdZ-0002gB-Cq for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:22 -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-246-iqmW3cotNZO7vKd3SHfA6A-1; Tue, 15 Sep 2020 18:41:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A5689801ABA; Tue, 15 Sep 2020 22:41:11 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id A70AB7BE76; Tue, 15 Sep 2020 22:41:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209680; 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=8ePgfCWByzRQmi2cnicC+aWlpeOGUB52vpyZeuE5ow4=; b=XPBmYCyxCb2SpcWzD/e+pOgHwQPRP06QfXGdtXNRzSrGyaNEKWFknNmLIrLG4isob74Uwy pBCGQLxbTWD9YPNmD4FFeZ7/6Rd79DiOF/SccI5HizZBY4dz3PeRLot/BMlZw2UZUfx3Kf TS+dMdhVfC5m9FiJklcjXnnj3ujzeIs= X-MC-Unique: iqmW3cotNZO7vKd3SHfA6A-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 24/37] qapi/gen.py: Fix edge-case of _is_user_module Date: Tue, 15 Sep 2020 18:40:14 -0400 Message-Id: <20200915224027.2529813-25-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:41:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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" The edge case is that if the name is '', this expression returns a string instead of a bool, which violates our declared type. Signed-off-by: John Snow --- 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 11472ba043..fc46813d1a 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -221,7 +221,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 name is not None and not name.startswith('./') =20 @staticmethod def _is_builtin_module(name): --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600211109; cv=none; d=zohomail.com; s=zohoarc; b=Se9FjeLFa13qVn+PIIuML4a0C96d2OfbEy2p/iGnQ1HR2j9Gq5LfEEBknV6Ur47qZe217BNykjJE83jgv+F75Y+P+hHXEplhk6dk4acAJGvqaS2/jYCXk2uxhmm//SGVyq8TK/0xzX+lL5u3GrBx26byt6QRsGSDGDTIA1WTeBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600211109; 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=r+ZVSYm0Ts4O68qcgdwGBJc5+14Ww2TemJhgzswZgEI=; b=OtzijiaGl8AViJ7UxHIAxoCxXKn5PQOFeFYrieHPtmh5MqYUDVHWvEyLgzPuVoUezBZEPc0/h6y3cWVSr9UhgxHqWusw9gb5JWMGFeDvPfYK4PES3a4Ty2xIyF3yEoyoM8S2xRCwRKb38MYVdocONVXJduAdFhKPPIGY3A+BDOs= 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 1600211109828401.7456448016843; Tue, 15 Sep 2020 16:05:09 -0700 (PDT) Received: from localhost ([::1]:34402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIK0a-0002Yn-Kf for importer@patchew.org; Tue, 15 Sep 2020 19:05:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdk-0007YD-Pi for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:32 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:59702 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdg-0002hp-TR for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-168-7gTsV6wEPD6nBDQGcTQywQ-1; Tue, 15 Sep 2020 18:41:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B81FD107B11B; Tue, 15 Sep 2020 22:41:12 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id D11D360BE5; Tue, 15 Sep 2020 22:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209688; 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=r+ZVSYm0Ts4O68qcgdwGBJc5+14Ww2TemJhgzswZgEI=; b=heE2qJJzbhpXad1CpdWO79sKwAIAErPF/LYbqy6t+u9ezBdmKqO3o65jMG8i+wS+wz440l asaXtoD3vHgl2oX01dRd94J4jgttAJtmfbFwJvpuLtOapJzbYWSG8eTuIjr8RBZGp5jtLK fcX2l1tHtdOoic1X7G4Lva/j18j2tPY= X-MC-Unique: 7gTsV6wEPD6nBDQGcTQywQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 25/37] qapi/gen.py: add notational type hints Date: Tue, 15 Sep 2020 18:40:15 -0400 Message-Id: <20200915224027.2529813-26-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:41:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/gen.py | 105 +++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 49 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index fc46813d1a..c87c84e7c9 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -15,6 +15,7 @@ import errno import os import re +from typing import Dict, Generator, List, Optional, Tuple =20 from .common import ( c_fname, @@ -24,32 +25,34 @@ guardstart, mcgen, ) -from .schema import QAPISchemaVisitor +from .schema import ( + 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. @@ -74,7 +77,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 @@ -91,40 +94,38 @@ def _wrap_ifcond(ifcond, before, after): =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 @@ -140,7 +141,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 */ @@ -150,16 +151,16 @@ 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) -> Generator[None, None, None]: """A 'with' statement context manager to wrap with start_if()/end_if() =20 *args: any number of QAPIGenCCode @@ -185,15 +186,17 @@ def ifcontext(ifcond, *args): =20 =20 class QAPIGenDoc(QAPIGen): - - def _top(self): + def _top(self) -> str: return (super()._top() + '@c AUTOMATICALLY GENERATED, DO NOT MODIFY\n\n') =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', @@ -201,38 +204,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 name is not None 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) @@ -244,27 +251,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 @@ -272,13 +279,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) @@ -292,7 +299,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 Thu Apr 18 14:32:38 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=1600211084; cv=none; d=zohomail.com; s=zohoarc; b=ETVkModtLVRIMv3DjdA84v7KLEXRc4lEoovrQHoMZWeKWAVBKMN5dRiTvn0Kvs3uvRGxZV+GjHvre8LR/vc0MMYFILHLMU/PvjC2LrmCGUzSCMko2tIKE9JCITgVmGcq96sq7lhbSaEogpwAHM+ApXuIDe19Fu9U9n/4twUXspE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600211084; 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=Q+YeKihzxPHwbsVVMqVxA2EImXHQRwwe9+UizU5EI0o=; b=mEYT1wg/vVSpCKvtY5nJfjxu9k3imP60u90mxiA0jr26XNpnR6Lpq3DvZdL6DFhJMA1vOOhiV2H9F2AIomhhSP0SxELR16DPaVyUkMG0BO12L8/46YJoZVTXYW/2jEUQdqe0TEONr8gLqWs6qRLoN/Ix/CiHi2J8GmdHPX0ai1M= 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 1600211084200916.3913674991952; Tue, 15 Sep 2020 16:04:44 -0700 (PDT) Received: from localhost ([::1]:60512 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIK0A-0001hu-ON for importer@patchew.org; Tue, 15 Sep 2020 19:04:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59586) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdj-0007V5-Ed for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:31 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:38255 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdd-0002h3-Cv for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-537-C0Nmco3XNveApGP9F9--2w-1; Tue, 15 Sep 2020 18:41:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C68A6ADC1C; Tue, 15 Sep 2020 22:41:13 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id E287660BE5; Tue, 15 Sep 2020 22:41:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209684; 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=Q+YeKihzxPHwbsVVMqVxA2EImXHQRwwe9+UizU5EI0o=; b=HK3ilRFmuUSSRWgvII9UibeBTfv6wtfGbVt2XUSoVqqsDFVPYk4MuOkotZxoQdn7vWSRPg IqV20Su8m8WePE+UGB0M45F2fgXk1rIDoLXh6jaAm8FIPRKIVxVvixp6YOupbszSU0AxKm e//muzuBvbXFp4aGWjhjynzR9/DCXHo= X-MC-Unique: C0Nmco3XNveApGP9F9--2w-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 26/37] qapi/gen.py: Enable checking with mypy Date: Tue, 15 Sep 2020 18:40:16 -0400 Message-Id: <20200915224027.2529813-27-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:40:57 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/mypy.ini | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 43c8bd1973..dbfeda748c 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -19,11 +19,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 Thu Apr 18 14:32:38 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=1600210962; cv=none; d=zohomail.com; s=zohoarc; b=Ah9NPIYeM6mM4HEFzUf4/UcmHpV9uAJ+F1USXkhf8wXhDiHUr8T7l5BcRoHvWwr1KBX31SIkfKfoe3ABD+YHNlZT+nW9WdcUuJnvS9XEGZ3HIq23xCyAWUSTVu2atGCcneFOYmqCc58PCpR/Bd+CStSCAQ4/VVWmLAtnoM5hc5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210962; 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=ne2OMY+TjgRRXnt1DWz8QZdZ/J1PTnT4T+PHJ7K7p6c=; b=F1vaGzpQnkxBACSWpAQx/wqTwTaycwwTBMo1HDr1UngBUugkdN+QnVC5BEbjFvb+QmNu+ES+xFsXjmPJzauCM1ZQWvmMM8MdX8DSSlwIbFcCgywldc2lBIaae7WrT4nc9JCMGIKPShpdQ8ix8NhP6VS99SbRQDBAmMGmj4/5FdQ= 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 1600210962723755.9923955879453; Tue, 15 Sep 2020 16:02:42 -0700 (PDT) Received: from localhost ([::1]:55280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJyD-00080Z-JK for importer@patchew.org; Tue, 15 Sep 2020 19:02:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdi-0007Tq-UB for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39726) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdg-0002hr-Ty for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:30 -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-85-I0LNncnfPWuySEgMkXpH0A-1; Tue, 15 Sep 2020 18:41:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E7F2210BBEC3; Tue, 15 Sep 2020 22:41:14 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id F1F6160BE5; Tue, 15 Sep 2020 22:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209688; 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=ne2OMY+TjgRRXnt1DWz8QZdZ/J1PTnT4T+PHJ7K7p6c=; b=OgMMLzuSWHKUgNimvHldWNfg2SbOJli3nj+p1wxHCWdwGlpIk2hpA72LAa+VhR8eLv1DjN tWV8E2SLrF4wkNjvoFzSyudhUuq8AhwvBIHNgv3pgijYp9esSZb5Mz5x4mEXBD7DaATVzG I54TXbBMwYgGww2XY6poDqjpRHt+Fd0= X-MC-Unique: I0LNncnfPWuySEgMkXpH0A-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 27/37] qapi/gen.py: Remove unused parameter Date: Tue, 15 Sep 2020 18:40:17 -0400 Message-Id: <20200915224027.2529813-28-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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_basename doesn't use the 'what' argument, so remove it. Signed-off-by: John Snow --- 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 c87c84e7c9..e873901672 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -234,7 +234,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 '' @@ -252,7 +252,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 Thu Apr 18 14:32:38 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=1600210815; cv=none; d=zohomail.com; s=zohoarc; b=dipuk0eQGQU8XYPvw2Kyf3gr8ZczwYzu3nDnNLvjx3+ugTHF4bsPbZ9eGcM0DqWhoVfpiptpmxBGoHb/RnyX0wR9BS+W+QqGDnwWjtDs1Uat10GZYlv7ciKc1JhkS+BPo8g2ttIAJHSDOdQiwS6BxzcykvE81cqXxn6oipL/2Gg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210815; 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=1dehnIwwTGGmMaoVH34Box1kbfIwHLRRX8vnXblZyB0=; b=SBX9mp/401Ug26+hocxh5luYTamoIJyovFbkOweDuFBbBUhlOelc9KVCOrhwni6sjsOYQOvGQ5fjlLlQ34JsCyZZKS8BiE4E0vg6Bqi4oFOR4oOAxwmhYtTp16qlNujGwYC/+yns/szgRSyp5lmyswZ3lVHminlw/nfmnfzZvWE= 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 1600210815594162.35933353041094; Tue, 15 Sep 2020 16:00:15 -0700 (PDT) Received: from localhost ([::1]:46912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJvq-0004UA-EV for importer@patchew.org; Tue, 15 Sep 2020 19:00:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdi-0007SM-5g for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57892) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdg-0002he-6D for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-11-pWjq-1BPNECm42bzUaBzGw-1; Tue, 15 Sep 2020 18:41:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01DEDAF207; Tue, 15 Sep 2020 22:41:16 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DF437BE76; Tue, 15 Sep 2020 22:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209687; 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=1dehnIwwTGGmMaoVH34Box1kbfIwHLRRX8vnXblZyB0=; b=MqWFrai5Tv6yh4J778AU9Ke1xAbCrsc0pmVYHXrL+7mfsTXbntdec4PiwwoIaRNK389a4O r/DF66hawhMJ5mfNk9wVyJoq8RI+yFJrVzAVJDYONu39TVZuwYBjWEI8sjPmC03fXxFgQm R/q69lsUA09tsGXQ6bRTRwmVtrxkZBw= X-MC-Unique: pWjq-1BPNECm42bzUaBzGw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 28/37] qapi/gen.py: update write() to be more idiomatic Date: Tue, 15 Sep 2020 18:40:18 -0400 Message-Id: <20200915224027.2529813-29-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/gen.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index e873901672..bd67f6b069 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 Dict, Generator, List, Optional, Tuple @@ -60,21 +59,18 @@ 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) + 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 Thu Apr 18 14:32:38 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=1600210396; cv=none; d=zohomail.com; s=zohoarc; b=JYyJ8AG+EAPirqjk0pBmKPOfUfiEtJoBVmF53iM2zFAJJ/JgcF3MilezMZywpxe3mwLSyZcH6VP+wjDQQMX0fg40vHrTiBmQdWdr4e+teVCR/Di3yGcpqYr3gLfgD6b1dJ3hHQvdbq31TgcqUC+lwhuVblhgqKwLXx+Zbrp+oF0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210396; 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=T0kflW0u6r6RefLzAKp1dbxjN39bMVvrllfkUHodpWU=; b=BVU4zNCP6sAA5lVmF85dWfOn6SyikHK2yd1IQefM7Tdyc8s4wwKVmpm1gK0FnIgRCYuxuVUyj5IUL9gE1jlOTAQAHPJIGT5Rd25Id9HMTQ2JRF5fZ2HAmAjjlMmQH8YAHWPDx4L326iaC/EYMmDyTODvlaz0xnU3ft7h9EzuOF0= 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 1600210396153214.41532188254166; Tue, 15 Sep 2020 15:53:16 -0700 (PDT) Received: from localhost ([::1]:55616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJp4-0004rR-N8 for importer@patchew.org; Tue, 15 Sep 2020 18:53:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdj-0007Ua-8b for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:31 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:21801 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdh-0002hx-Bw for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:30 -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-329-qZHJsWqjOtOW0eFvF5XDJA-1; Tue, 15 Sep 2020 18:41:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9A0391902ECB; Tue, 15 Sep 2020 22:41:17 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4344660BE5; Tue, 15 Sep 2020 22:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209688; 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=T0kflW0u6r6RefLzAKp1dbxjN39bMVvrllfkUHodpWU=; b=Dk4xIhHcen9oIR9c6vgNOinHWFF5pTRlLRnqAzzCuAERCwOrKZXTraMlHEekMT/uD2EdQT 54c/ItJFdAtdyu5G5il2Zj6v3lMv6lwyivtMtnPyqV2h/oBOSugGdByvUsuE2NmYzFQLa5 OdbHqsbMUS9ZuvgQAoAlILCmS2S6YYQ= X-MC-Unique: qZHJsWqjOtOW0eFvF5XDJA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 29/37] qapi/gen.py: delint with pylint Date: Tue, 15 Sep 2020 18:40:19 -0400 Message-Id: <20200915224027.2529813-30-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.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=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:40:43 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 class methods because some users override the method and need to use `self`. Tell pylint to shush. Signed-off-by: John Snow --- 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 bd67f6b069..0a72aecdd0 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -46,9 +46,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 c50a6656b7..3aebb0d228 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -5,7 +5,6 @@ ignore-patterns=3Ddoc.py, error.py, expr.py, - gen.py, parser.py, schema.py, types.py, @@ -46,7 +45,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 Thu Apr 18 14:32:38 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=1600210933; cv=none; d=zohomail.com; s=zohoarc; b=Lf/WcfUvIkhJDV0+uBi8J3/FfAq93+mrN6Qa4gV2WfLwYRhK1/qU2SOoyimig+vL13Du0iLYANHnatm7h4F7fe0q0UFMoIig0KdFaQHpQRiSToSfd5OlUheD9ZXqwDJucaxTd770INIODFVEnH26jjK6+110zgF0xjwXNtHnrgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210933; 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=ZqSJckFwaigPqII7TYtgwKO5VF0wvwDzqsNfM47vfmM=; b=ncrClxZZjlre1ZoAPQruN44wq0qKgAMadMUlB4cLLT/giwmSi4NR0Yr2bZOuZyf0fXXjIdMDzqF9vfob3VLdO9Lc5FQYaQy1fTRPzmGlmGI6op/nwnvqi9ZcT6s/ct6MQybL+TN/I0YoHPzyf0HDi8Ix6jpGeGTXBaHoDswjpw0= 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 1600210933602693.1199056661717; Tue, 15 Sep 2020 16:02:13 -0700 (PDT) Received: from localhost ([::1]:53386 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJxk-0007E4-D4 for importer@patchew.org; Tue, 15 Sep 2020 19:02:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdk-0007Wm-83 for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdi-0002i8-7A for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-101-23JKPyhvNx2sP6y7bMV-5w-1; Tue, 15 Sep 2020 18:41:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0720107B79B; Tue, 15 Sep 2020 22:41:18 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id E384660BE5; Tue, 15 Sep 2020 22:41:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209689; 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=ZqSJckFwaigPqII7TYtgwKO5VF0wvwDzqsNfM47vfmM=; b=gWh48C/2/z/+d1BiRV1F+57C4iN+QnWX3igJE2XNWSgIz7fHp77p/6aRHHXOkZRwgKZHdF xBtYKTmQbVJLLEvaZE53W7dHtBy5MlHRWgl4XysP8lMotMYjGStqpgXQesId7sGBFTJHIS 9fZOpk7YqhH3z3GwcqI72JjUxucLLE4= X-MC-Unique: 23JKPyhvNx2sP6y7bMV-5w-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 30/37] qapi/introspect.py: Add a typed 'extra' structure Date: Tue, 15 Sep 2020 18:40:20 -0400 Message-Id: <20200915224027.2529813-31-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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" Typing arbitrarily shaped dicts with mypy is difficult prior to Python 3.8; using explicit structures is nicer. Since we always define an Extra type now, the return type of _make_tree simplifies and always returns the tuple. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index b036fcf9ce..41ca8afc67 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,6 +10,8 @@ See the COPYING file in the top-level directory. """ =20 +from typing import (NamedTuple, Optional, Sequence) + from .common import ( c_name, gen_endif, @@ -21,16 +23,21 @@ QAPISchemaType) =20 =20 -def _make_tree(obj, ifcond, features, extra=3DNone): - if extra is None: - extra =3D {} - if ifcond: - extra['if'] =3D ifcond +class Extra(NamedTuple): + """ + Extra contains data that isn't intended for output by introspection. + """ + comment: Optional[str] =3D None + ifcond: Sequence[str] =3D tuple() + + +def _make_tree(obj, ifcond, features, + extra: Optional[Extra] =3D None): + comment =3D extra.comment if extra else None + extra =3D Extra(comment, ifcond) if features: - obj['features'] =3D [(f.name, {'if': f.ifcond}) for f in features] - if extra: - return (obj, extra) - return obj + obj['features'] =3D [(f.name, Extra(None, f.ifcond)) for f in feat= ures] + return (obj, extra) =20 =20 def _tree_to_qlit(obj, level=3D0, suppress_first_indent=3DFalse): @@ -40,8 +47,8 @@ def indent(level): =20 if isinstance(obj, tuple): ifobj, extra =3D obj - ifcond =3D extra.get('if') - comment =3D extra.get('comment') + ifcond =3D extra.ifcond + comment =3D extra.comment ret =3D '' if comment: ret +=3D indent(level) + '/* %s */\n' % comment @@ -168,7 +175,7 @@ def _gen_tree(self, name, mtype, obj, ifcond, features): if not self._unmask: # Output a comment to make it easy to map masked names # back to the source when reading the generated output. - extra =3D {'comment': '"%s" =3D %s' % (self._name(name), n= ame)} + extra =3D Extra(comment=3Df'"{self._name(name)}" =3D {name= }') name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600211201; cv=none; d=zohomail.com; s=zohoarc; b=RCKxlf5sl6tvkyv5EXWKa8DUhtivAgTAy1kUQaoaFktmU/ISymoXUo+EZ8hKSh3NIAibNPYlE6+Vo9ucnQOiox7nJMkWDp4O+ys4ePWMPxvUhd4uJEWBCnIvxLqRo3t2RfOlr8rewfTNWEA5ixw58UbP0LqN2dSJhyIPW0KqJng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600211201; 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=6v1QZedyVDhCtOAjeUf7VmKC1JSzpMgb4c04RWcAjQc=; b=FQjF9Xh6zC9txwEm1gdi9BNcy3dLJnPyuJASvxo1OxWWinO7u1nzdXVlPkgbmU9WttWYCCwb9t3lGT4ao4SR3/9Zb5H54yQTkY2q0T9By85WUO3ZiHQdxOTIJGfFpGmz1LygamO68WeslMbAOXd44OzcBSXcFTT355pSTmxG7wM= 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 1600211201239556.6860496430554; Tue, 15 Sep 2020 16:06:41 -0700 (PDT) Received: from localhost ([::1]:38278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIK24-0004Du-0j for importer@patchew.org; Tue, 15 Sep 2020 19:06:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJeC-0007mZ-OJ for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:42:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:45659) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJe5-0002kF-0L for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:57 -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-388-HZaLEmFFOPefx-utq45iow-1; Tue, 15 Sep 2020 18:41:21 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 646CC807344; Tue, 15 Sep 2020 22:41:20 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2845160BE5; Tue, 15 Sep 2020 22:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209707; 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=6v1QZedyVDhCtOAjeUf7VmKC1JSzpMgb4c04RWcAjQc=; b=B9MTSmvsuJWCJ9HF8zg9qZ6NIg/afuJwCkiCTc5ZF7P/JtdBDhxR1FDrVS2hqzr5ZImnp8 bGp1CkPq6DrZvlDSFUL5Ai7kZO33oPir7cVa9MpnDWvlBiZRH0MOe32ZKp0GqR2xML9TqT 0rsRyOGnTwB61U/DxRxW4MnUUHGMdgY= X-MC-Unique: HZaLEmFFOPefx-utq45iow-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 31/37] qapi/introspect.py: add _gen_features helper Date: Tue, 15 Sep 2020 18:40:21 -0400 Message-Id: <20200915224027.2529813-32-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 18:01:00 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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_tree doesn't know if it is receiving an object or some other type; adding features information should arguably be performed by the caller. This will help us refactor _make_tree more gracefully in the next patch. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 41ca8afc67..e1edd0b179 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,7 +10,7 @@ See the COPYING file in the top-level directory. """ =20 -from typing import (NamedTuple, Optional, Sequence) +from typing import (NamedTuple, List, Optional, Sequence) =20 from .common import ( c_name, @@ -20,7 +20,7 @@ ) from .gen import QAPISchemaMonolithicCVisitor from .schema import (QAPISchemaArrayType, QAPISchemaBuiltinType, - QAPISchemaType) + QAPISchemaFeature, QAPISchemaType) =20 =20 class Extra(NamedTuple): @@ -31,12 +31,10 @@ class Extra(NamedTuple): ifcond: Sequence[str] =3D tuple() =20 =20 -def _make_tree(obj, ifcond, features, +def _make_tree(obj, ifcond, extra: Optional[Extra] =3D None): comment =3D extra.comment if extra else None extra =3D Extra(comment, ifcond) - if features: - obj['features'] =3D [(f.name, Extra(None, f.ifcond)) for f in feat= ures] return (obj, extra) =20 =20 @@ -169,6 +167,10 @@ def _use_type(self, typ): return '[' + self._use_type(typ.element_type) + ']' return self._name(typ.name) =20 + @classmethod + def _gen_features(cls, features: List[QAPISchemaFeature]): + return [_make_tree(f.name, f.ifcond) for f in features] + def _gen_tree(self, name, mtype, obj, ifcond, features): extra =3D None if mtype not in ('command', 'event', 'builtin', 'array'): @@ -179,13 +181,17 @@ def _gen_tree(self, name, mtype, obj, ifcond, feature= s): name =3D self._name(name) obj['name'] =3D name obj['meta-type'] =3D mtype - self._trees.append(_make_tree(obj, ifcond, features, extra)) + if features: + obj['features'] =3D self._gen_features(features) + self._trees.append(_make_tree(obj, ifcond, extra)) =20 def _gen_member(self, member): obj =3D {'name': member.name, 'type': self._use_type(member.type)} if member.optional: obj['default'] =3D None - return _make_tree(obj, member.ifcond, member.features) + if member.features: + obj['features'] =3D self._gen_features(member.features) + return _make_tree(obj, member.ifcond) =20 def _gen_variants(self, tag_name, variants): return {'tag': tag_name, @@ -193,7 +199,7 @@ def _gen_variants(self, tag_name, variants): =20 def _gen_variant(self, variant): obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} - return _make_tree(obj, variant.ifcond, None) + return _make_tree(obj, variant.ifcond) =20 def visit_builtin_type(self, name, info, json_type): self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600210940; cv=none; d=zohomail.com; s=zohoarc; b=a720a4oAsz4HnnsVsOtc/14rt3XiLwPRpMC/0BBVR+JRN2nVld1m6+Y8FCbDW6qs+JwaJCEdAzTc04HeodKWD7OG/Tetv+1GnbkFY2QH7Pi/o6xiy0d6TjlKEbcT5NkNntjvK4brEiJmcGn6UUMr/1St5MP38kxG1CaT42okYiM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210940; 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=UfnNb8K+fR0XrTDp0uEKa0hcypzfZki4qBv716hnSTs=; b=UjDp5g8Bbu6sVLhjfN+KIsRX4bUm7ZY5rfM1T49gbrFJU9lAEphsI+Lv7PNawpPMQnGVH0tO3C/smFF4RsmSF1RzORm3Eq0qHr4e1ciJ8yUzdQ+48C2BFtFmOWKvCMt88OJBDLz7urhPekfJSgod2q4XsI3ZuNFvMU4sqt8LNoA= 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 1600210940423362.0887044048035; Tue, 15 Sep 2020 16:02:20 -0700 (PDT) Received: from localhost ([::1]:53840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJxp-0007Pu-1u for importer@patchew.org; Tue, 15 Sep 2020 19:02:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJeE-0007qy-Rc for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:42:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJe9-0002kY-Sv for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:42:02 -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-187-iA0yAwlENEykzH7BD6l0_g-1; Tue, 15 Sep 2020 18:41:25 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3EADB1022E13; Tue, 15 Sep 2020 22:41:22 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id B750760BE5; Tue, 15 Sep 2020 22:41:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209711; 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=UfnNb8K+fR0XrTDp0uEKa0hcypzfZki4qBv716hnSTs=; b=Ms0OVb0WFRwyMBd390romEOQLNcgtm+oPlF3+DwaI2FcJLpK8f4uhX6gGHKmu4ENW44jLa lTpg+BqWqYDomIiGngWblbkQQooBIEwk+twofO7083Ry8BZokiJWRAvwShntsb3vlMZ4ND czEBevA9X0SmelwsMC7HGJ9KD43Mbz4= X-MC-Unique: iA0yAwlENEykzH7BD6l0_g-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 32/37] qapi/introspect.py: create a typed 'Node' data structure Date: Tue, 15 Sep 2020 18:40:22 -0400 Message-Id: <20200915224027.2529813-33-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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" Replacing the un-typed tuple, add a typed Node that we can add typed metadata to. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 53 ++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index e1edd0b179..e0f5007ab7 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -31,11 +31,18 @@ class Extra(NamedTuple): ifcond: Sequence[str] =3D tuple() =20 =20 -def _make_tree(obj, ifcond, - extra: Optional[Extra] =3D None): - comment =3D extra.comment if extra else None - extra =3D Extra(comment, ifcond) - return (obj, extra) +class Node: + """ + Node generally contains a SchemaInfo-like type (as a dict), + But it also used to wrap comments/ifconds around leaf value types. + """ + # Remove after 3.7 adds @dataclass: + # pylint: disable=3Dtoo-few-public-methods + def __init__(self, data, ifcond: List[str], + extra: Optional[Extra] =3D None): + self.data =3D data + comment =3D extra.comment if extra else None + self.extra =3D Extra(comment, ifcond) =20 =20 def _tree_to_qlit(obj, level=3D0, suppress_first_indent=3DFalse): @@ -43,18 +50,15 @@ def _tree_to_qlit(obj, level=3D0, suppress_first_indent= =3DFalse): def indent(level): return level * 4 * ' ' =20 - if isinstance(obj, tuple): - ifobj, extra =3D obj - ifcond =3D extra.ifcond - comment =3D extra.comment + if isinstance(obj, Node): ret =3D '' - if comment: - ret +=3D indent(level) + '/* %s */\n' % comment - if ifcond: - ret +=3D gen_if(ifcond) - ret +=3D _tree_to_qlit(ifobj, level) - if ifcond: - ret +=3D '\n' + gen_endif(ifcond) + if obj.extra.comment: + ret +=3D indent(level) + '/* %s */\n' % obj.extra.comment + if obj.extra.ifcond: + ret +=3D gen_if(obj.extra.ifcond) + ret +=3D _tree_to_qlit(obj.data, level) + if obj.extra.ifcond: + ret +=3D '\n' + gen_endif(obj.extra.ifcond) return ret =20 ret =3D '' @@ -169,7 +173,7 @@ def _use_type(self, typ): =20 @classmethod def _gen_features(cls, features: List[QAPISchemaFeature]): - return [_make_tree(f.name, f.ifcond) for f in features] + return [Node(f.name, f.ifcond) for f in features] =20 def _gen_tree(self, name, mtype, obj, ifcond, features): extra =3D None @@ -183,7 +187,7 @@ def _gen_tree(self, name, mtype, obj, ifcond, features): obj['meta-type'] =3D mtype if features: obj['features'] =3D self._gen_features(features) - self._trees.append(_make_tree(obj, ifcond, extra)) + self._trees.append(Node(obj, ifcond, extra)) =20 def _gen_member(self, member): obj =3D {'name': member.name, 'type': self._use_type(member.type)} @@ -191,7 +195,7 @@ def _gen_member(self, member): obj['default'] =3D None if member.features: obj['features'] =3D self._gen_features(member.features) - return _make_tree(obj, member.ifcond) + return Node(obj, member.ifcond) =20 def _gen_variants(self, tag_name, variants): return {'tag': tag_name, @@ -199,15 +203,14 @@ def _gen_variants(self, tag_name, variants): =20 def _gen_variant(self, variant): obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} - return _make_tree(obj, variant.ifcond) + return Node(obj, variant.ifcond) =20 def visit_builtin_type(self, name, info, json_type): self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) =20 def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): self._gen_tree(name, 'enum', - {'values': [_make_tree(m.name, m.ifcond, None) - for m in members]}, + {'values': [Node(m.name, m.ifcond) for m in members= ]}, ifcond, features) =20 def visit_array_type(self, name, info, ifcond, element_type): @@ -227,9 +230,9 @@ def visit_object_type_flat(self, name, info, ifcond, fe= atures, def visit_alternate_type(self, name, info, ifcond, features, variants): self._gen_tree(name, 'alternate', {'members': [ - _make_tree({'type': self._use_type(m.type)}, - m.ifcond, None) - for m in variants.variants]}, + Node({'type': self._use_type(m.type)}, m.ifcond) + for m in variants.variants + ]}, ifcond, features) =20 def visit_command(self, name, info, ifcond, features, --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600211462; cv=none; d=zohomail.com; s=zohoarc; b=CZ/NqabOrylsbFpmZ9kfRPEWoXZR7Y9KZqETfx5ER5G5oUOFA+1GSUHWkbv3P6FnPilzS2ePz9tamaYvo8hPyB1hoPvACs5JtcXjRdHkzeIj7tQBpAQKSCzzBfOJmnza2/qlhVBmp9tFk3Mzl7+frESnixy7WXz/D8b55ujrT7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600211462; 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=Xucmwj4tTAsCtD3L6ZQ+AzD7cuIGftAw1H06DI/YQvk=; b=Y0TOEgvWg16GQRy4Jx2bMpdachD66thMrVpYfBdRiX8dyWC1C/ysSzSFfgJ4CClCauDn5QFJhW+W9GtTpL0fj2c+XWqMRoF5n16yeeuR4Uu+7NY8KL7av+0Z8BUHnW4nY/wyWG6p2akdNRsYM7+5QSmUz53psWva+H4eam4VUeY= 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 1600211462399650.2980177062069; Tue, 15 Sep 2020 16:11:02 -0700 (PDT) Received: from localhost ([::1]:49898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIK6H-0000dp-4n for importer@patchew.org; Tue, 15 Sep 2020 19:11:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59774) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJeF-0007sA-6Q for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:42:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJeB-0002kn-17 for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:42:02 -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-305-scKJAXX3PKuApur3Drw4kg-1; Tue, 15 Sep 2020 18:41:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 56E49190A3ED; Tue, 15 Sep 2020 22:41:23 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71AC060BE5; Tue, 15 Sep 2020 22:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209713; 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=Xucmwj4tTAsCtD3L6ZQ+AzD7cuIGftAw1H06DI/YQvk=; b=Lp0bnw9nImKshJ6xJiL8lVeX8stX5xaTV4q90polP5YniwmDiG7tL8cVJjON6AR2mR6Tgn eNZx3VoyPK7I/Kw4n+ORwxXMrATNSS/OLEEpLyifsXyuWl+jTCnP8tRB9bGFkHw3IZ66D/ jPU0lzcQCC4xHKWZkesAsa+VAWeA8vI= X-MC-Unique: scKJAXX3PKuApur3Drw4kg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 33/37] qapi/introspect.py: add notational type hints Date: Tue, 15 Sep 2020 18:40:23 -0400 Message-Id: <20200915224027.2529813-34-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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" Add a tiny hint into schema.py to allow introspect.py to type check, too. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 123 ++++++++++++++++++++++++++----------- scripts/qapi/mypy.ini | 5 -- scripts/qapi/schema.py | 2 +- 3 files changed, 87 insertions(+), 43 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index e0f5007ab7..4e1ea3a00c 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,7 +10,16 @@ See the COPYING file in the top-level directory. """ =20 -from typing import (NamedTuple, List, Optional, Sequence) +from typing import ( + Any, + Dict, + Generic, + List, + NamedTuple, + Optional, + Sequence, + TypeVar, +) =20 from .common import ( c_name, @@ -19,8 +28,23 @@ mcgen, ) from .gen import QAPISchemaMonolithicCVisitor -from .schema import (QAPISchemaArrayType, QAPISchemaBuiltinType, - QAPISchemaFeature, QAPISchemaType) +from .schema import ( + QAPISchema, + QAPISchemaArrayType, + QAPISchemaBuiltinType, + QAPISchemaEntity, + QAPISchemaEnumMember, + QAPISchemaFeature, + QAPISchemaObjectType, + QAPISchemaObjectTypeMember, + QAPISchemaType, + QAPISchemaVariant, + QAPISchemaVariants, +) +from .source import QAPISourceInfo + + +_NodeType =3D TypeVar('_NodeType') =20 =20 class Extra(NamedTuple): @@ -31,23 +55,24 @@ class Extra(NamedTuple): ifcond: Sequence[str] =3D tuple() =20 =20 -class Node: +class Node(Generic[_NodeType]): """ Node generally contains a SchemaInfo-like type (as a dict), But it also used to wrap comments/ifconds around leaf value types. """ # Remove after 3.7 adds @dataclass: # pylint: disable=3Dtoo-few-public-methods - def __init__(self, data, ifcond: List[str], + def __init__(self, data: _NodeType, ifcond: List[str], extra: Optional[Extra] =3D None): self.data =3D data comment =3D extra.comment if extra else None self.extra =3D Extra(comment, ifcond) =20 =20 -def _tree_to_qlit(obj, level=3D0, suppress_first_indent=3DFalse): +def _tree_to_qlit(obj: Any, level: int =3D 0, + suppress_first_indent: bool =3D False) -> str: =20 - def indent(level): + def indent(level: int) -> str: return level * 4 * ' ' =20 if isinstance(obj, Node): @@ -94,21 +119,20 @@ def indent(level): return ret =20 =20 -def to_c_string(string): +def to_c_string(string: str) -> str: return '"' + string.replace('\\', r'\\').replace('"', r'\"') + '"' =20 =20 class QAPISchemaGenIntrospectVisitor(QAPISchemaMonolithicCVisitor): - - def __init__(self, prefix, unmask): + def __init__(self, prefix: str, unmask: bool): super().__init__( prefix, 'qapi-introspect', ' * QAPI/QMP schema introspection', __doc__) self._unmask =3D unmask - self._schema =3D None - self._trees =3D [] - self._used_types =3D [] - self._name_map =3D {} + self._schema: Optional[QAPISchema] =3D None + self._trees: List[Node[Dict[str, Any]]] =3D [] + self._used_types: List[QAPISchemaType] =3D [] + self._name_map: Dict[str, str] =3D {} self._genc.add(mcgen(''' #include "qemu/osdep.h" #include "%(prefix)sqapi-introspect.h" @@ -116,10 +140,10 @@ def __init__(self, prefix, unmask): ''', prefix=3Dprefix)) =20 - def visit_begin(self, schema): + def visit_begin(self, schema: QAPISchema) -> None: self._schema =3D schema =20 - def visit_end(self): + def visit_end(self) -> None: # visit the types that are actually used for typ in self._used_types: typ.visit(self) @@ -141,18 +165,18 @@ def visit_end(self): self._used_types =3D [] self._name_map =3D {} =20 - def visit_needed(self, entity): + def visit_needed(self, entity: QAPISchemaEntity) -> bool: # Ignore types on first pass; visit_end() will pick up used types return not isinstance(entity, QAPISchemaType) =20 - def _name(self, name): + def _name(self, name: str) -> str: if self._unmask: return name if name not in self._name_map: self._name_map[name] =3D '%d' % len(self._name_map) return self._name_map[name] =20 - def _use_type(self, typ): + def _use_type(self, typ: QAPISchemaType) -> str: # Map the various integer types to plain int if typ.json_type() =3D=3D 'int': typ =3D self._schema.lookup_type('int') @@ -172,10 +196,13 @@ def _use_type(self, typ): return self._name(typ.name) =20 @classmethod - def _gen_features(cls, features: List[QAPISchemaFeature]): + def _gen_features(cls, + features: List[QAPISchemaFeature]) -> List[Node[str]= ]: return [Node(f.name, f.ifcond) for f in features] =20 - def _gen_tree(self, name, mtype, obj, ifcond, features): + def _gen_tree(self, name: str, mtype: str, obj: Dict[str, Any], + ifcond: List[str], + features: Optional[List[QAPISchemaFeature]]) -> None: extra =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: @@ -189,7 +216,8 @@ def _gen_tree(self, name, mtype, obj, ifcond, features): obj['features'] =3D self._gen_features(features) self._trees.append(Node(obj, ifcond, extra)) =20 - def _gen_member(self, member): + def _gen_member(self, member: QAPISchemaObjectTypeMember, + ) -> Node[Dict[str, Any]]: obj =3D {'name': member.name, 'type': self._use_type(member.type)} if member.optional: obj['default'] =3D None @@ -197,29 +225,39 @@ def _gen_member(self, member): obj['features'] =3D self._gen_features(member.features) return Node(obj, member.ifcond) =20 - def _gen_variants(self, tag_name, variants): + def _gen_variants(self, tag_name: str, + variants: List[QAPISchemaVariant]) -> Dict[str, Any]: return {'tag': tag_name, 'variants': [self._gen_variant(v) for v in variants]} =20 - def _gen_variant(self, variant): + def _gen_variant(self, variant: QAPISchemaVariant) -> Node[Dict[str, A= ny]]: obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} return Node(obj, variant.ifcond) =20 - def visit_builtin_type(self, name, info, json_type): + def visit_builtin_type(self, name: str, info: Optional[QAPISourceInfo], + json_type: str) -> None: self._gen_tree(name, 'builtin', {'json-type': json_type}, [], None) =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[QAPISchemaFeatur= e], + members: List[QAPISchemaEnumMember], + prefix: Optional[str]) -> None: self._gen_tree(name, 'enum', {'values': [Node(m.name, m.ifcond) for m in members= ]}, ifcond, features) =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: element =3D self._use_type(element_type) self._gen_tree('[' + element + ']', 'array', {'element-type': elem= ent}, ifcond, None) =20 - def visit_object_type_flat(self, name, info, ifcond, features, - members, variants): + def visit_object_type_flat(self, name: str, info: Optional[QAPISourceI= nfo], + ifcond: List[str], + features: List[QAPISchemaFeature], + members: Sequence[QAPISchemaObjectTypeMembe= r], + variants: Optional[QAPISchemaVariants]) -> = None: obj =3D {'members': [self._gen_member(m) for m in members]} if variants: obj.update(self._gen_variants(variants.tag_member.name, @@ -227,7 +265,10 @@ def visit_object_type_flat(self, name, info, ifcond, f= eatures, =20 self._gen_tree(name, 'object', obj, ifcond, features) =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: self._gen_tree(name, 'alternate', {'members': [ Node({'type': self._use_type(m.type)}, m.ifcond) @@ -235,24 +276,32 @@ def visit_alternate_type(self, name, info, ifcond, fe= atures, variants): ]}, ifcond, features) =20 - def visit_command(self, name, info, ifcond, features, - arg_type, ret_type, gen, success_response, boxed, - allow_oob, allow_preconfig): + def visit_command(self, name: str, info: QAPISourceInfo, ifcond: List[= str], + features: List[QAPISchemaFeature], + arg_type: QAPISchemaObjectType, + ret_type: Optional[QAPISchemaObjectType], gen: bool, + success_response: bool, boxed: bool, allow_oob: bool, + allow_preconfig: bool) -> None: arg_type =3D arg_type or self._schema.the_empty_object_type ret_type =3D ret_type or self._schema.the_empty_object_type - obj =3D {'arg-type': self._use_type(arg_type), - 'ret-type': self._use_type(ret_type)} + obj: Dict[str, Any] =3D { + 'arg-type': self._use_type(arg_type), + 'ret-type': self._use_type(ret_type) + } if allow_oob: obj['allow-oob'] =3D allow_oob self._gen_tree(name, 'command', obj, ifcond, features) =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: arg_type =3D arg_type or self._schema.the_empty_object_type self._gen_tree(name, 'event', {'arg-type': self._use_type(arg_type= )}, ifcond, features) =20 =20 -def gen_introspect(schema, output_dir, prefix, opt_unmask): +def gen_introspect(schema: QAPISchema, output_dir: str, prefix: str, + opt_unmask: bool) -> None: vis =3D QAPISchemaGenIntrospectVisitor(prefix, opt_unmask) schema.visit(vis) vis.write(output_dir) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index dbfeda748c..9ce8b56f22 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -19,11 +19,6 @@ disallow_untyped_defs =3D False disallow_incomplete_defs =3D False check_untyped_defs =3D False =20 -[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 diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index bb0cd717f1..3023bab44b 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -28,7 +28,7 @@ class QAPISchemaEntity: meta: Optional[str] =3D None =20 - def __init__(self, name, info, doc, ifcond=3DNone, features=3DNone): + def __init__(self, name: str, info, doc, ifcond=3DNone, features=3DNon= e): assert name is None or isinstance(name, str) for f in features or []: assert isinstance(f, QAPISchemaFeature) --=20 2.26.2 From nobody Thu Apr 18 14:32:38 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=1600210612; cv=none; d=zohomail.com; s=zohoarc; b=UOgWkiK23aimzFsiYuqvureZJ49W4M7kvKgtLPWQl5ez0ulYjBosiqaBPUps8F7XSLUrMrtkV1Fn/LcvIQ7zw3su2JFBCrRsWMBCOhC2+VqHrcZ8hRG7jXrYmAj2snNXp1JQRvuuNQuwY3GotLAt7bNt7V5IIePCFw6fjILmTkE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210612; 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=jFjpI4hzqVt2RJdVVk5njeG2P3S+vyB+6Aiq0fRi65I=; b=NlA1zlQjqG7FvmVZvYjAi8SEvbZi+aClJlOxiefo101dl/HmROoUS8Ymp2LZTJrwGENTcGn6Z0BA5TEtDkNx9D40TtRdKbGna9578sg/rCQsbfEOS5QJ2YoVRRA0uX3tEhfvqL85Co52hb+/WJs1T/P9da982oM7HSs0Kg386EE= 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 1600210612507491.2530496886004; Tue, 15 Sep 2020 15:56:52 -0700 (PDT) Received: from localhost ([::1]:35812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJsZ-0008PO-8j for importer@patchew.org; Tue, 15 Sep 2020 18:56:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdl-0007Zv-IG for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:58203) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdj-0002iI-6u for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-213-RBWRdw7NP8uv7HrOKEOi4w-1; Tue, 15 Sep 2020 18:41:25 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6EE1F80732A; Tue, 15 Sep 2020 22:41:24 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82BF060BE5; Tue, 15 Sep 2020 22:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209690; 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=jFjpI4hzqVt2RJdVVk5njeG2P3S+vyB+6Aiq0fRi65I=; b=K8bs7rGlu1DbwKc2vkz1eQaorZnDdfoNoxBEu68aHS7U0cVVDExuvV11OsRVw1yLmE9isT zQ4jFAw4Va8Ghcw2/fUpQvcvYiy7Mf7WFZ2EDqDIJgQ5mwvBYIUHCgk/CHdcylxqat3Ry9 p/LU9JdH53VUwukY2J7bZz9lxr1BAzM= X-MC-Unique: RBWRdw7NP8uv7HrOKEOi4w-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 34/37] qapi/types.py: add notational type hints Date: Tue, 15 Sep 2020 18:40:24 -0400 Message-Id: <20200915224027.2529813-35-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- 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 9ce8b56f22..3babc380a8 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 53b47f9e58..274d62fac8 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 Optional, List + from .common import ( c_enum_const, c_name, @@ -21,7 +23,16 @@ mcgen, ) from .gen import QAPISchemaModularCVisitor, ifcontext -from .schema import QAPISchemaEnumMember, QAPISchemaObjectType +from .source import QAPISourceInfo +from .schema import ( + QAPISchema, + QAPISchemaEnumMember, + QAPISchemaObjectType, + QAPISchemaVariants, + QAPISchemaObjectTypeMember, + QAPISchemaFeature, + QAPISchemaType, +) =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 Thu Apr 18 14:32:38 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=1600211373; cv=none; d=zohomail.com; s=zohoarc; b=NHhbLkuo6UR0zitp6JfaNlTaJZ0tBVcC/quTs9bkv/p1Bt458ISoWaEp8t/NDsDak6FRONGgSbVVXIE/9TvbCXjCNzWjvXfNSVpu8o/miiWpQY0gkrm9OXSTejD9PnGIG59LnOELgnw7JFlk3dzNWbt/THlsIvwEYP/30jOjxew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600211373; 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=asnqf+6Vai1qIfw6CHYSJVBHm5QKlKuylIT9SkdgwV4=; b=PcTLpf8F59Ak0qRvEzeN5niC+fxz8RZNNMC3QvOLy1dOrfp8E5y+bD+dbxgQnPqtIqtTjRi/JBQoa5lKxuSn7opZF8mnJYOiSwMbVcSp2+lGBhy6e6w8iz9l6fGhSuRxY3KpHWp6M/LZ3mMyCJfHCNnx7ODUCpwkbPGgTzl6ypM= 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 160021137376457.11482524544556; Tue, 15 Sep 2020 16:09:33 -0700 (PDT) Received: from localhost ([::1]:46054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIK4q-0007Oy-Ky for importer@patchew.org; Tue, 15 Sep 2020 19:09:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJeE-0007py-BE for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:42:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46219) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJe8-0002kM-PB for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:42:01 -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-353-mEIk7QMiNr6ABqOphL4Wwg-1; Tue, 15 Sep 2020 18:41:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8863E190A3EE; Tue, 15 Sep 2020 22:41:25 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AB5860BE5; Tue, 15 Sep 2020 22:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209710; 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=asnqf+6Vai1qIfw6CHYSJVBHm5QKlKuylIT9SkdgwV4=; b=dmUNn4qw1PWMbDClNmc1cuUDx+j8eqv7xZzsWpOxt6wW7s9QYPctNcl11opAXO1QSzcDeB JAuvWMMIbGP88aRQdVR7PIksC/J4uw7CMpw2b5sDwFP98n5qYyjr+bLPyFW4sooaaGc4di lFTzhjtTKWdjUkBwXPpIUP5YiGDRrxg= X-MC-Unique: mEIk7QMiNr6ABqOphL4Wwg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 35/37] qapi/types.py: remove one-letter variables Date: Tue, 15 Sep 2020 18:40:25 -0400 Message-Id: <20200915224027.2529813-36-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- 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 3aebb0d228..9ca6b60caf 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -7,7 +7,6 @@ ignore-patterns=3Ddoc.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 274d62fac8..a0a06b68c5 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 member in members: + ret +=3D gen_if(member.ifcond) + index =3D c_enum_const(name, member.name, prefix) ret +=3D mcgen(''' [%(index)s] =3D "%(name)s", ''', - index=3Dindex, name=3Dm.name) - ret +=3D gen_endif(m.ifcond) + index=3Dindex, name=3Dmember.name) + ret +=3D gen_endif(member.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 member in enum_members: + ret +=3D gen_if(member.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, member.name, prefix)) + ret +=3D gen_endif(member.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 variant in variants.variants if variants else (): + obj =3D variant.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 Thu Apr 18 14:32:38 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=1600211088; cv=none; d=zohomail.com; s=zohoarc; b=VlmyQ08c9YIKcSNkkJNOkgtcs/RUuu1nlH9lj0C3i1M0lHrCISB8KmDQqmwqjV2F4VutG0pU4m5tkfaGlJsGgeAAkDBXVUlHZJOhJs0hD6wLczrTvIIusrhebYW2XonZfjFQIY/M+pbTNCEYS6ZCeAUbHtyca+ZM/xSts7f6E1w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600211088; 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=/XQOZX3YlzB8uPAvQhr5pSb6yHYAjMkNZEf2C0oaaOY=; b=Ccc7BFBUXnyRBbGqTVgGL5fBwj3vszUmp+fadMtqzb9TMMxQkFTeOmFp9SeQK8VTZ0YMgIfm6ONaBcQsyrt3kAuNTiw4zP6VrhYRpRw4bfCTb/H3a88+1bWmzTwOMMacyMUmUk7YaW1hssC8PAX7bm7m0g2E2hMz/t0TR1yKCNc= 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 160021108899328.21267052026235; Tue, 15 Sep 2020 16:04:48 -0700 (PDT) Received: from localhost ([::1]:60964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIK0F-0001td-LL for importer@patchew.org; Tue, 15 Sep 2020 19:04:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdm-0007bx-Fl for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35414) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdk-0002ie-KQ for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-339-4uqy7edVNZWgGMkL2Py_CA-1; Tue, 15 Sep 2020 18:41:28 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 022AA190A403; Tue, 15 Sep 2020 22:41:27 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE78A60BE5; Tue, 15 Sep 2020 22:41:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209691; 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=/XQOZX3YlzB8uPAvQhr5pSb6yHYAjMkNZEf2C0oaaOY=; b=NijK9EKM1msOaVqMjuGfTF72A+fr5oC9pBMuLFPK1w0S3iFLiEpjhmlnx5OHc4zg5UQ3bo xKtjIiMYCRzNIWSBaYp//JDTq/tl7ZHWXdOEZ0meCo3h7Hculp595El8ewb8i1d9zRi/We 07UMml6ocbGNhTBxYTte6lBm/aHXnYc= X-MC-Unique: 4uqy7edVNZWgGMkL2Py_CA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 36/37] qapi/visit.py: remove unused parameters from gen_visit_object Date: Tue, 15 Sep 2020 18:40:26 -0400 Message-Id: <20200915224027.2529813-37-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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/09/15 02:10:32 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, 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: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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" And this fixes the pylint report for this file, so make sure we check this in the future, too. Signed-off-by: John Snow --- 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 9ca6b60caf..9d7a1d285f 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -7,7 +7,6 @@ ignore-patterns=3Ddoc.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 66ce3dc52e..ce71659a03 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -247,7 +247,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, %(c_name)s **obj, @@ -340,7 +340,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 Thu Apr 18 14:32:38 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=1600210758; cv=none; d=zohomail.com; s=zohoarc; b=BAiLDVQfsDv06ltd+1hIaD9Da+qNSgt8oXMovTxAAY1Gt2/aTjXX/1YHEOrm5KvjgfdGhf8RaVztmPjj5qVysCCM75sdE1RtIztS6cT0tHoflqDa0+ceBNjk1pICaYYa21o7Y8V/p944G0WECt6zavDeYLWDamU1zJwYlFIQ+Xg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600210758; 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=MSd8kx5ETUkpHpfpPM+dGA5JPQT4rsFzyDTt6W/zLvw=; b=Habei8MXiuz+mwS6t8+DQNprULN16lwVY0GqGUwtz+iMWs4hBmLqNnCCoqRNcQmPJKjAshPJtW9iFfdr+ankHq/tGQ9uzSzz7bO00qzkQmcaFCKwlmW4Qlk9I2DfnN1Kttsrz7WfMI/6dk8s+d9SlkDNW1x3OVQEbW967fvocJk= 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 1600210758074481.91109597286334; Tue, 15 Sep 2020 15:59:18 -0700 (PDT) Received: from localhost ([::1]:44192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIJuu-0003MZ-Jo for importer@patchew.org; Tue, 15 Sep 2020 18:59:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59632) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIJdn-0007e3-HH for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41:36 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:39982 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIJdk-0002iY-Cp for qemu-devel@nongnu.org; Tue, 15 Sep 2020 18:41: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-94-19v9y0UzMASYDg6Y-9T6HQ-1; Tue, 15 Sep 2020 18:41:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 884798030A1; Tue, 15 Sep 2020 22:41:28 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B2FE60BE5; Tue, 15 Sep 2020 22:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600209691; 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=MSd8kx5ETUkpHpfpPM+dGA5JPQT4rsFzyDTt6W/zLvw=; b=PbieldSSACxccDyK+qJjUP6HFgMkPQeYhiZS2XI+qeyr1RhWr0qAhn7J/1CZPeA1+aHVo/ GYytudQpd951E1KF5DgaTo78/J0ufqtDvTnIZqh7ZwQHaj1jHMzWcg0yqVoXsL9gUs1u/b Q2e0S9cpBlbeJpJPqq/5s64yS+6Nj9I= X-MC-Unique: 19v9y0UzMASYDg6Y-9T6HQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH 37/37] qapi/visit.py: add notational type hints Date: Tue, 15 Sep 2020 18:40:27 -0400 Message-Id: <20200915224027.2529813-38-jsnow@redhat.com> In-Reply-To: <20200915224027.2529813-1-jsnow@redhat.com> References: <20200915224027.2529813-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0.001 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=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 18:40:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.999, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Peter Maydell , =?UTF-8?q?Alex=20Benn=C3=A9e?= , 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 --- scripts/qapi/mypy.ini | 5 --- scripts/qapi/visit.py | 72 +++++++++++++++++++++++++++++++++---------- 2 files changed, 55 insertions(+), 22 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 3babc380a8..5ab3433c5f 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 ce71659a03..035521476f 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,19 @@ INDENT, ) from .gen import QAPISchemaModularCVisitor, ifcontext -from .schema import QAPISchemaObjectType +from .schema import ( + QAPISchema, + QAPISchemaEnumMember, + QAPISchemaFeature, + QAPISchemaObjectType, + QAPISchemaObjectTypeMember, + QAPISchemaVariants, + QAPISchemaType, +) +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 '*' @@ -36,7 +47,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); @@ -44,7 +55,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) @@ -122,7 +136,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, %(c_name)s **obj, @@ -156,7 +170,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, %(c_name)s *obj, @@ -171,7 +185,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, %(c_name)s **obj, @@ -247,7 +261,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, %(c_name)s **obj, @@ -282,12 +296,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" @@ -299,7 +313,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(''' @@ -316,18 +330,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 @@ -342,13 +372,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