From nobody Sun May 19 03:02:44 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=1600808608; cv=none; d=zohomail.com; s=zohoarc; b=ar5S2pT+mhG+SRZ4bNhEtMeseI/jbdS+kqa6dHYEeHQfaFmfFwEb68A9mfZNeXPGTc7kO9Yiy3fo9J5BP1hWma7oRuBVaF8unatljYESCq9N6q74raFCHsmrifK5pHQARc7mNXdsDNRP/LLS/Krawnrq97n6IdqFg5gpKmr93Eg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600808608; 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=WtravlbykbezhMIGT1D1DVs1rwmvdqPa51+1QjM5Nioo9YWAtu05E1OdpMYpVlYpwIrMQeKPkDTF+Jy+fNyvUVadp2l4gQXHwL5RCuVsVAkiliMvGoRIOHR/QfMa/+tAQbFNxpAvw75mP5zTmXq40WXJ12ARfeIqKZNAhPo4YsE= 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 1600808608511783.9975570071705; Tue, 22 Sep 2020 14:03:28 -0700 (PDT) Received: from localhost ([::1]:36026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpRe-0003Xp-7V for importer@patchew.org; Tue, 22 Sep 2020 17:03:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpPU-0001tA-8t for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57192) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPR-0004XA-Co for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:10 -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-403-R-AA6rvxNWKnodzD_SpNSg-1; Tue, 22 Sep 2020 17:01:06 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 537C21007464; Tue, 22 Sep 2020 21:01: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 A33FE5577A; Tue, 22 Sep 2020 21:01:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808468; 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=Lkw5YVpfleKaQGP1FWIWle0zTMyxc+HWNaPKebszaF4Y1X+/IGWZcYg/IIqxXfGL/waW4p Mw1AswQrHNgvdNXPlzJlGZh8XAX9B6xMmoHQ07w2BVjj2Kv2GImSN8hujPTlhdkxJGfx2m PUsU5j2i7pVO2NLCzpU7zeS518SjOII= X-MC-Unique: R-AA6rvxNWKnodzD_SpNSg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 01/38] [DO-NOT-MERGE] qapi: add debugging tools Date: Tue, 22 Sep 2020 17:00:24 -0400 Message-Id: <20200922210101.4081073-2-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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 Sun May 19 03:02:44 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=1600808817; cv=none; d=zohomail.com; s=zohoarc; b=PWj5Kmc3IRStEnhd7vaAXMB19lJMo7YSC/M6gLSjuzXSbe1vTNfg0K9egkT31Nb/Qcq/3GKdmW69C61ynNJz6EiuX69xxS/azKS9sAdwlOglZRBULyO1wAipW4WuBfGRkrKY8YKhxf5Sbn0LMPJyhVa0tQsEXd2K6865tQcXtK8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600808817; 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=CKKxnfFbEr/XggyNswMl/xAgfo2oT8IHB9rT0zmWHHO3VAQBsk8WVxpQ8ag3wYdi66lpj8/ZzUM0zmt+3vrRYJycIleoy3II2S88v+W29fHzY+Ky8IN+j1+xrEMqSs0TBcOcVJFWvISRfJmi+KCD+HbQd34GMBohC8SqYrLt8YU= 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 1600808817855181.15255961405217; Tue, 22 Sep 2020 14:06:57 -0700 (PDT) Received: from localhost ([::1]:45944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpV2-0007jN-Hu for importer@patchew.org; Tue, 22 Sep 2020 17:06:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpPX-0001wO-5H for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPU-0004XU-3a for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01: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-136-oxGLLNteM-Wt4rALAt3CEw-1; Tue, 22 Sep 2020 17:01:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6E68A64086; Tue, 22 Sep 2020 21:01: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 7A88A5577A; Tue, 22 Sep 2020 21:01:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808471; 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=WYq6M6N+PUn4VH0KhYRQf9g0Eg2187hjDOD5S8uKoDwLPOxT1Uy5/06FkkGVZa2/3RB/en QQelvy3qiypE7Eit4oL6AaRw8CAPMu0QIAsqLgq+7zhge0z5IG7lkhVxkbK25gqryAK/JA EHfy/ZJUqOg70YX2bi5QqyiRUaH2UD8= X-MC-Unique: oxGLLNteM-Wt4rALAt3CEw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 02/38] qapi-gen: Separate arg-parsing from generation Date: Tue, 22 Sep 2020 17:00:25 -0400 Message-Id: <20200922210101.4081073-3-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is a minor re-work of the entrypoint script. It isolates a generate() method from the actual command-line mechanism. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost --- 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 Sun May 19 03:02:44 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=1600809767; cv=none; d=zohomail.com; s=zohoarc; b=SvN330ObG/m5YVxs0O4oWjB7vf4OoXH9pHi/WQA9P1YgKZ7lN6xFS7SpNi0qoskAEA0EcvHKNrgWm0udYi3yHzWxuDenqpjQhiiGICSydozNI10QbbGYtjlT0PTAdafEpB2uVojPqlZcPWqmm3tIMJir9KPzPzVW1j7ZiNsWJlM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809767; 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=3UU1f30mAPcojDQT/qB9LLJq4ufRtwwhjbSiZBJqr3s=; b=N/JHnZjE1kD2mXnDU5WaFWGFUbnqv/u7KD4qdweBNumTBguqbWifF2N+Soulq0Ngbgs0GdP+leShXHX3R6VLepW5JZ61Dpn+TU0wNp0CtHJOktHwR5s4J5bcjTV6+3Xz6HoKu21agZbBuVFJOQqW4lXfW8xACxCE954lzDaJKsg= 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 160080976796760.94213259136018; Tue, 22 Sep 2020 14:22:47 -0700 (PDT) Received: from localhost ([::1]:39638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpkM-000478-Ka for importer@patchew.org; Tue, 22 Sep 2020 17:22:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ5-0002If-4O for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44932) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPy-0004aV-Uw for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-163-DiA-hk2XPIa_BM87Wq286A-1; Tue, 22 Sep 2020 17:01:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 252A96408A; Tue, 22 Sep 2020 21:01: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 63EFA55783; Tue, 22 Sep 2020 21:01:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808502; 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=3UU1f30mAPcojDQT/qB9LLJq4ufRtwwhjbSiZBJqr3s=; b=OAFay8toIrkNrAOIUWZ/uz20z9OOPqA6pOGrnuiDxbqs8ZU4p44SShuBt5nfNDJNeC+mdN Bsw5vcaFLpIewlVx+rO5xLmOPxa1AEsnlQHacHELG2YgYq8+Odhwjnv6M206RHeA11mf5T A3BXwgnCQLhu7bMGzzfIG0SErh3D1p4= X-MC-Unique: DiA-hk2XPIa_BM87Wq286A-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 03/38] qapi: move generator entrypoint into module Date: Tue, 22 Sep 2020 17:00:26 -0400 Message-Id: <20200922210101.4081073-4-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" As part of delinting and adding type hints to the QAPI generator, it's helpful for the entrypoint to be part of the package, only leaving a very tiny entrypoint shim outside of the module. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost Tested-by: Cleber Rosa --- scripts/qapi-gen.py | 90 +++---------------------------------------- scripts/qapi/main.py | 91 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 84 deletions(-) create mode 100644 scripts/qapi/main.py diff --git a/scripts/qapi-gen.py b/scripts/qapi-gen.py index 59becba3e1..f3518d29a5 100644 --- a/scripts/qapi-gen.py +++ b/scripts/qapi-gen.py @@ -4,94 +4,16 @@ # See the COPYING file in the top-level directory. =20 """ -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 standalone script exists primarily to facilitate the running of the Q= API +code generator without needing to install the python module to the current +execution environment. """ =20 -import argparse -import re import sys =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 main =20 if __name__ =3D=3D '__main__': - sys.exit(main()) + sys.exit(main.main()) diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py new file mode 100644 index 0000000000..18c246bbb4 --- /dev/null +++ b/scripts/qapi/main.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 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 --=20 2.26.2 From nobody Sun May 19 03:02:44 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=1600808721; cv=none; d=zohomail.com; s=zohoarc; b=Jz8Gdz/kOSTeoI5EB7cKhIWWWbNVn8M0tLWRL0ClEUVS6D8d4d3vbUiDfSs2W+oqAqFjwCcug0VwHBpmflvQQWH6dHy0DPeh9RiPS+1Vpd6aY1/CeraAhfETk2R+hn2hVYlblN39cXLlMIGfOovChLBP+S+M2ES4+txFu4iUQUQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600808721; 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=dnzOMpQr25DzsnyU3G84EU6kEpnrrG03CeH5K5qcbJo=; b=cXy8r822Qgwtm2CRLpTLgAet4wZfGwm5bAHuRRP3JNTGsqcqRY2ytvGjzGvVfru4OKCNxJLlATbJG0esV9sHegCYanObd7Omyavx9a6YrVeBnhEOZZPziWwbSgtPgWU2Y2wFjgvMj+lK6SHkP+H0LrQyDj3Pni2tB+6FX4at6Wk= 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 1600808721633278.261073408329; Tue, 22 Sep 2020 14:05:21 -0700 (PDT) Received: from localhost ([::1]:42862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpTU-0006NV-7E for importer@patchew.org; Tue, 22 Sep 2020 17:05:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36962) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpPc-0001zm-II for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42345) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPa-0004Xy-8p for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01: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-506-0GS3tC7_NP6xVD8hN8L-nA-1; Tue, 22 Sep 2020 17:01:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 433811007464; Tue, 22 Sep 2020 21:01: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 4C63F5577A; Tue, 22 Sep 2020 21:01:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808477; 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=dnzOMpQr25DzsnyU3G84EU6kEpnrrG03CeH5K5qcbJo=; b=CPWtLk/mIcxje6tMfQLjLylwvA83zcHoX3MHCtsmFmbKiqjM32vw+F/5wVC/EvEUNWvDBp M07u/MO/vHaHf8xTrUTnm9RsEEoE8xa2KzjLAuLqZnGiPPxg3FnnI4iN5nx3GSOk04LXkq 5V96hsy2FAJGN45Q6oFJ7Llwp/oki3Y= X-MC-Unique: 0GS3tC7_NP6xVD8hN8L-nA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 04/38] qapi: Prefer explicit relative imports Date: Tue, 22 Sep 2020 17:00:27 -0400 Message-Id: <20200922210101.4081073-5-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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" All of the QAPI include statements are changed to be package-aware, as explicit relative imports. A quirk of Python packages is that the name of the package exists only *outside* of the package. This means that to a module inside of the qapi folder, there is inherently no such thing as the "qapi" package. The reason these imports work is because the "qapi" package exists in the context of the caller -- the execution shim, where sys.path includes a directory that has a 'qapi' folder in it. When we write "from qapi import sibling", we are NOT referencing the folder 'qapi', but rather "any package named qapi in sys.path". If you should so happen to have a 'qapi' package in your path, it will use *that* package. When we write "from .sibling import foo", we always reference explicitly our sibling module; guaranteeing consistency in *where* we are importing these modules from. This can be useful when working with virtual environments and packages in development mode. In development mode, a package is installed as a series of symlinks that forwards to your same source files. The problem arises because code quality checkers will follow "import qapi.x" to the "installed" version instead of the sibling file and -- even though they are the same file -- they have different module paths, and this causes cyclic import problems, false positive type mismatch errors, and more. It can also be useful when dealing with hierarchical packages, e.g. if we allow qemu.core.qmp, qemu.qapi.parser, etc. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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/main.py | 16 ++++++++-------- scripts/qapi/parser.py | 4 ++-- scripts/qapi/schema.py | 8 ++++---- scripts/qapi/types.py | 6 +++--- scripts/qapi/visit.py | 6 +++--- 11 files changed, 35 insertions(+), 35 deletions(-) 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/main.py b/scripts/qapi/main.py index 18c246bbb4..3f8338ade8 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -11,14 +11,14 @@ 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 +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 =20 =20 DEFAULT_OUTPUT_DIR =3D '' 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/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 Sun May 19 03:02:44 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=1600808980; cv=none; d=zohomail.com; s=zohoarc; b=ANbab/UWQq8JdZNbOC2S2zHr2FpuBTWYXCO7pgf6x/E35QBZKLKoOvHgR1CFszV9C/nDWEjYd6m96R+vX7+Sp67DwUIQ1mXTbcJFdKT3ugIKf78wi+zRHwxUPfQQDDP2swzWEUKmP3ymDsqANVSANZUunXgdVs+vrZHKfLT9lJM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600808980; 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=QDFtIfhG0MifoykbTaXpG60w+Q3gZWmXZaTvxjIYhxQ=; b=Xs0tkfgAmre3yKnfEyYOoyoSJ/d4CEyVVLfnX2onWSmb/ng76jy4MfIkM+H1ikhXHaaVTwFr2daK+eRq0Z5yI0v0YaLfHyr6ZQ932+sUBP+W4W8QWY9tRG7+4aevBDrtA/7u0NY2Syhd6QnHWSS8XAHF+IucFtVsuSnY7ENYobY= 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 1600808980023710.8079500536668; Tue, 22 Sep 2020 14:09:40 -0700 (PDT) Received: from localhost ([::1]:54092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpXe-0002mq-Kx for importer@patchew.org; Tue, 22 Sep 2020 17:09:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpPe-0001zu-24 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52305) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPb-0004Y5-9A for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-504-Q9eqo74lPAGpX49EzvK0EQ-1; Tue, 22 Sep 2020 17:01:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 534D51074641; Tue, 22 Sep 2020 21:01:15 +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 68D4D55765; Tue, 22 Sep 2020 21:01:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808478; 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=QDFtIfhG0MifoykbTaXpG60w+Q3gZWmXZaTvxjIYhxQ=; b=TI4YlQzOdEuy8ORIkU4eqnrzYMoW1hTTPlOcj+yNhLaHGCPY57lhFJXhq0garCL0gQ5Oag tWFiVrpz9Z5uh0uT5D1PT4sKdLgMbWJe/nrxz2wGtBMk/eNny3+CX7xijaBWuZ5MEvbDeK 24VjBnCsaVFYdA97tYamwbeTmFbtcMg= X-MC-Unique: Q9eqo74lPAGpX49EzvK0EQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 05/38] qapi: Remove wildcard includes Date: Tue, 22 Sep 2020 17:00:28 -0400 Message-Id: <20200922210101.4081073-6-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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. flake8 also flags each one as a warning, as it is not smart enough to know which names exist in the imported file. Remove them and include things explicitly by name instead. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 Sun May 19 03:02:44 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=1600809233; cv=none; d=zohomail.com; s=zohoarc; b=Tc9QvTWFdH5jeJeQdM9jrgW8hpaImrW4SUPtgAickAJywnMnirsrgCXAyQXaDggBouT9jpWu7tYZ76dUe5qgvqYNPhlBBEgztuUvQrHd93WzgoIV59cNZi9rw23u8NEaCCeX5gkDpsNCm/Kv1VtqqGS9CmxYV1GP2OL8BAaSaD8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809233; 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=BYuTFD1tqhO7d1AdTxU4t1KC53WtZomH05jT65ra51A=; b=QNAIBE63PE42wKWKN3UVEi68kfJ2chjSV0kSJO9GCGdSRDYFxYayv+OcvBK5rFVjKUwax2+7UNqW9863fO+no+LEn3Fszu4UtGe1HGl6WtEggDt4hLI1acCsTNuYHXEvbd6Waau8lG5W91scicB8kHXHo9KxqFp5LfO/EnqL1jo= 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 1600809233695872.2401162271414; Tue, 22 Sep 2020 14:13:53 -0700 (PDT) Received: from localhost ([::1]:41618 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpbk-0001Ab-DX for importer@patchew.org; Tue, 22 Sep 2020 17:13:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpPi-000207-Bk for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55391) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPb-0004YF-VA for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01: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-595-AtFsug9tNCy9_q8BYujaJA-1; Tue, 22 Sep 2020 17:01:17 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 643CC1007464; Tue, 22 Sep 2020 21:01: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 7BC0055765; Tue, 22 Sep 2020 21:01:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808479; 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=BYuTFD1tqhO7d1AdTxU4t1KC53WtZomH05jT65ra51A=; b=O0yyS+sQgPUEGjA9PMvbyfOyeiTZilGNp8iuAskxTtaWsAevP2l45QhzY0kxurgVTT4fpI vukdOyUr+uLs61Liy7h0chz/FIKJUd7sFwjkKP9Ow3msZYbJgM7/kDb4dOaHQzOuY9GKWP HV1nWdr7DC+frP7xgnTmRjE6FPNpV50= X-MC-Unique: AtFsug9tNCy9_q8BYujaJA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 06/38] qapi: delint using flake8 Date: Tue, 22 Sep 2020 17:00:29 -0400 Message-Id: <20200922210101.4081073-7-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Petty style guide fixes and line length enforcement. Not a big win, not a big loss, but flake8 passes 100% on the qapi module, which gives us an easy baseline to enforce hereafter. A note on the flake8 exception: flake8 will warn on *any* bare except, but pylint's is context-aware and will suppress the warning if you re-raise the exception. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- scripts/qapi/.flake8 | 2 ++ scripts/qapi/commands.py | 3 ++- scripts/qapi/schema.py | 8 +++++--- scripts/qapi/visit.py | 16 +++++++++++----- 4 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 scripts/qapi/.flake8 diff --git a/scripts/qapi/.flake8 b/scripts/qapi/.flake8 new file mode 100644 index 0000000000..6b158c68b8 --- /dev/null +++ b/scripts/qapi/.flake8 @@ -0,0 +1,2 @@ +[flake8] +extend-ignore =3D E722 # Prefer pylint's bare-except checks to flake8's diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index e1df0e341f..d9cda3b209 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..808410d6f1 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -31,7 +31,9 @@ def gen_visit_decl(name, scalar=3DFalse): if not scalar: c_type +=3D '*' return mcgen(''' -bool visit_type_%(c_name)s(Visitor *v, const char *name, %(c_type)sobj, Er= ror **errp); + +bool visit_type_%(c_name)s(Visitor *v, const char *name, + %(c_type)sobj, Error **errp); ''', c_name=3Dc_name(name), c_type=3Dc_type) =20 @@ -125,7 +127,8 @@ def gen_visit_object_members(name, base, members, varia= nts): def gen_visit_list(name, element_type): return mcgen(''' =20 -bool visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj,= Error **errp) +bool visit_type_%(c_name)s(Visitor *v, const char *name, + %(c_name)s **obj, Error **errp) { bool ok =3D false; %(c_name)s *tail; @@ -158,7 +161,8 @@ def gen_visit_list(name, element_type): def gen_visit_enum(name): return mcgen(''' =20 -bool visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s *obj, = Error **errp) +bool visit_type_%(c_name)s(Visitor *v, const char *name, + %(c_name)s *obj, Error **errp) { int value =3D *obj; bool ok =3D visit_type_enum(v, name, &value, &%(c_name)s_lookup, errp); @@ -172,7 +176,8 @@ def gen_visit_enum(name): def gen_visit_alternate(name, variants): ret =3D mcgen(''' =20 -bool visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj,= Error **errp) +bool visit_type_%(c_name)s + (Visitor *v, const char *name, %(c_name)s **obj, Error **errp) { bool ok =3D false; =20 @@ -247,7 +252,8 @@ def gen_visit_alternate(name, variants): def gen_visit_object(name, base, members, variants): return mcgen(''' =20 -bool visit_type_%(c_name)s(Visitor *v, const char *name, %(c_name)s **obj,= Error **errp) +bool visit_type_%(c_name)s + (Visitor *v, const char *name, %(c_name)s **obj, Error **errp) { bool ok =3D false; =20 --=20 2.26.2 From nobody Sun May 19 03:02:44 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=1600808911; cv=none; d=zohomail.com; s=zohoarc; b=iIRqu/Yh3F7dSqfMtuKPWdYJgPOk3TkF7XScCYgs2xiqZg1lXlOB3CXbQqs2P0MInYq6Q80cVkxrkKUSzdObm92O9i8HsSwOjWhYeH8GktkYEr2JOPjlwM4ezOQ7bfJ6yJ8Ax8T+wliUGgH1lpmuN3LZ5Cdz2HYPij6FkKhYQY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600808911; 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=8RFT00FZTL8ygX6hYN6t8BOtTxbg9dnOFGKZdSeqQ+U=; b=CHQtWamHgWteqEmh3HLLMr6dRVbBA1yfUNky3v59RDu/0CLO3HFLPnZLUR6V4/qirueaXRnYXgATBaPj3fmdg33W9dadLjqkNK4AkVx7t5acku7yG0QnhKoJE/NQuJ2ToF2r2RLlI7stfE3v0eLBLodhxJCkuvtT6c2SfOWRiu0= 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 1600808911545879.3324738867152; Tue, 22 Sep 2020 14:08:31 -0700 (PDT) Received: from localhost ([::1]:50836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpWY-0001OS-7t for importer@patchew.org; Tue, 22 Sep 2020 17:08:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37016) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpPs-000217-BD for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:37 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:39991 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 1kKpPi-0004YZ-0l for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01: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-585-sMgTm_57OziEJ1jKYONmpg-1; Tue, 22 Sep 2020 17:01:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 76EFF1074659; Tue, 22 Sep 2020 21:01: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 8A5C15577A; Tue, 22 Sep 2020 21:01:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808482; 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=8RFT00FZTL8ygX6hYN6t8BOtTxbg9dnOFGKZdSeqQ+U=; b=P/UBI3ilrHBuO0wnFSej3MZPZjmx2ybVXcjvOnuD1xekPpf5BKj7nBMcL05pa39Hh8lAco awRStC3++xT44hnO1KVdN5iIQCsbhT/Dh4r64jwqhdMZNHITzD1XQ9fdL9C5FrTy2s3LGG SP7Ac2uJK66SrYM8yGyoi/eMuDFobOA= X-MC-Unique: sMgTm_57OziEJ1jKYONmpg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 07/38] qapi: add pylintrc Date: Tue, 22 Sep 2020 17:00:30 -0400 Message-Id: <20200922210101.4081073-8-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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=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/22 17:01:22 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Using `pylint --generate-rcfile > pylintrc`, generate a skeleton pylintrc file. Sections that are not presently relevant (by the end of this series) are removed leaving just the empty section as a search engine / documentation hint to future authors. Right now, quite a few modules are ignored as they are known to fail as of this commit. modules will be removed from the known-bad list throughout this and following series as they are repaired. Note: Normally, pylintrc would go in the folder above the module, but as that folder is shared by many things, it is going inside the module folder (for now). Due to a bug in pylint 2.5.x, pylint does not correctly recognize when it is being run from "inside" a package, and must be run *outside* of the package. Therefore, to run it, you must: > pylint scripts/qapi/ --rcfile=3Dscripts/qapi/pylintrc Signed-off-by: John Snow Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Tested-by: Eduardo Habkost --- 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..02dd22c863 --- /dev/null +++ b/scripts/qapi/pylintrc @@ -0,0 +1,74 @@ +[MASTER] + +# Add files or directories matching the regex patterns to the ignore list. +# The regex matches against base names, not paths. +ignore-patterns=3Dcommon.py, + 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 import statements themselves when computing similarities. +ignore-imports=3Dyes + +[TYPECHECK] + +[CLASSES] + +[IMPORTS] + +[DESIGN] + +[EXCEPTIONS] --=20 2.26.2 From nobody Sun May 19 03:02:44 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=1600809095; cv=none; d=zohomail.com; s=zohoarc; b=Hpo01IjJKnD6ZjPj2QxigqYY8czAXfvHaqnIdho8sIVljj+n4/hqJIbgAAgtRbRR0wCZAzSHBIzLaxhuA+R+UmDCCKB57wYIq46DqbUSWOHLD2584OwNx6qV+VoQiDNz7YTDu0DsOsUQbeFNuQGtvdcqFQSWA3vmVn90/jJZHyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809095; 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=kTo5tXluIAZo7BnSaXP+0ah/wdiNwdFnzC+WFFHmlUk=; b=V0lBuS948CFGzkFgRC7p7qHSR0ovfNiouw23AGcf1/PkxJjANtelK8u29cdKHg/Pt3tf4WaMtqIk+EYdXEzmZukCzP94WU2yYlKblg3P0HPJDPfDXy6gHU6AzQIZDPDvREcl/UBTzYRFRQ+5M5XtpCVj5jHIuUpYxGNDnCzjTTI= 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 1600809095287715.5965842388902; Tue, 22 Sep 2020 14:11:35 -0700 (PDT) Received: from localhost ([::1]:33986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpZV-0006Jg-Q8 for importer@patchew.org; Tue, 22 Sep 2020 17:11:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpPs-000216-BS for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31496) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPf-0004YU-KU for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01: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-235-m1Anwn41PXqxAD1WEmvh7Q-1; Tue, 22 Sep 2020 17:01:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B63211007464; Tue, 22 Sep 2020 21:01: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 9E46955765; Tue, 22 Sep 2020 21:01:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808481; 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=kTo5tXluIAZo7BnSaXP+0ah/wdiNwdFnzC+WFFHmlUk=; b=TCe65u9XJPnOldYAyejw2ENT7TZA9M0WrotIEWFQhzQKvazvG0ENC8YjMg77HzSlQoyzuE K8rOzLRb6B2RWHp3+Of2vedFyYvQsP+NBLvsH0qvQtZZjgyHd72ZYt3iyl1Prf/h9Wpe/7 9NxIqAYRzVm2NAZULdatoDCDYn9g/m4= X-MC-Unique: m1Anwn41PXqxAD1WEmvh7Q-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 08/38] qapi/common.py: Remove python compatibility workaround Date: Tue, 22 Sep 2020 17:00:31 -0400 Message-Id: <20200922210101.4081073-9-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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..cee63eb95c 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -119,10 +119,7 @@ def cgen(code, **kwds): raw =3D code % kwds if indent_level: indent =3D genindent(indent_level) - # re.subn() lacks flags support before Python 2.7, use re.compile() - raw =3D re.subn(re.compile(r'^(?!(#|$))', re.MULTILINE), - indent, raw) - raw =3D raw[0] + raw =3D re.sub(r'^(?!(#|$))', indent, raw, flags=3Dre.MULTILINE) return re.sub(re.escape(eatspace) + r' *', '', raw) =20 =20 --=20 2.26.2 From nobody Sun May 19 03:02:44 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=1600808611; cv=none; d=zohomail.com; s=zohoarc; b=J2ggfXulERSbi2gGyGiNBjoYfs4135/7lposmpgNcLrOCByWB/U/XKuxEqZx0bW9tYCE/MiPAHXoSa6+tBIYa81Y4bOwQNqhAG/ZEsQNlSrkHthMDCXtIYwvZEbbkq83sv6dqAQM4QrrF7/w0WnTcZzbYmgR/n62j1Po/Fcoy4U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600808611; 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=ghDb5rKOmGTyb03vCBBcn9DARDR8dEGxmDStUABhhqE=; b=ns/ui66kwqTIvu4MO370Faai2E9zOxoqRABRlmWcCt+jTHfBgQ+PeQ3Unnqc0EHK1Bln4UwTErQwWXtHIuo3dueynjYoekh/cLBwAqv7r/U00tHILtGYcnztvsOZfwWYasqwWrBFDI0afyPnWyC+bBriK31sGDiWDS3v+rup4eY= 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 1600808611600416.39149160245665; Tue, 22 Sep 2020 14:03:31 -0700 (PDT) Received: from localhost ([::1]:36350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpRi-0003g2-9m for importer@patchew.org; Tue, 22 Sep 2020 17:03:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpPw-00022Y-JC for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45950) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPq-0004Z3-PV for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:38 -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-109-6Vv_IK32Nu2WhiCCUWCLOA-1; Tue, 22 Sep 2020 17:01:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8506F80F056; Tue, 22 Sep 2020 21:01: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 0A3FB55765; Tue, 22 Sep 2020 21:01:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808488; 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=ghDb5rKOmGTyb03vCBBcn9DARDR8dEGxmDStUABhhqE=; b=Z1+y0zjWolhB2hKcYB+HH/FfcBaZniUJH2FpdnXiVr1Oms8Dw81wpuAMx4ydt1Tkz5a6JN FjO7Fjk4ZL31bq7UO1R29qXuf73b6bBtxN35rND84NyOmuOm4Fa/PStYXtFs64KRoLAn0g ElEFg1RNs2yXlW7ShpAiiaLgoHKBOlw= X-MC-Unique: 6Vv_IK32Nu2WhiCCUWCLOA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 09/38] qapi/common.py: Add indent manager Date: Tue, 22 Sep 2020 17:00:32 -0400 Message-Id: <20200922210101.4081073-10-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Code style tools really dislike the use of global keywords, because it generally involves re-binding the name at runtime which can have strange effects depending on when and how that global name is referenced in other modules. Make a little indent level manager instead. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- scripts/qapi/common.py | 51 +++++++++++++++++++++++++++++------------- scripts/qapi/visit.py | 7 +++--- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index cee63eb95c..e0c5871b10 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -93,33 +93,52 @@ def c_name(name, protect=3DTrue): pointer_suffix =3D ' *' + eatspace =20 =20 -def genindent(count): - ret =3D '' - for _ in range(count): - ret +=3D ' ' - return ret +class Indentation: + """ + Indentation level management. =20 + :param initial: Initial number of spaces, default 0. + """ + def __init__(self, initial: int =3D 0) -> None: + self._level =3D initial =20 -indent_level =3D 0 + def __int__(self) -> int: + return self._level =20 + def __repr__(self) -> str: + return "{}({:d})".format(type(self).__name__, self._level) =20 -def push_indent(indent_amount=3D4): - global indent_level - indent_level +=3D indent_amount + def __str__(self) -> str: + """Return the current indentation as a string of spaces.""" + return ' ' * self._level =20 + def __bool__(self) -> bool: + """True when there is a non-zero indentation.""" + return bool(self._level) =20 -def pop_indent(indent_amount=3D4): - global indent_level - indent_level -=3D indent_amount + def increase(self, amount: int =3D 4) -> int: + """Increase the indentation level by `amount`, default 4.""" + self._level +=3D amount + return self._level + + def decrease(self, amount: int =3D 4) -> int: + """Decrease the indentation level by `amount`, default 4.""" + if self._level < amount: + raise ArithmeticError( + f"Can't remove {amount:d} spaces from {self!r}") + self._level -=3D amount + return self._level + + +indent =3D Indentation() =20 =20 # Generate @code with @kwds interpolated. -# Obey indent_level, and strip eatspace. +# Obey indent, and strip eatspace. def cgen(code, **kwds): raw =3D code % kwds - if indent_level: - indent =3D genindent(indent_level) - raw =3D re.sub(r'^(?!(#|$))', indent, raw, flags=3Dre.MULTILINE) + if indent: + raw =3D re.sub(r'^(?!(#|$))', str(indent), raw, flags=3Dre.MULTILI= NE) return re.sub(re.escape(eatspace) + r' *', '', raw) =20 =20 diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 808410d6f1..4edaee33e3 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 @@ -69,7 +68,7 @@ def gen_visit_object_members(name, base, members, variant= s): if (visit_optional(v, "%(name)s", &obj->has_%(c_name)s)) { ''', name=3Dmemb.name, c_name=3Dc_name(memb.name)) - push_indent() + indent.increase() ret +=3D mcgen(''' if (!visit_type_%(c_type)s(v, "%(name)s", &obj->%(c_name)s, errp)) { return false; @@ -78,7 +77,7 @@ def gen_visit_object_members(name, base, members, variant= s): c_type=3Dmemb.type.c_name(), name=3Dmemb.name, c_name=3Dc_name(memb.name)) if memb.optional: - pop_indent() + indent.decrease() ret +=3D mcgen(''' } ''') --=20 2.26.2 From nobody Sun May 19 03:02:44 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=1600809324; cv=none; d=zohomail.com; s=zohoarc; b=X3h/m0Wm66p3gSvvFnSZRvb/Dql8BuPyYSuZVNfDmnpJdU1kCt1JEH8gFCeGYzlRvauVXzLSiIGKmGXvslPeHFmGbLlzcZywiq3NW3RWBS14rlXhgmVLmT7cFDPpykpihjS6Kex/hiZko3lFEcnmdY6nqcYrpej79SrqSpytl5g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809324; 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=Us/oDBvh6Rm7t7VwPH7ZlLF2BEUIP8iSpwElUFOQcz8=; b=bMaaw6IpKVypZYgvTgch+qHwpcIf4IUECX/qRW2yM8NE569pVvgvnApBA/Upopxm2TT5w/rlUyo9nGKj3YDGWkUbrV3yv4nOrWm7gloQ9OaZwfAXKw/PY9PV3Io3gSEaJ34FxW9yfiy9ES4h1XJguDMCUyCetlSDfzdrqT4SOqA= 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 1600809324822977.5756163904279; Tue, 22 Sep 2020 14:15:24 -0700 (PDT) Received: from localhost ([::1]:47174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpdD-0003Y7-IG for importer@patchew.org; Tue, 22 Sep 2020 17:15:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37164) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ0-00028H-RQ for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:39391) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPx-0004Yh-Ry for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-323-3InQFxdiP4Wp4XfHrpWf8g-1; Tue, 22 Sep 2020 17:01:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3D61420F4; Tue, 22 Sep 2020 21:01:21 +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 AAA6055765; Tue, 22 Sep 2020 21:01:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808486; 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=Us/oDBvh6Rm7t7VwPH7ZlLF2BEUIP8iSpwElUFOQcz8=; b=eDSUKBOz7a0iRmBCAOOzHbz6h2GmsmAfqAvxw/IAYf/IzKgZlXDq0I7VJraWZx9Ciwcz6b 6x1KktBSSg7FxqLiuCVzJG0ScQ+ZQ4QHBlnVt4zp8IkGhN9wMa8bYKl5dPIJyXnQntffhm ePV9P5993+Jx9KMU6r1CaWtHdFxEVLs= X-MC-Unique: 3InQFxdiP4Wp4XfHrpWf8g-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 10/38] qapi/common.py: delint with pylint Date: Tue, 22 Sep 2020 17:00:33 -0400 Message-Id: <20200922210101.4081073-11-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" At this point, that just means using a consistent strategy for constant nam= es. constants get UPPER_CASE and names not used externally get a leading unders= core. As a preference, while renaming constants to be UPPERCASE, move them to the head of the file. Generally, it's nice to be able to audit the code that runs on import in one central place. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- scripts/qapi/common.py | 18 ++++++++---------- scripts/qapi/schema.py | 14 +++++++------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index e0c5871b10..bddfb5a9e5 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -14,6 +14,11 @@ import re =20 =20 +EATSPACE =3D '\033EATSPACE.' +POINTER_SUFFIX =3D ' *' + EATSPACE +_C_NAME_TRANS =3D str.maketrans('.-', '__') + + # ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1 # ENUM_NAME -> ENUM_NAME, ENUM_NAME1 -> ENUM_NAME1, ENUM_Name2 -> ENUM_NAM= E2 # ENUM24_Name -> ENUM24_NAME @@ -42,9 +47,6 @@ def c_enum_const(type_name, const_name, prefix=3DNone): return camel_to_upper(type_name) + '_' + c_name(const_name, False).upp= er() =20 =20 -c_name_trans =3D str.maketrans('.-', '__') - - # Map @name to a valid C identifier. # If @protect, avoid returning certain ticklish identifiers (like # C keywords) by prepending 'q_'. @@ -82,17 +84,13 @@ def c_name(name, protect=3DTrue): 'not_eq', 'or', 'or_eq', 'xor', 'xor_eq']) # namespace pollution: polluted_words =3D set(['unix', 'errno', 'mips', 'sparc', 'i386']) - name =3D name.translate(c_name_trans) + name =3D name.translate(_C_NAME_TRANS) if protect and (name in c89_words | c99_words | c11_words | gcc_words | cpp_words | polluted_words): return 'q_' + name return name =20 =20 -eatspace =3D '\033EATSPACE.' -pointer_suffix =3D ' *' + eatspace - - class Indentation: """ Indentation level management. @@ -134,12 +132,12 @@ def decrease(self, amount: int =3D 4) -> int: =20 =20 # Generate @code with @kwds interpolated. -# Obey indent, and strip eatspace. +# Obey indent, and strip EATSPACE. def cgen(code, **kwds): raw =3D code % kwds if indent: raw =3D re.sub(r'^(?!(#|$))', str(indent), raw, flags=3Dre.MULTILI= NE) - return re.sub(re.escape(eatspace) + r' *', '', raw) + return re.sub(re.escape(EATSPACE) + r' *', '', raw) =20 =20 def mcgen(code, **kwds): diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 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 Sun May 19 03:02:44 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=1600810096; cv=none; d=zohomail.com; s=zohoarc; b=R7h9PdWpQhB9MPcux4sh4PtuoVd8Zwu9qRnqkZw8KWtloazB7OL9UiWNLE4wkCfLWNbw9IEQvV5/K0BF9cTAsZrHo03J89Ty9t3PEV96mF5mM6LQoeFpiG6xMiTtdMIcCKkXnVGxhPk3V6rbCSRmbKerxiwiwvdvFUL7mweKN1c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810096; 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=YxKa+PBG1Gkw9x/b9aY4+eW6f9wJE00d+CbIL8BiwRM=; b=mCRykFyyV+/9M188rzl4o2EHKICMLeEvhr4LiI3rT47sy1skLNA+LnGH8okC30Kpwxqy7l2pbb1OgbPA4WnE16yqVKbBqyqG0wsEk27gUDQxFHvwZAC3IpyhjIYzUMi+kLRINriDeYIvOhrKYlRJv5a9ifu9VKXAW498GQxsN0M= 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 1600810096191623.2583021706275; Tue, 22 Sep 2020 14:28:16 -0700 (PDT) Received: from localhost ([::1]:55346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKppe-0002ku-KK for importer@patchew.org; Tue, 22 Sep 2020 17:28:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ4-0002H2-BK for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60089) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPy-0004Yx-1t for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-198-Qclo0GSpMq2BoN5HyRLiKA-1; Tue, 22 Sep 2020 17:01:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 792FA1074641; Tue, 22 Sep 2020 21:01: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 187B85577A; Tue, 22 Sep 2020 21:01:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808488; 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=YxKa+PBG1Gkw9x/b9aY4+eW6f9wJE00d+CbIL8BiwRM=; b=CPVi97Tu6/1URO4qphW12WqUISTnu83oDIclasuVklj/paLNFiKTUirNTyQHC1dXBJC6jW TmPs2dYUsnumo9CVWi4LBEdf/u5Bs8B/7O/O60LA38pl92F3ancgPBq375rbmwDTAn+UgY 3CmjVE66d42MsgCHRwGtKn7EPKThPeo= X-MC-Unique: Qclo0GSpMq2BoN5HyRLiKA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 11/38] qapi/common.py: Replace one-letter 'c' variable Date: Tue, 22 Sep 2020 17:00:34 -0400 Message-Id: <20200922210101.4081073-12-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 bddfb5a9e5..682e74fe65 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -30,14 +30,14 @@ def camel_to_upper(value): new_name =3D '' length =3D len(c_fun_str) for i in range(length): - c =3D c_fun_str[i] - # When c is upper and no '_' appears before, do more checks - if c.isupper() and (i > 0) and c_fun_str[i - 1] !=3D '_': + char =3D c_fun_str[i] + # When char is upper case and no '_' appears before, do more checks + if char.isupper() and (i > 0) and c_fun_str[i - 1] !=3D '_': if i < length - 1 and c_fun_str[i + 1].islower(): new_name +=3D '_' elif c_fun_str[i - 1].isdigit(): new_name +=3D '_' - new_name +=3D c + new_name +=3D char return new_name.lstrip('_').upper() =20 =20 --=20 2.26.2 From nobody Sun May 19 03:02:44 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=1600809249; cv=none; d=zohomail.com; s=zohoarc; b=Hlt1j9GN5hQA2o/kEJp2YbFdWBtplTGWuTddZQsAKN9KvpoetVXKFUiPQvA3rpuLjE/CrYdm6NfdiwfrSPzCXERjIdbKIOGn0Ti7VmJkLqgtOOUJG5Ywlp8786pbprqYinYCxxevyOkD6v4pDqrikZlxmzpY3ru7+XafM7RpzD8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809249; 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=iyPjotsofwAivaxb5c15TPQyD6/fpddxsJGH537Fy3M=; b=NgcDO2IfRrhoKpo5L5xG5zQGSFqi/lbP8QDPe3nUR6jElJ3HT3Dtw4sGUjxYsYkTNLRqLPmiZ+wKA6t4bXWoVxnS2MbBqpwHvX9ZkrcvG3I3XmmnP++wQpL26mgen13jg8Y1Wy/tc6BBuj0oeC/yq9w5wV5AnkWYjS+6OhrlhEM= 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 1600809249476363.85957392339367; Tue, 22 Sep 2020 14:14:09 -0700 (PDT) Received: from localhost ([::1]:42418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpbz-0001WN-Vo for importer@patchew.org; Tue, 22 Sep 2020 17:14:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpPy-00024o-Pm for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47799) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPt-0004Yt-0v for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:42 -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-312-VqwJROFQPSGt40JOmYdatw-1; Tue, 22 Sep 2020 17:01:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EB8A9188C125; Tue, 22 Sep 2020 21:01: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 BEA3755765; Tue, 22 Sep 2020 21:01:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808488; 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=iyPjotsofwAivaxb5c15TPQyD6/fpddxsJGH537Fy3M=; b=e6SRm1a9SVaNdKnAF2y20QJ49mRdQcBCwTy4Au4r2o85p+6EIINYk8xdtSNeFUp2sTbd+v Pd0VS+GOYrAfqAbKX2mHaMAKdoWSUisai3kh4fZp88l8eRxqaMk26I7grYjQNaxrN+PvEm ugVxiCQbao8GiFHmQvCSK+3o02VnYoM= X-MC-Unique: VqwJROFQPSGt40JOmYdatw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 12/38] qapi/common.py: check with pylint Date: Tue, 22 Sep 2020 17:00:35 -0400 Message-Id: <20200922210101.4081073-13-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Remove qapi/common.py from the pylintrc ignore list. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa Tested-by: Eduardo Habkost --- scripts/qapi/pylintrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index 02dd22c863..6151427a51 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -2,8 +2,7 @@ =20 # Add files or directories matching the regex patterns to the ignore list. # The regex matches against base names, not paths. -ignore-patterns=3Dcommon.py, - doc.py, +ignore-patterns=3Ddoc.py, error.py, expr.py, gen.py, --=20 2.26.2 From nobody Sun May 19 03:02:44 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=1600809396; cv=none; d=zohomail.com; s=zohoarc; b=Km+bNL0Cuj2W8n4LTMbfMaqF1CglO31z21AkmDnLDwjPwoOsZeAB4mCmLfNjG1gTz8xJU6JYOLFlpf5nu0hY5FCXWdg2MjVcs3+PNRQyFYWlm2NW6z7mEuxkrraPtosvngovE1pd2GOPYuyRZq1PtHenm3t2aUlnaqYiknIuHCY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809396; 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=xmwwfzlaBCDTdjdnMa+Kl1+NU9ifQERLrJDUej62q84=; b=bWJWlHtZZyFUtOYede6nJFFZ3nevi9IBSCG0As21tylZhCFnzni1hqf6OwIiVduHea7CBch+0edO1lIgX5NqWI7svBNmBNnQl3uvlT07G/rPmeoARSLWnnamE5LOWFSMuktKojn46RyOZuEVMX361+GvMcSPQl4UIEpHVm4k6Do= 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 1600809396839886.5965537569836; Tue, 22 Sep 2020 14:16:36 -0700 (PDT) Received: from localhost ([::1]:49856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpeN-0004kF-Cn for importer@patchew.org; Tue, 22 Sep 2020 17:16:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ0-00027L-GX for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPu-0004Z9-AA for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:44 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-ZDOMmVudPLG3225DI7RoLw-1; Tue, 22 Sep 2020 17:01:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10AE1800469; Tue, 22 Sep 2020 21:01:26 +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 21B8055767; Tue, 22 Sep 2020 21:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808489; 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=xmwwfzlaBCDTdjdnMa+Kl1+NU9ifQERLrJDUej62q84=; b=TAhnAaxC826xYsxeiX3Y7+7P9u73IZf9A63D8y/tRqbfW1wykhPEmoYQS0/HNoZtlF/m3w JdcuD3Y6L7L7vgaEYxJwEOrvjWptE6Wx1N6Kind7yf6iRNynAAP6NWl9yexytr1MKSTKlL 1JDDDQMFuecB3Zk1hdqBdXwdCpd+NfQ= X-MC-Unique: ZDOMmVudPLG3225DI7RoLw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 13/38] qapi/common.py: add type hint annotations Date: Tue, 22 Sep 2020 17:00:36 -0400 Message-Id: <20200922210101.4081073-14-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 682e74fe65..0ce4a107e6 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -12,6 +12,7 @@ # See the COPYING file in the top-level directory. =20 import re +from typing import Optional, Sequence =20 =20 EATSPACE =3D '\033EATSPACE.' @@ -22,7 +23,7 @@ # ENUMName -> ENUM_NAME, EnumName1 -> ENUM_NAME1 # ENUM_NAME -> ENUM_NAME, ENUM_NAME1 -> ENUM_NAME1, ENUM_Name2 -> ENUM_NAM= E2 # ENUM24_Name -> ENUM24_NAME -def camel_to_upper(value): +def camel_to_upper(value: str) -> str: c_fun_str =3D c_name(value, False) if value.isupper(): return c_fun_str @@ -41,7 +42,9 @@ def camel_to_upper(value): return new_name.lstrip('_').upper() =20 =20 -def c_enum_const(type_name, const_name, prefix=3DNone): +def c_enum_const(type_name: str, + const_name: str, + prefix: Optional[str] =3D None) -> str: if prefix is not None: type_name =3D prefix return camel_to_upper(type_name) + '_' + c_name(const_name, False).upp= er() @@ -56,7 +59,7 @@ def c_enum_const(type_name, const_name, prefix=3DNone): # into substrings of a generated C function name. # '__a.b_c' -> '__a_b_c', 'x-foo' -> 'x_foo' # protect=3DTrue: 'int' -> 'q_int'; protect=3DFalse: 'int' -> 'int' -def c_name(name, protect=3DTrue): +def c_name(name: str, protect: bool =3D True) -> str: # ANSI X3J11/88-090, 3.1.1 c89_words =3D set(['auto', 'break', 'case', 'char', 'const', 'continue= ', 'default', 'do', 'double', 'else', 'enum', 'extern', @@ -133,24 +136,24 @@ def decrease(self, amount: int =3D 4) -> int: =20 # Generate @code with @kwds interpolated. # Obey indent, and strip EATSPACE. -def cgen(code, **kwds): +def cgen(code: str, **kwds: object) -> str: raw =3D code % kwds if indent: raw =3D re.sub(r'^(?!(#|$))', str(indent), raw, flags=3Dre.MULTILI= NE) return re.sub(re.escape(EATSPACE) + r' *', '', raw) =20 =20 -def mcgen(code, **kwds): +def mcgen(code: str, **kwds: object) -> str: if code[0] =3D=3D '\n': code =3D code[1:] return cgen(code, **kwds) =20 =20 -def c_fname(filename): +def c_fname(filename: str) -> str: return re.sub(r'[^A-Za-z0-9_]', '_', filename) =20 =20 -def guardstart(name): +def guardstart(name: str) -> str: return mcgen(''' #ifndef %(name)s #define %(name)s @@ -159,7 +162,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 */ @@ -167,7 +170,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(''' @@ -176,7 +179,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(''' @@ -185,7 +188,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 Sun May 19 03:02:44 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=1600809060; cv=none; d=zohomail.com; s=zohoarc; b=jfhU98eE3HUfwvYfSCdwUkXctQgKFFC6c5y7U093ihcdvlvyZDzJcawKf1x902sVZ6gTGMZTIz6XoJBu6d7To7Pm8MjKYEQ0hHISDkz5csaFXkXSBfICJSsq+G8Cj5NCKotIi7UzfG388BHbWt9ICpN98OmsezIq7DoMFtl3Dvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809060; 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=5SQ8w3odRh+wnwdi2Hx0UP7mPEEusa6HSgBmceA9Df8=; b=l+9Y1DolHJKm4LCdM7k5AKzrpf4UTbj0WSrBu7SxzKG5FkC09tmv7Cqvf2/gCajfzMBmdnx1qjEJ2SYwvbLRXUiMTGWRZQ+wlr0AxkFaiu/qFLz7cNx68mk6HEz01L7Pq4Ioa2KiokLCHWiXJ0GQV9e5QOFbCCq6OBhn4C2IQV4= 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 1600809060239639.053467981761; Tue, 22 Sep 2020 14:11:00 -0700 (PDT) Received: from localhost ([::1]:59004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpYw-0004r4-Uj for importer@patchew.org; Tue, 22 Sep 2020 17:10:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ0-000270-5a for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:44 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:56632 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 1kKpPw-0004ZK-9d for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:43 -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-539-9B-mL5M0OGeRS2Xw1KhDKw-1; Tue, 22 Sep 2020 17:01:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 245FE8014D9; Tue, 22 Sep 2020 21:01: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 36ED75577A; Tue, 22 Sep 2020 21:01:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808492; 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=5SQ8w3odRh+wnwdi2Hx0UP7mPEEusa6HSgBmceA9Df8=; b=elzd7yhWhW+8dXKccMqtoSGU+MOJMHuYmtEJmfHUqe4st1FXOqdNqNg1Uo0KrazhEVenXw /bOQY9rsTc6QeS4m61BgW8vIoxySij0OYjyLZvC8eTmQGZvRaxhirZ3+PVeqXFDnzfoCnq H6eUmwe3FVgy2OqkXe4KTt7gDiFdsGA= X-MC-Unique: 9B-mL5M0OGeRS2Xw1KhDKw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 14/38] qapi/common.py: Convert comments into docstrings, and elaborate Date: Tue, 22 Sep 2020 17:00:37 -0400 Message-Id: <20200922210101.4081073-15-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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=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/22 17:01:22 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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 Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- scripts/qapi/common.py | 51 ++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 0ce4a107e6..730283722a 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', @@ -134,9 +154,12 @@ def decrease(self, amount: int =3D 4) -> int: indent =3D Indentation() =20 =20 -# Generate @code with @kwds interpolated. -# Obey indent, and strip EATSPACE. def cgen(code: str, **kwds: object) -> str: + """ + Generate `code` with `kwds` interpolated. + + Obey `indent`, and strip `EATSPACE`. + """ raw =3D code % kwds if indent: raw =3D re.sub(r'^(?!(#|$))', str(indent), raw, flags=3Dre.MULTILI= NE) --=20 2.26.2 From nobody Sun May 19 03:02:44 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=1600809568; cv=none; d=zohomail.com; s=zohoarc; b=i+85qamZdo7whozyXVOFNhSr2ASEtxJmOco+2pFapUfPpHbkaNsT1wwKx90EENst8vTPLLMrXs5O8f4BaKgW1Y7DCFp6aDKwbqZCvlq3xErx2aizUKDQ6i+qMR06ZT8ucGSb2PPF5vOwqjIuOsnFhmlAyjvfbX0wB+e1tnGr08I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809568; 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=VoTXH1LT6mqnbGdmbNqN1uvPhns+MLUmlaxVx2YRzLk=; b=MGCNWYqerdVqhc5N3oFblvmFhJBfq4H5YFHT88BzlayclaJFFRHHsVMUWqNr1NGFalhZbALk1jx0y+se2hBfpTH50cYVZdLDMyr6uTRE8o75B+82RRQ0NWiwANrPUyDvlP1/rre3Sx8H71Ok8yVnT9Sf2E7QcMjeqmbJlsUuAC4= 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 1600809568507102.22878102135519; Tue, 22 Sep 2020 14:19:28 -0700 (PDT) Received: from localhost ([::1]:58432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKph9-0008Pk-1p for importer@patchew.org; Tue, 22 Sep 2020 17:19:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ2-0002C0-4q for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPx-0004ZO-Vl for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:45 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-593-sHTpNouFNuG9uRJ6e8hgDw-1; Tue, 22 Sep 2020 17:01:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7A0861005E5E; Tue, 22 Sep 2020 21:01: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 4DE4B55765; Tue, 22 Sep 2020 21:01:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808492; 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=VoTXH1LT6mqnbGdmbNqN1uvPhns+MLUmlaxVx2YRzLk=; b=ZJi6rH3xDWCGF0vADIdnPfTezP6X+LillqVFxlEyJcFyveURPQY9GwWThSPXkFHctwy7yp iAnHe7mpsd02BJHe+rxuBmh3XZ6E0ti2S7YadvcuzHC6UHMS7+owMlU1rokJhVMZ9if0Ta VyBK8SyqVXTOwcqZidDQ/V/6oe6VaXg= X-MC-Unique: sHTpNouFNuG9uRJ6e8hgDw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 15/38] qapi/common.py: move build_params into gen.py Date: Tue, 22 Sep 2020 17:00:38 -0400 Message-Id: <20200922210101.4081073-16-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Including it in common.py creates a circular import dependency; schema relies on common, but common.build_params requires a type annotation from schema. To type this properly, it needs to be moved outside the cycle. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- scripts/qapi/commands.py | 8 ++++++-- scripts/qapi/common.py | 23 ----------------------- scripts/qapi/events.py | 7 +++++-- scripts/qapi/gen.py | 34 ++++++++++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index d9cda3b209..9b3f24b8ed 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -14,11 +14,15 @@ """ =20 from .common import ( - build_params, c_name, mcgen, ) -from .gen import QAPIGenCCode, QAPISchemaModularCVisitor, ifcontext +from .gen import ( + QAPIGenCCode, + QAPISchemaModularCVisitor, + build_params, + ifcontext, +) =20 =20 def gen_command_decl(name, arg_type, boxed, ret_type): diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 730283722a..50c3d36e27 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..69a0ac5471 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -13,12 +13,15 @@ """ =20 from .common import ( - build_params, c_enum_const, c_name, mcgen, ) -from .gen import QAPISchemaModularCVisitor, ifcontext +from .gen import ( + QAPISchemaModularCVisitor, + build_params, + ifcontext, +) from .schema import QAPISchemaEnumMember from .types import gen_enum, gen_enum_lookup =20 diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 11472ba043..9898d513ae 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -2,9 +2,11 @@ # # QAPI code generation # -# Copyright (c) 2018-2019 Red Hat Inc. +# Copyright IBM, Corp. 2011 +# Copyright (c) 2013-2019 Red Hat Inc. # # Authors: +# Anthony Liguori # Markus Armbruster # Marc-Andr=C3=A9 Lureau # @@ -15,16 +17,21 @@ import errno import os import re +from typing import Optional =20 from .common import ( c_fname, + c_name, gen_endif, gen_if, guardend, guardstart, mcgen, ) -from .schema import QAPISchemaVisitor +from .schema import ( + QAPISchemaObjectType, + QAPISchemaVisitor, +) =20 =20 class QAPIGen: @@ -90,6 +97,29 @@ def _wrap_ifcond(ifcond, before, after): return out =20 =20 +def build_params(arg_type: Optional[QAPISchemaObjectType], + boxed: bool, + extra: Optional[str] =3D None) -> str: + ret =3D '' + sep =3D '' + if boxed: + assert arg_type + ret +=3D '%s arg' % arg_type.c_param_type() + sep =3D ', ' + elif arg_type: + assert not arg_type.variants + for memb in arg_type.members: + ret +=3D sep + sep =3D ', ' + if memb.optional: + ret +=3D 'bool has_%s, ' % c_name(memb.name) + ret +=3D '%s %s' % (memb.type.c_param_type(), + c_name(memb.name)) + if extra: + ret +=3D sep + extra + return ret if ret else 'void' + + class QAPIGenCCode(QAPIGen): =20 def __init__(self, fname): --=20 2.26.2 From nobody Sun May 19 03:02:44 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=1600809577; cv=none; d=zohomail.com; s=zohoarc; b=QFBOgJ5yZLgQtp2N9AEnLLX3oD7kmy+zGxMi/Uk3K+sksuAh31juThF5yae4GhQn8ijPUQXIEGH7aSdU9sC4ZbxeTwSOPv1Me0487yg2vf+sUsV43qmTjM56BH9ZmjtyXLY0zXw2rXj+FBofNyx5h1HkAJb8mCOx+M8IxSoNmBE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809577; 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=c8rJg2hW457XDEttHB6jSzmKv0FsM4P6jDozlZK17ce3st1BMBsHpaKJKfHd4julLesjPVGfV60/LrshsSAijitEtC6UupxOu9J827N0spfJyHLr47FUwuvhw1mM44pEul7xYRDUn3Pdbjo5V1G4hMmpcJUbOcdGCyoAMO88eS8= 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 1600809577323399.3706835737705; Tue, 22 Sep 2020 14:19:37 -0700 (PDT) Received: from localhost ([::1]:59246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKphH-0000JD-TV for importer@patchew.org; Tue, 22 Sep 2020 17:19:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ2-0002Cn-Fg for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:46 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:20517 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 1kKpPy-0004ZX-1P for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:45 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-543-es7J_1xjPreLsZULCXJfrA-1; Tue, 22 Sep 2020 17:01:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C1B861074659; Tue, 22 Sep 2020 21:01:29 +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 A293255765; Tue, 22 Sep 2020 21:01:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808494; 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=EZLHrBFWgSQrKEzPqk5gjP8Mw1AeN4TVjKia6sU62W3vh3XrqmQLjAzHyrMHlolVYATxZj 2BVjGOFTFB2IB9nIR09iGSYR8gQW7HGFOaaNozkGyP/LH6Qt/uG5a2vCDVL2hyMjNjEekK h3mT/3u62J0wk+jJGxT240dyS3nRmwE= X-MC-Unique: es7J_1xjPreLsZULCXJfrA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 16/38] qapi: establish mypy type-checking baseline Date: Tue, 22 Sep 2020 17:00:39 -0400 Message-Id: <20200922210101.4081073-17-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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=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/22 17:01:35 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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 Tested-by: Eduardo Habkost --- 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 Sun May 19 03:02:44 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=1600808818; cv=none; d=zohomail.com; s=zohoarc; b=G+XlAZWbgB386kJU/NV13dJ4QBM29BaXLF0KfKy0ts4uM1auvoJacSUpEi3brxCFCylXkgeqYL0YHLGdayrMCdSd1sXTAA8SIuqIYQIfyPu4YFcrPqqUUwpIlylEItbSf1QgUcNuSQJTmd1d96y2oOSjab5F2hJ+NYZ/8J0ULrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600808818; 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=r1R0tOQDvuArHpZ0fuNqE5FIkjQNfh4d2fAfWlU8+Ak=; b=A9/LchVIYLIRrIkTU7HEJf+stCm3gKMvnEDtydRz0VFvytD8//iDzvlcG4ENuogaxo13jsOIQ31l5C8keq9AOw4t4N0GXBybaM67rx+cKtz+hFIU36IVET5y+Z3BVwJTY6XcoDUBSK527vmGGYQ5RPpsuua1Wtgl3LEGmUncTyw= 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 1600808818644221.5814156157719; Tue, 22 Sep 2020 14:06:58 -0700 (PDT) Received: from localhost ([::1]:46098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpV3-0007nL-At for importer@patchew.org; Tue, 22 Sep 2020 17:06:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37108) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpPy-00023p-DA for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36719) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPt-0004Zc-RL for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01: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-563-o4Sbi0gfP6iNUuJ1W-gwIw-1; Tue, 22 Sep 2020 17:01:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7BC11801FD7; Tue, 22 Sep 2020 21:01:31 +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 1190455765; Tue, 22 Sep 2020 21:01:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808495; 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=r1R0tOQDvuArHpZ0fuNqE5FIkjQNfh4d2fAfWlU8+Ak=; b=Coq39cAlCEb3nYFsDIDyIbgvBQGjrYUJYSr1AQfwYwWIMOkq6DpOAv/+7eAwJJZEIAueZK 6ovCuo0FNMOU7Xd1loujrbiw4rU4aYQ9Xf0ljFChqnyPyZlgBkFVNsE0k/EmbgOkfwDTmt KLCt1XQnuOtV0xaaCYfJbFpsQuA0VnY= X-MC-Unique: o4Sbi0gfP6iNUuJ1W-gwIw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 17/38] qapi/events.py: add type hint annotations Date: Tue, 22 Sep 2020 17:00:40 -0400 Message-Id: <20200922210101.4081073-18-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 69a0ac5471..00a9513c16 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, @@ -22,17 +24,27 @@ build_params, ifcontext, ) -from .schema import QAPISchemaEnumMember +from .schema import ( + QAPISchema, + QAPISchemaEnumMember, + QAPISchemaFeature, + QAPISchemaObjectType, +) +from .source import QAPISourceInfo from .types import gen_enum, gen_enum_lookup =20 =20 -def build_event_send_proto(name, arg_type, boxed): +def build_event_send_proto(name: str, + arg_type: QAPISchemaObjectType, + boxed: bool) -> str: return 'void qapi_event_send_%(c_name)s(%(param)s)' % { 'c_name': c_name(name.lower()), 'param': build_params(arg_type, boxed)} =20 =20 -def gen_event_send_decl(name, arg_type, boxed): +def gen_event_send_decl(name: str, + arg_type: QAPISchemaObjectType, + boxed: bool) -> str: return mcgen(''' =20 %(proto)s; @@ -41,7 +53,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 { @@ -69,7 +81,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 @@ -145,15 +161,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) @@ -176,7 +192,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" @@ -197,7 +213,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, @@ -208,7 +230,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 Sun May 19 03:02:44 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=1600809205; cv=none; d=zohomail.com; s=zohoarc; b=Z31lnh2ILldf4xpd2OKiWW5XBsCQb21rAX6rdvzBTIH0Q4a0pK24rJvEF6H3K5uC+LNLEHGHz7d3dZDRLu1vhNaulawuz6EG0WS/vboGOtVCXevrEAK/5E6y65ElazqoMvGrvcVK0mgoaw3cxCU0XoLWAwrL3aUEjTWFT8kCqGk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809205; 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=8WtqxaSw1MTImERH4LhuKMMOrFNggPc8qUjTc00nyy0=; b=AGBMsrq74FD4ESKU0Xm7m2Ze0P5AtqCMPSYyCSDlriOHW1JrJRNZNF1w7uDyflVmlUrO+I1kjSm31wjA1xiMmfNGFIPRJ/3rn7kdUqg6al1hgte3jJC0Ft6nCgyg8ZRo9EMTtCV3cT8A3tQ4JtjBSdKwuWXjjjNBXmO+fFUgw3Q= 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 1600809205435720.0762646388744; Tue, 22 Sep 2020 14:13:25 -0700 (PDT) Received: from localhost ([::1]:38916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpbH-0008Qg-R9 for importer@patchew.org; Tue, 22 Sep 2020 17:13:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ0-000272-7T for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53427) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPu-0004Zn-Nt for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:43 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-17-k-i3HLS-NlKSBZtTabBmrg-1; Tue, 22 Sep 2020 17:01:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D6EED83DC20; Tue, 22 Sep 2020 21:01: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 A316955765; Tue, 22 Sep 2020 21:01:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808496; 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=8WtqxaSw1MTImERH4LhuKMMOrFNggPc8qUjTc00nyy0=; b=YjNBMnXyDKT44JAEZ369Dp+OfcIA+I6GnIwNRKjeqyOx9ujyUDRN6ZefgyPohfrSMyvfzt 7ZS/IbreUWsXNEO3Cy1x2FRp5ERrLkErD5fcpiA8wohloiR1RQPz4gReP5a8OcbQJ2lb2A a5QpTU0M8wUd0kR8v9ZrcUAwta6fMY8= X-MC-Unique: k-i3HLS-NlKSBZtTabBmrg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 18/38] qapi/events.py: Move comments into docstrings Date: Tue, 22 Sep 2020 17:00:41 -0400 Message-Id: <20200922210101.4081073-19-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 00a9513c16..e859fd7a52 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -52,8 +52,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 Sun May 19 03:02:44 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=1600809423; cv=none; d=zohomail.com; s=zohoarc; b=PjsOq4eYoeovDVvYbJQYeUkNqs5IkVLG4ASdm1KP0qXOkcIIq3oH4V82BkxQelPKK9vk9E2lf3hLXOabJQgsAS6RAWgMA3fY3h22YYp8vlbHpFLePQZD3cuvGIGs7ECXiGolT56HFKzRpKXwrGvoMUz9LJWEFsfRv9GA/o/eCtE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809423; 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=Dg7npXVAAO6MKtoTq8yKwcSRTMtaXYno4U8oSZj+4jE=; b=iirRf1cysG/ls2aGgDAamamOVI/nB1/jTu3OaEsxOPT/NbibGmdhxkVU5SWiIW+FMWRoj4fdRgB4x1VwAR9CwPfBBwg9xxBIbzfTZGtMuoB5wNlniGmlTL5HdfaL5OVxa2hjaxHJMuBN9ASzcACLn6Q9SCaipZoVPofIsLX/LWI= 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 1600809423846643.5900950543615; Tue, 22 Sep 2020 14:17:03 -0700 (PDT) Received: from localhost ([::1]:50688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpeo-000560-FX for importer@patchew.org; Tue, 22 Sep 2020 17:17:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37196) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ1-0002Aq-It for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56574) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPx-0004a0-Tl for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:45 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-515-pRPWY3eENj2HdXIQDwuwqw-1; Tue, 22 Sep 2020 17:01:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 614BF1074641; Tue, 22 Sep 2020 21:01:34 +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 276625577A; Tue, 22 Sep 2020 21:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808499; 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=Dg7npXVAAO6MKtoTq8yKwcSRTMtaXYno4U8oSZj+4jE=; b=NUM4fLgSZHKEhTYxXhJFLExbRuD+zptcQXDFlLTt8p9Oz2Uo3j70L19fWh2ya6Nyv3OSxc 3UPZGd/6v2Os22oPIr7SIFAHwNQiqBTfmpjEkfb9L7fSVQ5D4+zS60uf5yBJVWJLk9YbnP 8oEuAt8NqlqU+fZYfLmjof1wF/dm5Dg= X-MC-Unique: pRPWY3eENj2HdXIQDwuwqw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 19/38] qapi/commands.py: Don't re-bind to variable of different type Date: Tue, 22 Sep 2020 17:00:42 -0400 Message-Id: <20200922210101.4081073-20-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Mypy isn't a fan of rebinding a variable with a new data type. It's easy enough to avoid. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 9b3f24b8ed..389dd879a6 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -198,14 +198,12 @@ def gen_register_command(name, success_response, allo= w_oob, allow_preconfig): if not options: options =3D ['QCO_NO_OPTIONS'] =20 - options =3D " | ".join(options) - ret =3D mcgen(''' qmp_register_command(cmds, "%(name)s", qmp_marshal_%(c_name)s, %(opts)s); ''', name=3Dname, c_name=3Dc_name(name), - opts=3Doptions) + opts=3D" | ".join(options)) return ret =20 =20 --=20 2.26.2 From nobody Sun May 19 03:02:45 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=1600809691; cv=none; d=zohomail.com; s=zohoarc; b=Q10zwr6dG3LnutuQxAKOPSWs4CWoigMrVEFu0sfl2O57zVZoRe7TOwd/BkIW7QzpmHin2UFC3UmLdBRdtPb1+YEtPcYIq5A1pfNmhb+uKaoDeeeu2viq9HkjRne/kCrMXvyXjVVcZfP90PWnYbTkSV7GAhNPM402kRQkVbWdrdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809691; 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=2giffaOrqGEsDrWJW1W81X4oET/EhvdY0U7WXfADDV4=; b=Vk3MICcBLmAbYG8Io4fHwIY6cL3tP9d3SGS3O/KJq8un2KSIESy83zCKPB+jc4TicpF6t9s/P8fQqhhst48+73PyzFVxFCwZGydXR8pNwkVCk46E8d8N/19prThmVtTgnFtLQ/ccXN4sP0SaP4CrVLJL1L6sqztiUlmuLj96DIw= 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 1600809691417498.7563338264564; Tue, 22 Sep 2020 14:21:31 -0700 (PDT) Received: from localhost ([::1]:35984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpj8-0002X9-3C for importer@patchew.org; Tue, 22 Sep 2020 17:21:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ5-0002JG-ER for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:49 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:51889 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 1kKpPx-0004aB-W4 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-455-XYLPXVwpMWW8qd0UE6_LLg-1; Tue, 22 Sep 2020 17:01:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 790AE188C122; Tue, 22 Sep 2020 21:01:35 +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 883FA55765; Tue, 22 Sep 2020 21:01:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808500; 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=2giffaOrqGEsDrWJW1W81X4oET/EhvdY0U7WXfADDV4=; b=RlOd+vN71lJcWP8Rfmjowk+1cJH8T8LbCSXglkfzU4aAaVybXQhJ2rHgX2LRyY6iXmqtw+ 4P6tH8WqW7fxCdvPXOvnuzZWoqgRT2JjdEBZ74T0X7MaKH7r7ETorOtgKOs96twO93bb2H wubRuL8zp5q4/3dANvBUKUOBlTl96wQ= X-MC-Unique: XYLPXVwpMWW8qd0UE6_LLg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 20/38] qapi/commands.py: add notational type hints Date: Tue, 22 Sep 2020 17:00:43 -0400 Message-Id: <20200922210101.4081073-21-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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=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/22 17:01:22 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- scripts/qapi/commands.py | 66 +++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/scripts/qapi/commands.py b/scripts/qapi/commands.py index 389dd879a6..80f22d562d 100644 --- a/scripts/qapi/commands.py +++ b/scripts/qapi/commands.py @@ -13,19 +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, build_params, ifcontext, ) +from .schema import ( + QAPISchema, + QAPISchemaFeature, + QAPISchemaObjectType, + QAPISchemaType, +) +from .source import QAPISourceInfo =20 =20 -def gen_command_decl(name, arg_type, boxed, ret_type): +def gen_command_decl(name: str, + arg_type: Optional[QAPISchemaObjectType], + boxed: bool, + ret_type: Optional[QAPISchemaType]) -> str: return mcgen(''' %(c_type)s qmp_%(c_name)s(%(params)s); ''', @@ -34,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 '' @@ -70,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, @@ -91,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(''' @@ -185,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: @@ -207,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) @@ -224,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) @@ -256,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" @@ -272,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 @@ -295,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 Sun May 19 03:02:45 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=1600809899; cv=none; d=zohomail.com; s=zohoarc; b=bMny9kJvZsqNddhiltpbF/UX1ERF3uzlbld1r6jfjRKjqfZ85v4rYNt0g2y9/vXtbNytq1NoPTzUWtRFNM4/idQ9ZxkBZL1feua3T+FYbYKjFzKfi/37DCYivZJl3zvLiMt6u7XAonqFfELnryfRQWdqFQdU3kue1ISA2GbA/zE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809899; 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=m3nh4Q5N/KG4bEnjfdMo7Ye11avzSJdOnU9OcjzmHi7cRQstFLAS62oDjeUgqVTb9F2U9o0BZJr59oZIcAqWEECKHI3bhyRXfUDKf67JhRrTFDwqLt2PYvg67qYkG29FqUFruEAwyMCH+pAiyK9dh3AJZ6MTCiz4e9FR5irZUUU= 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 1600809899133813.25410751043; Tue, 22 Sep 2020 14:24:59 -0700 (PDT) Received: from localhost ([::1]:46980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpmT-0007Ix-KK for importer@patchew.org; Tue, 22 Sep 2020 17:24:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ3-0002F6-Eu for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:47 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:46347 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 1kKpPy-0004aM-Ju for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-320-CHxQ18zaO3WitwPWq8XQSg-1; Tue, 22 Sep 2020 17:01:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8E90A8014D9; Tue, 22 Sep 2020 21:01:36 +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 A41A055765; Tue, 22 Sep 2020 21:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808501; 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=KSdOhJtfvE/AsmhnRdwDdtoG811zXDDaqP8TBYlqCuzgb45y6d/OaSENvR0LCaDqBD+o6+ C4f2JqE5SEVG1uugZogLzgHvLVLxMkv3/MhgcGQHBK5x7ij7vklh0iw7dS5Q+RFpPfP4RN oP/WPsQ6q2L0f0rb+Oo0pzrLhDYmdfM= X-MC-Unique: CHxQ18zaO3WitwPWq8XQSg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 21/38] qapi/commands.py: enable checking with mypy Date: Tue, 22 Sep 2020 17:00:44 -0400 Message-Id: <20200922210101.4081073-22-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 13:33:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 Sun May 19 03:02:45 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=1600809521; cv=none; d=zohomail.com; s=zohoarc; b=Q3ZbMGDlG1JeAzYC43GR/V4JJUu0YUF03ISGBTwUry7jEed/KiFkuDzahjw3R5WEGD8ogWtevJNQWzh1di0RiJ4wykuSkTJ5f9DFsqwlGV4jm0jxdIzf0SoBAgoOdkMzn2V+GJLcapY6ndZbOy/tAu9KHMyya7uGsSux1pkC22o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809521; 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=8a9MVlWgBGw5Ju9tvv1Bh6clLXokzrVfUNMVBIYUfO8=; b=O6TaQHu3S8NBD5d5Wwev3CRUd14PeS8uA8QViQ5o/fxHThlrvdHsnUL2DDLUGT6huwvv86Ss54jOcnwIqTphawUs7ehd+ejKRDwKj//v2HVWS8qg0vECYsnvXKD/9vF2A4FS5vLxgXBj9hF4mE6HI6dNQcH3b92gPEFlSQ9Kcyk= 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 1600809521374428.7057406861394; Tue, 22 Sep 2020 14:18:41 -0700 (PDT) Received: from localhost ([::1]:55630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpgO-0007Cp-15 for importer@patchew.org; Tue, 22 Sep 2020 17:18:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ4-0002GQ-2w for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28600) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPy-0004aT-Tm for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-221-NKaRi7f9MUK1IJCy_niRNg-1; Tue, 22 Sep 2020 17:01:39 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2C4180046B; Tue, 22 Sep 2020 21:01:37 +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 B7A1655767; Tue, 22 Sep 2020 21:01:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808502; 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=8a9MVlWgBGw5Ju9tvv1Bh6clLXokzrVfUNMVBIYUfO8=; b=dlkhOwSw5tj/GFJ3c6R+Hr2Utk83J+NWSC2aHY0ctCX+1motIQZK1Oh/Lu7PhXcza5sfjv DO1guNYp1loMChdGDvVuNfC7Q/c45QYPlHwtI6GIpF4sJk14HfHxPKebxoMMcCIFmUphgF lJdU7WyLLj/kdTaJYf5A6Z/q8yQAAi0= X-MC-Unique: NKaRi7f9MUK1IJCy_niRNg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 22/38] qapi/source.py: add type hint annotations Date: Tue, 22 Sep 2020 17:00:45 -0400 Message-Id: <20200922210101.4081073-23-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost --- 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 Sun May 19 03:02:45 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=1600809751; cv=none; d=zohomail.com; s=zohoarc; b=L9a6zquShwPKpJJzgdLXm+2y8MBzAto5tMJphN2mPZtkiEIV6Xukf26Yc5N+OUpFFoKvND/vLuYoWrxAhAFwVwBUs5J6Gi5ExqUC/zyj/TPTGjzglz+8x3MSbnDOA/Ne5bm6FZRwjJ5K5z26NC1HCGC0SWveVixQdNGT4jYJ0hQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809751; 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=TfE4iGbq7w22nk05xoMfyoK+hdx/KMvqzG8qGMUIQHw=; b=JNq/S44/XzyE+uY0VaB1jVnMkxxM2al2p+ubvadZ4xxtXpZIlH8EHIAGeTBJ4w7pkZBaxmqIfJyQLuXE3+l2+uYlFl6qvYEU9XFQYx/Pe8+iKJh6AlZFR2D2AE+OE1nve2uxdQ6eDwdt5qKuxjNF007yaW6OoxnMw23Y6YjpQHo= 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 1600809751602132.92279574754627; Tue, 22 Sep 2020 14:22:31 -0700 (PDT) Received: from localhost ([::1]:38682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpk6-0003hN-3P for importer@patchew.org; Tue, 22 Sep 2020 17:22:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ3-0002Eg-8M for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43269) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpPy-0004aK-C5 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:46 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-244-FgJAURNDO5qVmJnzFdI5Bg-1; Tue, 22 Sep 2020 17:01:39 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B286D1005E6D; Tue, 22 Sep 2020 21:01:38 +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 CA95755767; Tue, 22 Sep 2020 21:01:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808501; 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=TfE4iGbq7w22nk05xoMfyoK+hdx/KMvqzG8qGMUIQHw=; b=fHwPXFQxaLGcAoI6OB7c6F5FcXz6o9YX0fLT7pzAcLYHX71xRRJIEFLaZ6jLmu76j3uwaq pC8ES1RcQh8RNPSdEBaZ96mt9swUSrx2JCgQAkZBbz8093ivF8PMocOKzud4hRiChNYyoA rR7n/hE46+gdZNAzvCKhywdDLtHHVM0= X-MC-Unique: FgJAURNDO5qVmJnzFdI5Bg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 23/38] qapi/source.py: delint with pylint Date: Tue, 22 Sep 2020 17:00:46 -0400 Message-Id: <20200922210101.4081073-24-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Shush an error and leave a hint for future cleanups when we're allowed to use Python 3.7+. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost Tested-by: Cleber Rosa --- 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 6151427a51..7438806096 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 Sun May 19 03:02:45 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=1600808981; cv=none; d=zohomail.com; s=zohoarc; b=mimd2LlwJcU4D7Cd8xv5TtJPiJni9l95XdvbBvJ5VzXVoLm1kRZ3KuE/ouOsGqRj7KFTZrjCcbicQMMg0KknR5IL5h5K+ORycG7kNnC7xSr8DSJmFRGoFl7D6sHbS54oiiOPQWePxoa7WMNHcn76fCZrHEu4n+CR9mtF7msk4sE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600808981; 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=39EY1IEoTn95VCB+o4INBS9zDz+TfqD7urT+HBs5QsM=; b=emhtS375pmIH9GiSvAcUWQSALQvl2w/T9zrNpIGz03/w6AtHPooqPEDmrKR4zCkP/hLA1l/8475DGhOrgBW4fcmLBEz3f3EZ6LDjZkA68mZAleQ5RvcecIAfBmG0jdswPQMd8JNRZUt6Xsje3U/S7xOPcdFWIrguz2ieaqhN6pQ= 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 1600808981512821.6695117376416; Tue, 22 Sep 2020 14:09:41 -0700 (PDT) Received: from localhost ([::1]:54236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpXg-0002qq-8L for importer@patchew.org; Tue, 22 Sep 2020 17:09:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ5-0002Jt-Mr for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58351) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ1-0004bq-MD for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-rvklwwpDMeCIczfvixMwvw-1; Tue, 22 Sep 2020 17:01:40 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C78D81005E5E; Tue, 22 Sep 2020 21:01:39 +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 D981A5577B; Tue, 22 Sep 2020 21:01:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808504; 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=39EY1IEoTn95VCB+o4INBS9zDz+TfqD7urT+HBs5QsM=; b=Yj72GTm0H+rypmsYUd++QHBNhq/lRr2K+9TiCSXJu1zJ5KjcwWHO9XswTmcUUWMMPXI+99 J9aw7yExm9H7RxGv7RovAsocq5FfbU1CphtkjBwhWwXcG5k/ePpF9JyQbnHi5OluD3qoKS VQvXOn9rN2PR9QkPxLZks/iSExrJUHw= X-MC-Unique: rvklwwpDMeCIczfvixMwvw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 24/38] qapi/gen.py: Fix edge-case of _is_user_module Date: Tue, 22 Sep 2020 17:00:47 -0400 Message-Id: <20200922210101.4081073-25-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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 Reviewed-by: Cleber Rosa --- 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 9898d513ae..cb2b2655c3 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -251,7 +251,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 Sun May 19 03:02:45 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=1600809937; cv=none; d=zohomail.com; s=zohoarc; b=mfiktrht8DKnSoR225nC//7henvDAQJBdoPNe2PNVP25/qKTDZnnaAvEzRpaI3Ul96uUrqus5yHBYxoCmC/C0Zs8w8h2zA2aPEtgFHmWhplari1ZBsvGrRbehF8kL4idGmGCslAvrGlwouLoP+l08mx5fEoYWGzoAkCj+9VOcf4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809937; 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=GFFSP+kUdBqOW5dqjOhn98eEC7+OQ9zgS6bKILSSiMM=; b=HBJHFClVHtWIki3PyG3uowgk8r1Tz2i9kLYceKlDQ+3uXosxCz9gSmwl2tC312P6KdagR+t79JCAgIrZ2OUIrO8Mn6UPv+EZIIyRG/jr3yVrMMC4eoCu+3zZMPADfTP6fpXjIFetfH59MPnpOH68tvaE27HDGes0Nr7GABDSqmI= 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 1600809937860929.182870802384; Tue, 22 Sep 2020 14:25:37 -0700 (PDT) Received: from localhost ([::1]:47974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpn6-0007mf-Fh for importer@patchew.org; Tue, 22 Sep 2020 17:25:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ6-0002MM-SZ for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27861) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ1-0004b2-C0 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:50 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-38-fhl-2QvfPEyqNx3oOoRJ4A-1; Tue, 22 Sep 2020 17:01:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D3D4D8014D9; Tue, 22 Sep 2020 21:01:40 +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 F02E055767; Tue, 22 Sep 2020 21:01:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808504; 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=GFFSP+kUdBqOW5dqjOhn98eEC7+OQ9zgS6bKILSSiMM=; b=VAONFY0q/cWvspACcE45aQgRJEq5oAWi4QiYwv6uK23Ux1gt7CDcqwYBV7KIBC7YXqLAIc Oct3kSiYDhmHePHvlfBlybeHvUFOBiiBQ5BdP2js08+Ls6ILIpiOIpRICUWIeX+6nwiBkq g9mh/ca+xgODrU0BiPfxeYLwiwfpCm0= X-MC-Unique: fhl-2QvfPEyqNx3oOoRJ4A-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 25/38] qapi/gen.py: add type hint annotations Date: Tue, 22 Sep 2020 17:00:48 -0400 Message-Id: <20200922210101.4081073-26-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- scripts/qapi/gen.py | 102 +++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 49 deletions(-) diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index cb2b2655c3..df8cf8271c 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -17,7 +17,7 @@ import errno import os import re -from typing import Optional +from typing import Dict, Generator, List, Optional, Tuple =20 from .common import ( c_fname, @@ -32,31 +32,31 @@ QAPISchemaObjectType, QAPISchemaVisitor, ) +from .source import QAPISourceInfo =20 =20 class QAPIGen: - - def __init__(self, fname): + def __init__(self, fname: Optional[str]): self.fname =3D fname self._preamble =3D '' self._body =3D '' =20 - def preamble_add(self, text): + def preamble_add(self, text: str) -> None: self._preamble +=3D text =20 - def add(self, text): + def add(self, text: str) -> None: self._body +=3D text =20 - def get_content(self): + def get_content(self) -> str: return self._top() + self._preamble + self._body + self._bottom() =20 - def _top(self): + def _top(self) -> str: return '' =20 - def _bottom(self): + def _bottom(self) -> str: return '' =20 - def write(self, output_dir): + def write(self, output_dir: str) -> None: # Include paths starting with ../ are used to reuse modules of the= main # schema in specialised schemas. Don't overwrite the files that are # already generated for the main schema. @@ -81,7 +81,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 @@ -121,40 +121,38 @@ def build_params(arg_type: Optional[QAPISchemaObjectT= ype], =20 =20 class QAPIGenCCode(QAPIGen): - - def __init__(self, fname): + def __init__(self, fname: Optional[str]): super().__init__(fname) - self._start_if =3D None + self._start_if: Optional[Tuple[List[str], str, str]] =3D None =20 - def start_if(self, ifcond): + def start_if(self, ifcond: List[str]) -> None: assert self._start_if is None self._start_if =3D (ifcond, self._body, self._preamble) =20 - def end_if(self): + def end_if(self) -> None: assert self._start_if self._wrap_ifcond() self._start_if =3D None =20 - def _wrap_ifcond(self): + def _wrap_ifcond(self) -> None: self._body =3D _wrap_ifcond(self._start_if[0], self._start_if[1], self._body) self._preamble =3D _wrap_ifcond(self._start_if[0], self._start_if[2], self._preamble) =20 - def get_content(self): + def get_content(self) -> str: assert self._start_if is None return super().get_content() =20 =20 class QAPIGenC(QAPIGenCCode): - - def __init__(self, fname, blurb, pydoc): + def __init__(self, fname: str, blurb: str, pydoc: str): super().__init__(fname) self._blurb =3D blurb self._copyright =3D '\n * '.join(re.findall(r'^Copyright .*', pydo= c, re.MULTILINE)) =20 - def _top(self): + def _top(self) -> str: return mcgen(''' /* AUTOMATICALLY GENERATED, DO NOT MODIFY */ =20 @@ -170,7 +168,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 */ @@ -180,16 +178,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 @@ -215,15 +213,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', @@ -231,38 +231,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) @@ -274,27 +278,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 @@ -302,13 +306,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) @@ -322,7 +326,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 Sun May 19 03:02:45 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=1600809839; cv=none; d=zohomail.com; s=zohoarc; b=FeBXmxmpj+ToKoH2z8AqXwrsCCRGk3qdJ2fMcflhRH2FUOASmWEb0U3SQX/dww0dWAo1zz8scp0TGFk03kG0JC6Ge59Lygolv7F+ZAyPl3cl0TY/F5voNj++oX52cJEfplQ5pOetofeSihRnQqUgqYG3nOJOzdMMJydSa/rxmeM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809839; 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=lVKktALRsXg2FsZQ1DypmPB1L7UorTW3MyLggMgadBCvIFiKiMrEQyfJtoF8x4v4gVSf1cMAvLIUeIAKF6JGYBzCPm2OFGbgob1hTIU25+MMb6mdJuQfZmdHGTp/B729NiBTgIAnDFmFS6G4vBx4dxUxufNFJRC7XhE7Q9eKw5E= 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 1600809839602481.6794709021216; Tue, 22 Sep 2020 14:23:59 -0700 (PDT) Received: from localhost ([::1]:44420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKplW-0006DT-3E for importer@patchew.org; Tue, 22 Sep 2020 17:23:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ5-0002KC-Rx for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23037) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ1-0004cN-Vs for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-86--3UkK60zPHSNIolMD-kqXA-1; Tue, 22 Sep 2020 17:01:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E6DB3420EB; Tue, 22 Sep 2020 21:01:41 +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 0685E55767; Tue, 22 Sep 2020 21:01:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808505; 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=Q3n3qrRNwWDZjSSfk3hdSmApWb0hhau4KzzG5c/HH5J5xB+RY/CqqOPstOhrlfbjVQQAdj 25tqkJApBm1yvh4t+IjbI+wonoJAJ5rdVqCO40gH66hxL13gkJVseXoucSBpIKTdTbPfAn eJ1ehaoDB/AIXf5I55BwlVae0nhgINA= X-MC-Unique: -3UkK60zPHSNIolMD-kqXA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 26/38] qapi/gen.py: Enable checking with mypy Date: Tue, 22 Sep 2020 17:00:49 -0400 Message-Id: <20200922210101.4081073-27-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost Tested-by: Cleber Rosa --- 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 Sun May 19 03:02:45 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=1600809098; cv=none; d=zohomail.com; s=zohoarc; b=h+6Na+C532bwTv8RDGy4S0l4Cv7y1Gvpx2r9QcPAvt2fmr7sPL9GKzOMGsInqjdQQr/6s0l6mkYHd5n+zk5MODEMwFpy6vajG+p11ddVU+RQmLU5m49RHx7UnG/vgM1/NfgXcpjddIRJrginq3lxszSJGpXfYCW+J9OfMFLZlvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809098; 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=oPlkWiLUlN6cVGzoFo/5U4ARiTDU1/VuQaG05GnR3aE=; b=WI+2hXIeeXHo2/481cMN8n0I6eVD5hmjPvo3KuOYE6gGQ8hvFLOSY6l5VrmDUTKQt6nvDj8xhWYDA526Z2Zhdo8lw6gx/MKFywbr9hl0ujiNKjbc9U/zMp+7n9kRYrfBvM2FA2JCjtJzLceXPu4xDQxefT0F1SMF7eHv32TUceo= 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 1600809098638160.31918792476654; Tue, 22 Sep 2020 14:11:38 -0700 (PDT) Received: from localhost ([::1]:34240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpZZ-0006Px-9A for importer@patchew.org; Tue, 22 Sep 2020 17:11:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37348) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ9-0002SF-Px for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ5-0004dH-0O for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:53 -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-YJ5VCyc1OYywftO57e4WLQ-1; Tue, 22 Sep 2020 17:01:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 012011005E5E; Tue, 22 Sep 2020 21:01:43 +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 1B36D55767; Tue, 22 Sep 2020 21:01:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808508; 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=oPlkWiLUlN6cVGzoFo/5U4ARiTDU1/VuQaG05GnR3aE=; b=BM+3a6oJAkI8oezvjJcs7Ni/foTskgoG6XJQo9sU6sMj7T0x2yUDsh27Qi7DxJTaCQPrz/ eI+Foun1zpE50nrPVfyAQkEygcuhm+8E5yiR6dYIz+/qMpuE6/N1o8HmhN4AoTEXpij/GX 4HXWC6sFLMKtZ/y5G91MxKH1u/yhEGQ= X-MC-Unique: YJ5VCyc1OYywftO57e4WLQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 27/38] qapi/gen.py: Remove unused parameter Date: Tue, 22 Sep 2020 17:00:50 -0400 Message-Id: <20200922210101.4081073-28-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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 Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 df8cf8271c..ba32f776e6 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -261,7 +261,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 '' @@ -279,7 +279,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 Sun May 19 03:02:45 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=1600810294; cv=none; d=zohomail.com; s=zohoarc; b=dCvL1Apcbv1erNpWRpoE3KpoMbAej/8dJY0lBr5VWIOiSpjSuNOe3wNN+jmyeKhMi2PElEU9KfQ1cTZURCvEFPx/0eTjaqIOyvBhSBo9zIvRp1usVwJNvgKZgFnbxa0R16kCF9uA2XeSGQ1XeK05yrYgERHS1oD53/5FW19lQ2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810294; 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=+Ibo9+RLfwsro0GaTeo9uSseS1EBK0++KO7WNXemOpA=; b=bug2p3Bs2HiyCAO/U2sJqwUvBCHfY+vrMojuZJ4RSsdBJl7w5AIForbP1Jw4dhng9Z3yug2nNIEZ4pZxGMtbob9HHYhmBTD0PMRcN+R0oMxFpbArxMpi11xF3RIais7vNNkpehMo6Vc5iLhCL4/4IY7jmgzw4OhkRpBkUEsbEBI= 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 1600810294571315.7841202893346; Tue, 22 Sep 2020 14:31:34 -0700 (PDT) Received: from localhost ([::1]:35394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpsq-0006o1-PR for importer@patchew.org; Tue, 22 Sep 2020 17:31:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ8-0002PL-2V for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ5-0004dM-8P for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01: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-31-peFxE_XVNluv_1B20Vlghg-1; Tue, 22 Sep 2020 17:01:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 153088014D9; Tue, 22 Sep 2020 21:01:44 +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 292C55577B; Tue, 22 Sep 2020 21:01:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808508; 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=+Ibo9+RLfwsro0GaTeo9uSseS1EBK0++KO7WNXemOpA=; b=Belm4uJs7eiiAjtd44aPf5dpS3xfvoFBr7CdNId7stubr/rZPEKPE95OIMSmsEUeZeFybb p4uEolId4Agzg8EKHoRXpsXAgYo1PPI0veZWoksSHoBO+0Utmddfdat2ES+KG+emahOfZQ TQ4151yZexw+IMt7CXz7ktvXUY9Mvuc= X-MC-Unique: peFxE_XVNluv_1B20Vlghg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 28/38] qapi/gen.py: update write() to be more idiomatic Date: Tue, 22 Sep 2020 17:00:51 -0400 Message-Id: <20200922210101.4081073-29-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Make the file handling here just a tiny bit more idiomatic. (I realize this is heavily subjective.) Use exist_ok=3DTrue for os.makedirs and remove the exception, use fdopen() to wrap the file descriptor in a File-like object, and use a context manager for managing the file pointer. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 ba32f776e6..cf340e66d4 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -14,7 +14,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 @@ -64,21 +63,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 Sun May 19 03:02:45 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=1600810118; cv=none; d=zohomail.com; s=zohoarc; b=T+DjVQBQoQhEwt840EDbm1lJvK6t1arsWVK6TfSUvEyz5Ou4LBafvy7KdeqPb32LsHylWSzoaN2mTYXlhfro6PTKA2yUE1/1Lpl1hIbrg9BVb1XJflXU0x/N4yoiNSE4I7z0lfqzUW//A2ZNId9PlJpK8sC4GymKm5gHo1BesGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810118; 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=p+VT7uJZOGfrmWudoqPbqJmNENOSpifBVctO6t6feII=; b=HUHWSMjV2LK7knJOZZiEGaLbSmd0knZ6XZXBjcyf6HnG8jBrQuOuZjKsXx8fJlx536HxZUXUkQR0X+ZTg06SxMjn3Et01BYhRCQBx+AVcvCobKM/SWeRn5yLhLWfWaHJD7t/4VOC58WDnnW9sg8kT+eEkK3Ogtbvm8ENMx4/iNI= 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 160081011808489.48483124482459; Tue, 22 Sep 2020 14:28:38 -0700 (PDT) Received: from localhost ([::1]:55950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKppy-00032K-Oa for importer@patchew.org; Tue, 22 Sep 2020 17:28:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37336) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ9-0002Rb-7L for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:26139) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQ7-0004dn-66 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:52 -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-292-baOfa6ckPQmceDJdAf7QQg-1; Tue, 22 Sep 2020 17:01:46 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 25F8B85C706; Tue, 22 Sep 2020 21:01: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 3CD7E55767; Tue, 22 Sep 2020 21:01:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808510; 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=p+VT7uJZOGfrmWudoqPbqJmNENOSpifBVctO6t6feII=; b=EvOn/CNgwSbaMXESHC3Zl9UdsDeWtoV3ZFHOR0pO2PSehzeXeLiA2F8IIkVVu6dHYRwZNH Hbd4Yh+j3kioXZJskrn5+994MlsOX/ziz6Tl3dcRmJwIeSUsH6N/mCEscET10W1KE2fbM0 8V0yogmJLzmpQYWtkSae+3rx2j9ToQE= X-MC-Unique: baOfa6ckPQmceDJdAf7QQg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 29/38] qapi/gen.py: delint with pylint Date: Tue, 22 Sep 2020 17:00:52 -0400 Message-Id: <20200922210101.4081073-30-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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 Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 cf340e66d4..ed498397ad 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -50,9 +50,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 7438806096..de132d03cf 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 Sun May 19 03:02:45 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=1600810475; cv=none; d=zohomail.com; s=zohoarc; b=I0SSgm/lXnNrVZVg3Ha/+AZgHrYXIP3a9X8tBJxCx/ID5mBT0/ao3VBFB42W7oxCwcAq28Xm8+lEIiW1dQrKjCGWLcgdw8980kEtoKkgb6zelvuoLsqlwGxYRolkIk7Zk6FfByQzeK3rLdKVHMP6borvJGRylXmVZdvtFC6paak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810475; 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=HoJRDCT4K3kHAdk1/rbsak3r/cp+GyjB6IG1mtGQxBA21rWe0lbeQqihI7ZJY+s9yy2r6zgI75Czy3X3vXdS2bYPvCTksUMfWD4uljKfT1xOQeYIHIIRAEXcdgznwZH+DbczPLbnyG7NNeok3iXiOgkNreW71DOqIXLMZaze23s= 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 1600810475217122.08997331261185; Tue, 22 Sep 2020 14:34:35 -0700 (PDT) Received: from localhost ([::1]:43626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpvl-000290-Jp for importer@patchew.org; Tue, 22 Sep 2020 17:34:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQE-0002WC-HC for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21752) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQB-0004eK-3j for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:01:58 -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-463-0cQZgwQWPmmCy0RCxfOLag-1; Tue, 22 Sep 2020 17:01:50 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0ACD6107465F; Tue, 22 Sep 2020 21:01:49 +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 5611E71775; Tue, 22 Sep 2020 21:01:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808514; 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=WXQSGRcEEyOhdiHCzhO8JikHB1QrW5nVmTPuXgMzSLkXBTUHSIvpa9S6m0pQzm0hfauF3Q g6yzHC2Bu6NU1cWFEVH5/C8nuW4ATuf7ttqsb34ZKNzI+6e42OHWfc9vvFdE2o1w+wF4a0 4cM9PHm2X4GttWd/9Qz6txR2lMXjq3Q= X-MC-Unique: 0cQZgwQWPmmCy0RCxfOLag-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 30/38] qapi/introspect.py: Add a typed 'extra' structure Date: Tue, 22 Sep 2020 17:00:53 -0400 Message-Id: <20200922210101.4081073-31-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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 Reviewed-by: Eduardo Habkost --- 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 Sun May 19 03:02:45 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=1600810629; cv=none; d=zohomail.com; s=zohoarc; b=faHQXNboZktK3mb0qcbjRrUY1FkHZk68P0DiOyXgGrz7LNMJJMMkBS4uLLNJC5YjTp1D3wll3++kp2QpvOWq2K3hViug/6ZNiOb/hkzp0lPOfXITGyvpyOCakgR31vWG3BfysmKXdMpq4YVz1wPaI5UCHb6GiPCT8o9dkl1XjV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810629; 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=eHyKzejCQs4XmMTHkEpgKrVOPavkNzazn57t4Uhl2/NygJ6BMR7gJ9iwMwkZQ8B12apuum16PSl5HaxmFoWygU24AfkPqQnVn0syIr4g0n1eJGgDpgMulUT3fz+8H08Q+MTkTDScXPDGvlVXiW+0/UdC+Q0JkhptvN33jlu0Pu0= 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 1600810629574872.8941856110864; Tue, 22 Sep 2020 14:37:09 -0700 (PDT) Received: from localhost ([::1]:52110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpyG-0005za-7B for importer@patchew.org; Tue, 22 Sep 2020 17:37:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37500) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQY-0002nN-Ju for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22015) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQW-0004fq-HB for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:18 -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-470-1YbrltPrOSalI_V1etwKmQ-1; Tue, 22 Sep 2020 17:01:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 20FC71868422; Tue, 22 Sep 2020 21:01: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 3273755765; Tue, 22 Sep 2020 21:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808535; 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=LMbEfQkhVLUMdGttvXz1ujN/aADmqeaJQDiT1ftzsK26Jx85uZWTDz30u4WkiVAcJpJxAW CQKQKOzvR4F8kStQhhm58/SomyyJ+edaVh1WM/TfBsz9q5lzcgVQtaZ284MI/HZu5/bb3Y +tmdcldr7/SERlVazENE2Ys/jrubtwY= X-MC-Unique: 1YbrltPrOSalI_V1etwKmQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 31/38] qapi/introspect.py: add _gen_features helper Date: Tue, 22 Sep 2020 17:00:54 -0400 Message-Id: <20200922210101.4081073-32-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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 Reviewed-by: Eduardo Habkost --- 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 Sun May 19 03:02:45 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=1600810793; cv=none; d=zohomail.com; s=zohoarc; b=n1/gaZ2MX7v4kdCrQUewgm2KkNmZJ/5FR1WauGFt/tsYwjD3w5hiNWl3r1zzBgbHgEpWiLZ6sUyQfg6gxkhKwAKn5i6wkfVDYy7QE+iQcM1yBIFiMi2KCof0Xl7Y3qpdMHLi/vf5Dq2wiQBtzvW4tHUv04vln9G4eKtOB6DUboM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810793; 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=oLr3sdzgYiIZ8PdZ/uqX2aSZREOo52B3lO5hI4j9CYeKLs6rkOmwieBeYBMMK7BPFr5O57mTyb04rhRDLgK7rMH+kVn38TtyYZRl9DSCGvifXzMwjod20OMm47jLr4NAVa9r+/j/f0f/kNzWTbsrkKDz41dXLbDV0B+DUdK2lnc= 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 1600810793106184.52900555904705; Tue, 22 Sep 2020 14:39:53 -0700 (PDT) Received: from localhost ([::1]:60240 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKq0t-0001Lk-K2 for importer@patchew.org; Tue, 22 Sep 2020 17:39:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQc-0002ty-F5 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQZ-0004gP-6B for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02: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-328-SygbvdQYNiSzHA4SjBiuEA-1; Tue, 22 Sep 2020 17:01:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 39A1D186841A; Tue, 22 Sep 2020 21:01: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 49E6955767; Tue, 22 Sep 2020 21:01:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808538; 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=OiZUm0C6qxKEb4WOoXTIBcJ3Hj9oviRk2QPQCOEgMMZwCGy3xaq6NiARLSItNGRfJGxtGF pj0BPJrWv1gVijip5SJqiMgAINIuMmYFgnAqPyh22ypqkIHVzA+hqjb+CzvM+3tTI1DpaI SARJSAsyXB8bn9VPjT50YuT/o/fK5Jc= X-MC-Unique: SygbvdQYNiSzHA4SjBiuEA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 32/38] qapi/introspect.py: create a typed 'Node' data structure Date: Tue, 22 Sep 2020 17:00:55 -0400 Message-Id: <20200922210101.4081073-33-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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 Sun May 19 03:02:45 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=1600810637; cv=none; d=zohomail.com; s=zohoarc; b=XEjhUlA4bJK/J4D8BJM3YvTlT6w+7HnI+Vlk9MEcXo8/KC+VGhL7+7HUTphJ8BT0k7bPUl7EVMjjFQ5XJF3BeRIEB5w78mmPOqR2tanjrWqZEMkLNbst/BZ9xaxAU3o3IOIlclDR77FtaAtBLhR8rCUBKkTJxaHyp2XZp/Z5Nak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810637; 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=JPrStWWZbcECY3Td1vYTtBWaUYqjwCSycYgpvCspoLg=; b=n7TGH8z4E+qa38szBn3fnbCMfLz6eI5+kSW0Nu15Mj5sYW6mau25SaV6Wah9jnEcp2NhXHKpsixgSKaO4h+yOyF/X2KIYIF5OJ8r9iY1vnkN44iWX3ElhLgvx8ATWya2718hzqfHRRvC5IXzObNtwkudfcYh0J9dpG/0dJWVsXQ= 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 1600810637572180.37494724194983; Tue, 22 Sep 2020 14:37:17 -0700 (PDT) Received: from localhost ([::1]:52778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpyO-0006Hg-2n for importer@patchew.org; Tue, 22 Sep 2020 17:37:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQb-0002sf-PD for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52724) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQZ-0004gF-3f for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:21 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-402-fp8epnaVOe2sRnZs_X8wEA-1; Tue, 22 Sep 2020 17:01:53 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 51BB7873081; Tue, 22 Sep 2020 21:01:52 +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 61A5255765; Tue, 22 Sep 2020 21:01:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808538; 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=JPrStWWZbcECY3Td1vYTtBWaUYqjwCSycYgpvCspoLg=; b=MZk5HchVk5Cb2kL0tZVU0+9tzVB9LtooavyaFBEHC3Tucs3fIawO7ZNdznpIwnyyRKlVF0 mFhnAoztOvKk1BT8wvDn4M++W1wBSPumzNahOJ44mNYHQRveMjKSTMD7b1NTo7Ct3rO18I 59nY2LVFiN9GtgA5hISfwEx2oTCx0OY= X-MC-Unique: fp8epnaVOe2sRnZs_X8wEA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 33/38] qapi/introspect.py: add type hint annotations Date: Tue, 22 Sep 2020 17:00:56 -0400 Message-Id: <20200922210101.4081073-34-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow --- scripts/qapi/introspect.py | 135 ++++++++++++++++++++++++++----------- scripts/qapi/mypy.ini | 5 -- scripts/qapi/schema.py | 2 +- 3 files changed, 96 insertions(+), 46 deletions(-) diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index e0f5007ab7..7c0444170d 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -10,7 +10,15 @@ See the COPYING file in the top-level directory. """ =20 -from typing import (NamedTuple, List, Optional, Sequence) +from typing import ( + Dict, + Generic, + List, + NamedTuple, + Optional, + Sequence, + TypeVar, +) =20 from .common import ( c_name, @@ -19,8 +27,24 @@ 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') +_DObject =3D Dict[str, object] =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: object, 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[_DObject]] =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: _DObject, + ifcond: List[str], + features: Optional[List[QAPISchemaFeature]]) -> None: extra =3D None if mtype not in ('command', 'event', 'builtin', 'array'): if not self._unmask: @@ -189,45 +216,65 @@ def _gen_tree(self, name, mtype, obj, ifcond, feature= s): obj['features'] =3D self._gen_features(features) self._trees.append(Node(obj, ifcond, extra)) =20 - def _gen_member(self, member): - obj =3D {'name': member.name, 'type': self._use_type(member.type)} + def _gen_member(self, + member: QAPISchemaObjectTypeMember) -> Node[_DObject]: + obj: _DObject =3D { + 'name': member.name, + 'type': self._use_type(member.type) + } if member.optional: obj['default'] =3D None if member.features: 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]) -> _DObject: return {'tag': tag_name, 'variants': [self._gen_variant(v) for v in variants]} =20 - def _gen_variant(self, variant): - obj =3D {'case': variant.name, 'type': self._use_type(variant.type= )} + def _gen_variant(self, variant: QAPISchemaVariant) -> Node[_DObject]: + obj: _DObject =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): - obj =3D {'members': [self._gen_member(m) for m in members]} + 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: _DObject =3D {'members': [self._gen_member(m) for m in member= s]} if variants: obj.update(self._gen_variants(variants.tag_member.name, variants.variants)) =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 +282,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[QAPISchemaType], 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: _DObject =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 Sun May 19 03:02:45 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=1600809501; cv=none; d=zohomail.com; s=zohoarc; b=gunpsekImyjMTsuQSeOHZHqjL+WOkpwfHtxF5R1VT9bqqA0VdEgYsN9ga4GAp3lixfUMpQ0Xjxya6qas8G0yugfBiq9GQMwnYN1SfloXq7fJV7E5ygfG2oj8D7rrqd8GYryKUAQHgpGn2VfvV5Vn3swoRgDfoQXj03Jp6Qobp1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809501; 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=Z4w9bu52YJN64UzWB9SJHda3kSLmUfgj+GpZhbmKw5Y=; b=e7l5HR3CfsyU/jRvBYfkfPoB6w9GW1175g2/wg7FCTgyThnktmMmHOPjFfBra8He8Ey22oh+nJYG5w9fXxYGmJKPafh6cZYUKw2sdWvgBw4M4t742OoXtNIyM8JDEkFbbjy4BPReUoHYeE9Ewm9O6hnDdspxRx9Cl0tA8boQVDI= 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 1600809501218491.98917663932764; Tue, 22 Sep 2020 14:18:21 -0700 (PDT) Received: from localhost ([::1]:53786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpg3-0006Oj-Qn for importer@patchew.org; Tue, 22 Sep 2020 17:18:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQN-0002Yh-8R for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:33705) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQH-0004ej-6u for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02: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-50-Op08GOsVO3awFe-FYRVbJw-1; Tue, 22 Sep 2020 17:01:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69544420EB; Tue, 22 Sep 2020 21:01: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 7B9B355765; Tue, 22 Sep 2020 21:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808519; 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=Z4w9bu52YJN64UzWB9SJHda3kSLmUfgj+GpZhbmKw5Y=; b=a1vGjWUUHI+SCGL5Y+jKb58jfFJBqwikfjjBlzGAtfmZUC0dQB3L3fIlAoMGduKZQl7zOZ cvYatAdRN84UTH/IJMrYMUElQ9wEwX7h7msAnSUMG12u9KVqX1+tQrHjxs/6eNKHHV3hW5 7+XvfcFi+x723KLfl+6gbzcp/DxGiHY= X-MC-Unique: Op08GOsVO3awFe-FYRVbJw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 34/38] qapi/types.py: add type hint annotations Date: Tue, 22 Sep 2020 17:00:57 -0400 Message-Id: <20200922210101.4081073-35-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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..5533c5a126 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, + QAPISchemaFeature, + QAPISchemaObjectType, + QAPISchemaObjectTypeMember, + QAPISchemaType, + QAPISchemaVariants, +) =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 Sun May 19 03:02:45 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=1600810485; cv=none; d=zohomail.com; s=zohoarc; b=fbdU82VzHTbEGT9iL8chy+pqGFbvq3BWUqV14oaD0Rz/2z2CL3l9mZU7onM064905IfFjh1dqztA2S6nfMiIHjzi9evBehRhaZf9TVXszuLr1I+6ZUuOhnUV5BlglE9/9vSlKNLo/H6Nh/3QdVZLmaQns89sZ7TLf16fyIeMZG8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810485; 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=Gjv/1TCr1+x4mJxtRx4j/pu85zh+OSeH8cUFmDsVUqY=; b=is35azSIloVYUXkyT8au/z7qSOoy88WiqaDQh/ADKopQKkjECM3bl2z4cfDz8QKk4NMIniaqAEF0EdRkmSw2cpW0/EHkirwOhZSf8DLgR99AQ6FoU0lknLW0qv7akapwDLPt2X/ZB/i7dBzOyIciLMMKx5QTxZtTgqUBM8NdVxk= 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 1600810485610319.5688358566009; Tue, 22 Sep 2020 14:34:45 -0700 (PDT) Received: from localhost ([::1]:44608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpvw-0002ZH-9t for importer@patchew.org; Tue, 22 Sep 2020 17:34:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQa-0002qL-LP for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:27057) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQY-0004g5-My for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02: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-288-BsuXlV0WMFGXxqaiQTGs3w-1; Tue, 22 Sep 2020 17:01:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83B99185A0CA; Tue, 22 Sep 2020 21:01: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 957E855765; Tue, 22 Sep 2020 21:01:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808537; 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=Gjv/1TCr1+x4mJxtRx4j/pu85zh+OSeH8cUFmDsVUqY=; b=RShr8lRA2UlEqZSCoxwLHjIyxqufJjADqR9EPtv2c9LZ0d/ejAoGOSUv3TVhx7mC8sdreU eR7t7+MJj3It+qFs48FEyiXMJbXzgflZ2gzNmmsyD90uSZFsYLbA3ODljT7NaYRVXacxGc O1XgY6Rcoi6iuidWCAHid5kx8SlMhT8= X-MC-Unique: BsuXlV0WMFGXxqaiQTGs3w-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 35/38] qapi/types.py: remove one-letter variables Date: Tue, 22 Sep 2020 17:00:58 -0400 Message-Id: <20200922210101.4081073-36-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" "John, if pylint told you to jump off a bridge, would you?" Hey, if it looked like fun, I might. Now that this file is clean, enable pylint checks on this file. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- 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 de132d03cf..cebaf600f9 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 5533c5a126..78c2a5a3e9 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 Sun May 19 03:02:45 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=1600809298; cv=none; d=zohomail.com; s=zohoarc; b=nkiXNrOEJhRGaszvM+UdjvU7Ke0tKziCMpOhUA6LyiQVB9zxtGz4An4WuuioTVpVZkQsfO1C3BME01kJygbJLyDEIfI+YkMU2My46gv4JchOf7f06dZJ5ho52Mky02MNCNEQuBRd+/+Hk+ytRyl6EcCqcv3mhVbTm8L7U4Yvk9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809298; 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=dwdxZ7usePEAdoPVmc2yggRyJc5HQsHt+MgZta716kw=; b=FukOD3UOuFV5LL9btA7BL8xemIcZQ01y3U4kz40mq9RY8vbtYRrkH9rIvkuRb3JkeQYCmipSANxmfFkX4wnXxTbJcrWWbKNU/QrrQyjQL3uKSVyUc4X1mjCdzUzOKLJo4OwfXlRxq9Z/PYI+IXN3BIaoWCZgna45ksqUrQlrAmA= 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 1600809298289432.85790424413733; Tue, 22 Sep 2020 14:14:58 -0700 (PDT) Received: from localhost ([::1]:45464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpcm-0002pa-UU for importer@patchew.org; Tue, 22 Sep 2020 17:14:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQL-0002YK-EL for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35553) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQH-0004er-68 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:05 -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-216-6po8QN2nNq2xxctc7_aaWA-1; Tue, 22 Sep 2020 17:01:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 98973801FD7; Tue, 22 Sep 2020 21:01:55 +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 AB2DF55765; Tue, 22 Sep 2020 21:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808520; 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=dwdxZ7usePEAdoPVmc2yggRyJc5HQsHt+MgZta716kw=; b=DBr64MgI27Nea9d9DoAas47oPqPCEMBnVkMdvETvgcyRWo3mFVS9X8AukcU9vc4w+BpWFo Wc6zi5T3qDTi1JSLjxCcr6LO2s37nkqxz0ONxLCli1MtEEXicPFB1/7swmXFbvBMY5zzlL zF0y6EhVPSkzmQ6+jdmGpP3SMQ8C2Ro= X-MC-Unique: 6po8QN2nNq2xxctc7_aaWA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 36/38] qapi/visit.py: assert tag_member contains a QAPISchemaEnumType Date: Tue, 22 Sep 2020 17:00:59 -0400 Message-Id: <20200922210101.4081073-37-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost --- scripts/qapi/visit.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/visit.py b/scripts/qapi/visit.py index 4edaee33e3..180c140180 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -22,7 +22,10 @@ indent, ) from .gen import QAPISchemaModularCVisitor, ifcontext -from .schema import QAPISchemaObjectType +from .schema import ( + QAPISchemaEnumType, + QAPISchemaObjectType, +) =20 =20 def gen_visit_decl(name, scalar=3DFalse): @@ -84,15 +87,17 @@ def gen_visit_object_members(name, base, members, varia= nts): ret +=3D gen_endif(memb.ifcond) =20 if variants: + tag_member =3D variants.tag_member + assert isinstance(tag_member.type, QAPISchemaEnumType) + ret +=3D mcgen(''' switch (obj->%(c_name)s) { ''', - c_name=3Dc_name(variants.tag_member.name)) + c_name=3Dc_name(tag_member.name)) =20 for var in variants.variants: - case_str =3D c_enum_const(variants.tag_member.type.name, - var.name, - variants.tag_member.type.prefix) + case_str =3D c_enum_const(tag_member.type.name, var.name, + tag_member.type.prefix) ret +=3D gen_if(var.ifcond) if var.type.name =3D=3D 'q_empty': # valid variant and nothing to do --=20 2.26.2 From nobody Sun May 19 03:02:45 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=1600810316; cv=none; d=zohomail.com; s=zohoarc; b=Rw/C6KhxjbiXKjrxyv+m+LjFR57pEK/CSA30x92Px4WV8oLf5gbLA0gsbvPlAGL2k5RMEUKj6Y/q3FndjO7urcOgieoSl1qs8Dp476ua8CKcIOnhDpAVrF3ZFlSKFso++mI3YH9CLCJBPgxdKsBsMK7NTvtC9K2zUMnDEYtAuyw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810316; 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=5faI8ElcYvnxKPiHc83uD5yKXb0k2Hk/EbySAFimiQk=; b=mhEkQtgmjV03LK/9OLGqe77L8fh472XaV2wgkTHItZ7acR7pDgOldi3uAN4mB2kYQwXpeDBRGL0h9UKIdxLAJN4vCAPpkvUTkYwirppXESkJQIq79BvdzGOKNfu8FWom0g3g7VDHYyUyIpQx6HYtBTxrAx5bXgosSAnJrSul1ig= 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 1600810316695709.4379920560932; Tue, 22 Sep 2020 14:31:56 -0700 (PDT) Received: from localhost ([::1]:35936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKptD-00073i-9I for importer@patchew.org; Tue, 22 Sep 2020 17:31:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQK-0002Xk-AP for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:05 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:50813 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 1kKpQH-0004em-6B for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:04 -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-590-ifGqNRatOQ6biSVpmdow9w-1; Tue, 22 Sep 2020 17:01:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2D85186841A; Tue, 22 Sep 2020 21:01: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 C28DA5577A; Tue, 22 Sep 2020 21:01:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808519; 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=5faI8ElcYvnxKPiHc83uD5yKXb0k2Hk/EbySAFimiQk=; b=ez09atZWKXYlGazAz49QsV/bvYWMisDtCITZqMcAlh7JgkWvm/ARV4X3+miZWHQZbqMfU7 s1snnBi5GllkMaeWN3vEzkcfsMUlwYmiLxP5sIa02L8duvUh0j/4ljrpCNTfdWI5zw27lR HiDiJMHNITCPq8Bx0jiNP9B3KW+3RrQ= X-MC-Unique: ifGqNRatOQ6biSVpmdow9w-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 37/38] qapi/visit.py: remove unused parameters from gen_visit_object Date: Tue, 22 Sep 2020 17:01:00 -0400 Message-Id: <20200922210101.4081073-38-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.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/22 17:00:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow 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 Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost Tested-by: Cleber Rosa --- 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 cebaf600f9..581755351b 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 180c140180..ec9d36e72f 100644 --- a/scripts/qapi/visit.py +++ b/scripts/qapi/visit.py @@ -253,7 +253,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 @@ -346,7 +346,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 Sun May 19 03:02:45 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=1600810341; cv=none; d=zohomail.com; s=zohoarc; b=SV35EOWfa0FzNsLh0C8JYsqR6dt5tr22YJcgVl6XfE+KvpY+gfFzoLe6O4O2Z8h1qOamCb4is0Mn3OwFkVbK8cD2FZJkzrBm1HdDjbFmlx20pKurVRhC8IYXIi1Juw95gN/whJAgkAeuh6vvh+P/78T2GJJq+dUuLFbCKBPIzzU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810341; 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=rv+GbJMGvi07Ydrp0iM6tLrOr0MCaCDZiPfLKRTNgy8=; b=Qo4nEz9ClxQs6kH6J7Lp+xVVCIcISJlQ+1K+Aa9zq7K2Yi8AzYHSWvrh/2YCSkS3MX3UxJstoSoTYnDrVGvcbtt7n7PwVjo+hmZ0bd9AW0UZwq55/AVgyWOlMkmYX0OKd+gs4NOl4CTvruyKX5YXtJNit7HQPHSK2X+CC3coVuM= 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 1600810341690283.79756654893913; Tue, 22 Sep 2020 14:32:21 -0700 (PDT) Received: from localhost ([::1]:36382 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKptc-0007FT-A0 for importer@patchew.org; Tue, 22 Sep 2020 17:32:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37484) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpQP-0002aE-Bq for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpQI-0004ew-Ds for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:02: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-477-X2BgJvh1NCWS7iDwI4Oqgg-1; Tue, 22 Sep 2020 17:01:59 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C3570185A0CA; Tue, 22 Sep 2020 21:01:57 +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 DAD4455765; Tue, 22 Sep 2020 21:01:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600808520; 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=rv+GbJMGvi07Ydrp0iM6tLrOr0MCaCDZiPfLKRTNgy8=; b=Gsw4vavPbwGpY4hUuWus5kfYiQ8aAwtPV/yhPYe7yOIP/0QGGbejUKx3N8qAtrNeVHyt3O xG3I0rtURgiE+QFAjJmb2280JDQIrQF0UGrfetWrMQmHPyGMJqfHaiqo3YT11BRxzJS05G L+e0qfNGg2poJ9p/7I5jTK1HpWKcWH4= X-MC-Unique: X2BgJvh1NCWS7iDwI4Oqgg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v2 38/38] qapi/visit.py: add type hint annotations Date: Tue, 22 Sep 2020 17:01:01 -0400 Message-Id: <20200922210101.4081073-39-jsnow@redhat.com> In-Reply-To: <20200922210101.4081073-1-jsnow@redhat.com> References: <20200922210101.4081073-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, 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: Peter Maydell , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Cleber Rosa , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost Tested-by: Cleber Rosa --- scripts/qapi/mypy.ini | 5 ---- scripts/qapi/visit.py | 68 +++++++++++++++++++++++++++++++++---------- 2 files changed, 52 insertions(+), 21 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 ec9d36e72f..3bd06661c4 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, @@ -23,12 +25,19 @@ ) from .gen import QAPISchemaModularCVisitor, ifcontext from .schema import ( + QAPISchema, + QAPISchemaEnumMember, QAPISchemaEnumType, + QAPISchemaFeature, QAPISchemaObjectType, + QAPISchemaObjectTypeMember, + QAPISchemaType, + QAPISchemaVariants, ) +from .source import QAPISourceInfo =20 =20 -def gen_visit_decl(name, scalar=3DFalse): +def gen_visit_decl(name: str, scalar: bool =3D False) -> str: c_type =3D c_name(name) + ' *' if not scalar: c_type +=3D '*' @@ -40,7 +49,7 @@ def gen_visit_decl(name, scalar=3DFalse): c_name=3Dc_name(name), c_type=3Dc_type) =20 =20 -def gen_visit_members_decl(name): +def gen_visit_members_decl(name: str) -> str: return mcgen(''' =20 bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **er= rp); @@ -48,7 +57,10 @@ def gen_visit_members_decl(name): c_name=3Dc_name(name)) =20 =20 -def gen_visit_object_members(name, base, members, variants): +def gen_visit_object_members(name: str, + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> st= r: ret =3D mcgen(''' =20 bool visit_type_%(c_name)s_members(Visitor *v, %(c_name)s *obj, Error **er= rp) @@ -128,7 +140,7 @@ def gen_visit_object_members(name, base, members, varia= nts): return ret =20 =20 -def gen_visit_list(name, element_type): +def gen_visit_list(name: str, element_type: QAPISchemaType) -> str: return mcgen(''' =20 bool visit_type_%(c_name)s(Visitor *v, const char *name, @@ -162,7 +174,7 @@ def gen_visit_list(name, element_type): c_name=3Dc_name(name), c_elt_type=3Delement_type.c_name()) =20 =20 -def gen_visit_enum(name): +def gen_visit_enum(name: str) -> str: return mcgen(''' =20 bool visit_type_%(c_name)s(Visitor *v, const char *name, @@ -177,7 +189,7 @@ def gen_visit_enum(name): c_name=3Dc_name(name)) =20 =20 -def gen_visit_alternate(name, variants): +def gen_visit_alternate(name: str, variants: QAPISchemaVariants) -> str: ret =3D mcgen(''' =20 bool visit_type_%(c_name)s @@ -253,7 +265,7 @@ def gen_visit_alternate(name, variants): return ret =20 =20 -def gen_visit_object(name): +def gen_visit_object(name: str) -> str: return mcgen(''' =20 bool visit_type_%(c_name)s @@ -288,12 +300,12 @@ def gen_visit_object(name): =20 class QAPISchemaGenVisitVisitor(QAPISchemaModularCVisitor): =20 - def __init__(self, prefix): + def __init__(self, prefix: str): super().__init__( prefix, 'qapi-visit', ' * Schema-defined QAPI visitors', ' * Built-in QAPI visitors', __doc__) =20 - def _begin_system_module(self, name): + def _begin_system_module(self, name: None) -> None: self._genc.preamble_add(mcgen(''' #include "qemu/osdep.h" #include "qapi/error.h" @@ -305,7 +317,7 @@ def _begin_system_module(self, name): =20 ''')) =20 - def _begin_user_module(self, name): + def _begin_user_module(self, name: str) -> None: types =3D self._module_basename('qapi-types', name) visit =3D self._module_basename('qapi-visit', name) self._genc.preamble_add(mcgen(''' @@ -322,18 +334,34 @@ def _begin_user_module(self, name): ''', types=3Dtypes)) =20 - def visit_enum_type(self, name, info, ifcond, features, members, prefi= x): + def visit_enum_type(self, + name: str, + info: QAPISourceInfo, + ifcond: List[str], + features: List[QAPISchemaFeature], + members: List[QAPISchemaEnumMember], + prefix: Optional[str]) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name, scalar=3DTrue)) self._genc.add(gen_visit_enum(name)) =20 - def visit_array_type(self, name, info, ifcond, element_type): + def visit_array_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: List[str], + element_type: QAPISchemaType) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_list(name, element_type)) =20 - def visit_object_type(self, name, info, ifcond, features, - base, members, variants): + def visit_object_type(self, + name: str, + info: Optional[QAPISourceInfo], + ifcond: List[str], + features: List[QAPISchemaFeature], + base: Optional[QAPISchemaObjectType], + members: List[QAPISchemaObjectTypeMember], + variants: Optional[QAPISchemaVariants]) -> None: # Nothing to do for the special empty builtin if name =3D=3D 'q_empty': return @@ -348,13 +376,21 @@ def visit_object_type(self, name, info, ifcond, featu= res, self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_object(name)) =20 - def visit_alternate_type(self, name, info, ifcond, features, variants): + def visit_alternate_type(self, + name: str, + info: QAPISourceInfo, + ifcond: List[str], + features: List[QAPISchemaFeature], + variants: QAPISchemaVariants) -> None: with ifcontext(ifcond, self._genh, self._genc): self._genh.add(gen_visit_decl(name)) self._genc.add(gen_visit_alternate(name, variants)) =20 =20 -def gen_visit(schema, output_dir, prefix, opt_builtins): +def gen_visit(schema: QAPISchema, + output_dir: str, + prefix: str, + opt_builtins: bool) -> None: vis =3D QAPISchemaGenVisitVisitor(prefix) schema.visit(vis) vis.write(output_dir, opt_builtins) --=20 2.26.2