From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621533518; cv=none; d=zohomail.com; s=zohoarc; b=C7id+aMOdgvEbSwCQjDAo3+CxNAy2tVAOdu4+Qmh/MpoxjtMCsf8445Gd7Yz8g4m6xYrdNUAVwY1MAKjUNUl2BivNOx5tpxXUOxTqP4ASb5HZkDum0NnA3XcoUOOphWE3tCoFbgw303lvEXAnVMqep7G7SSh5cH2RzhdeB3XriU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621533518; 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=O+Y4vKwQgLFxmUB8GBsnkT3KWgnLn3bm3S6VROGERys=; b=KYiCNWw9GBq6PoUl/+KQ9HmLQ+VpfJJ1H4IucKczW1vsVVsPR6St+kJKTbTirUUoyHhjNxWjTMUDlV0PrugtHkSq47RdvgLBSd1vQqJH9HPHEIWWWY2DHOPl1leRUD+ECQa3/YVl4vBAGI2tUjVcR2i2nxdaY4HNN/ElzpkO3eQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 162153351857719.522554282582746; Thu, 20 May 2021 10:58:38 -0700 (PDT) Received: from localhost ([::1]:50860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljmwP-0002yb-DA for importer2@patchew.org; Thu, 20 May 2021 13:58:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrL-0002oi-1G for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:36810) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr1-0006aP-3z for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:17 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-67-pSx4W1aCOC-h0x1QxoqRGw-1; Thu, 20 May 2021 13:52:58 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EA0C4107ACE4; Thu, 20 May 2021 17:52:57 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99F7836D5; Thu, 20 May 2021 17:52:57 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 38056113861E; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533181; 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=O+Y4vKwQgLFxmUB8GBsnkT3KWgnLn3bm3S6VROGERys=; b=CvMdm4oHShguiQ1RvFTBu7cDaJNWxP4mhKuv1X0Go6azoeWKxAm5EpyoCyaoFaSrPlvM64 LjqCItVOy5nOPiNqn6q18SrSOYJtWIK5gIem0HKbEVfDXEC6nqbQnZNTXkUtU1S5VzXTjY ZhF6x+r16E+IO5auq4vjXZUFUyGPVvM= X-MC-Unique: pSx4W1aCOC-h0x1QxoqRGw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 01/15] qapi/parser: Don't try to handle file errors Date: Thu, 20 May 2021 19:52:42 +0200 Message-Id: <20210520175256.1119684-2-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Fixes: f5d4361cda Fixes: 52a474180a Fixes: 46f49468c6 Remove the try/except block that handles file-opening errors in QAPISchemaParser.__init__() and add one each to QAPISchemaParser._include() and QAPISchema.__init__() respectively. This simultaneously fixes the typing of info.fname (f5d4361cda), A static typing violation in test-qapi (46f49468c6), and a regression of an error message (52a474180a). The short-ish version of what motivates this patch is: - It's hard to write a good error message in the init method, because we need to determine the context of our caller to do so. It's easier to just let the caller write the message. - We don't want to allow QAPISourceInfo(None, None, None) to exist. The typing introduced by commit f5d4361cda types the 'fname' field as (non-optional) str, which was premature until the removal of this construct. - Errors made using such an object are currently incorrect (since 52a474180a) - It's not technically a semantic error if we cannot open the schema. - There are various typing constraints that make mixing these two cases undesirable for a single special case. - test-qapi's code handling an fname of 'None' is now dead, drop it. Additionally, Not all QAPIError objects have an 'info' field (since 46f49468), so deleting this stanza corrects a typing oversight in test-qapi introduced by that commit. Other considerations: - open() is moved to a 'with' block to ensure file pointers are cleaned up deterministically. - Python 3.3 deprecated IOError and made it a synonym for OSError. Avoid the misleading perception these exception handlers are narrower than they really are. The long version: The error message here is incorrect (since commit 52a474180a): > python3 qapi-gen.py 'fake.json' qapi-gen.py: qapi-gen.py: can't read schema file 'fake.json': No such file = or directory In pursuing it, we find that QAPISourceInfo has a special accommodation for when there's no filename. Meanwhile, the intent when QAPISourceInfo was typed (f5d4361cda) was non-optional 'str'. This usage was overlooked. To remove this, I'd want to avoid having a "fake" QAPISourceInfo object. I also don't want to explicitly begin accommodating QAPISourceInfo itself being None, because we actually want to eventually prove that this can never happen -- We don't want to confuse "The file isn't open yet" with "This error stems from a definition that wasn't defined in any file". (An earlier series tried to create a dummy info object, but it was tough to prove in review that it worked correctly without creating new regressions. This patch avoids that distraction. We would like to first prove that we never raise QAPISemError for any built-in object before we add "special" info objects. We aren't ready to do that yet.) So, which way out of the labyrinth? Here's one way: Don't try to handle errors at a level with "mixed" semantic contexts; i.e. don't mix inclusion errors (should report a source line where the include was triggered) and command line errors (where we specified a file we couldn't read). Remove the error handling from the initializer of the parser. Pythonic! Now it's the caller's job to figure out what to do about it. Handle the error in QAPISchemaParser._include() instead, where we can write a targeted error message where we are guaranteed to have an 'info' context to report with. The root level error can similarly move to QAPISchema.__init__(), where we know we'll never have an info context to report with, so we use a more abstract error type. Now the error looks sensible again: > python3 qapi-gen.py 'fake.json' qapi-gen.py: can't read schema file 'fake.json': No such file or directory With these error cases separated, QAPISourceInfo can be solidified as never having placeholder arguments that violate our desired types. Clean up test-qapi along similar lines. Signed-off-by: John Snow Message-Id: <20210519183951.3946870-2-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 18 +++++++++--------- scripts/qapi/schema.py | 11 +++++++++-- scripts/qapi/source.py | 3 --- tests/qapi-schema/test-qapi.py | 3 --- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index ca5e8e18e0..a53b735e7d 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -40,15 +40,9 @@ def __init__(self, fname, previously_included=3DNone, in= cl_info=3DNone): previously_included =3D previously_included or set() previously_included.add(os.path.abspath(fname)) =20 - try: - fp =3D open(fname, 'r', encoding=3D'utf-8') + # May raise OSError; allow the caller to handle it. + with open(fname, 'r', encoding=3D'utf-8') as fp: self.src =3D fp.read() - except IOError as e: - raise QAPISemError(incl_info or QAPISourceInfo(None, None, Non= e), - "can't read %s file '%s': %s" - % ("include" if incl_info else "schema", - fname, - e.strerror)) =20 if self.src =3D=3D '' or self.src[-1] !=3D '\n': self.src +=3D '\n' @@ -129,7 +123,13 @@ def _include(self, include, info, incl_fname, previous= ly_included): if incl_abs_fname in previously_included: return None =20 - return QAPISchemaParser(incl_fname, previously_included, info) + try: + return QAPISchemaParser(incl_fname, previously_included, info) + except OSError as err: + raise QAPISemError( + info, + f"can't read include file '{incl_fname}': {err.strerror}" + ) from err =20 def _check_pragma_list_of_str(self, name, value, info): if (not isinstance(value, list) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 3a4172fb74..d1d27ff7ee 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -20,7 +20,7 @@ from typing import Optional =20 from .common import POINTER_SUFFIX, c_name -from .error import QAPISemError, QAPISourceError +from .error import QAPIError, QAPISemError, QAPISourceError from .expr import check_exprs from .parser import QAPISchemaParser =20 @@ -849,7 +849,14 @@ def visit(self, visitor): class QAPISchema: def __init__(self, fname): self.fname =3D fname - parser =3D QAPISchemaParser(fname) + + try: + parser =3D QAPISchemaParser(fname) + except OSError as err: + raise QAPIError( + f"can't read schema file '{fname}': {err.strerror}" + ) from err + exprs =3D check_exprs(parser.exprs) self.docs =3D parser.docs self._entity_list =3D [] diff --git a/scripts/qapi/source.py b/scripts/qapi/source.py index 03b6ede082..1ade864d7b 100644 --- a/scripts/qapi/source.py +++ b/scripts/qapi/source.py @@ -10,7 +10,6 @@ # See the COPYING file in the top-level directory. =20 import copy -import sys from typing import List, Optional, TypeVar =20 =20 @@ -53,8 +52,6 @@ def next_line(self: T) -> T: return info =20 def loc(self) -> str: - if self.fname is None: - return sys.argv[0] ret =3D self.fname if self.line is not None: ret +=3D ':%d' % self.line diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index e8db9d09d9..f1c4deb9a5 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -128,9 +128,6 @@ def test_and_diff(test_name, dir_name, update): try: test_frontend(os.path.join(dir_name, test_name + '.json')) except QAPIError as err: - if err.info.fname is None: - print("%s" % err, file=3Dsys.stderr) - return 2 errstr =3D str(err) + '\n' if dir_name: errstr =3D errstr.replace(dir_name + '/', '') --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621533519; cv=none; d=zohomail.com; s=zohoarc; b=CV86+pW6S/yi5JQrs9hmqzHIB0GkHXtT52r/Uh7NEKJnWuMcvwiE14vwI3DCnpOmqiK4K8nprMjDB5n8J8hIImgHh5emx6ey51F/Sl8dn7vDJ+QFZFJrbQwGYHPfPlDrSbFBkZBL2YMd3UJnEN9Hj1dd+HA/EWEE8DcgEDLOlo8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621533519; 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=TTSBUHyyZ4C9VH87or9MiGZwdNubQ0xMg/dYqRxpjps=; b=RLhooW5oCL5naanwy2M+F27K95GGPx+WMtyQtv0a2Y2ZpPRN837V+45twAqguqAvvY1lBRaLAesYxk+Z2s36VqJWBfMCzWlOKTE9+/amFrHInpN1WR5MRzKgCRwlC8X13/KHlyUGL0Trr8IcbQnKNnmOP+dn78rYmBVnSXg0lO0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621533519807220.26151868768886; Thu, 20 May 2021 10:58:39 -0700 (PDT) Received: from localhost ([::1]:51008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljmwQ-00034P-KF for importer2@patchew.org; Thu, 20 May 2021 13:58:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrQ-0002pQ-GZ for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:28183) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr1-0006aO-AV for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53: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-505-hG6Mie6FPG2dMtuhmEajYw-1; Thu, 20 May 2021 13:52:58 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CB74F800D62; Thu, 20 May 2021 17:52:57 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A9A219C59; Thu, 20 May 2021 17:52:57 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3BA101138529; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533181; 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=TTSBUHyyZ4C9VH87or9MiGZwdNubQ0xMg/dYqRxpjps=; b=AhbSqaqO1DTg3zOWc4Zl0eNyfru10Jfi+YJ8mnW0MUGOpoqPcwGvUVS9UevcTWotl6T09l 9X11tNekbv8/+d/ROnnd7Era5Uilvlqo1qw+KqS224wq8QTFgMUUVIinfWVp/+rDhNHrYu 1ZvL4SVTSOAQ8Sfajr6wIChKm6pg2UI= X-MC-Unique: hG6Mie6FPG2dMtuhmEajYw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 02/15] qapi: Add test for nonexistent schema file Date: Thu, 20 May 2021 19:52:43 +0200 Message-Id: <20210520175256.1119684-3-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow This tests the error-return pathway introduced in the previous commit. (Thanks to Paolo for the help with the Meson magic.) Signed-off-by: John Snow Message-Id: <20210519183951.3946870-3-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- tests/qapi-schema/meson.build | 7 ++++++- tests/qapi-schema/missing-schema.err | 1 + tests/qapi-schema/missing-schema.out | 0 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 tests/qapi-schema/missing-schema.err create mode 100644 tests/qapi-schema/missing-schema.out diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index d7163e6601..dc448e8f74 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -199,11 +199,16 @@ schemas =3D [ 'unknown-escape.json', 'unknown-expr-key.json', ] +schemas =3D files(schemas) + +# Intentionally missing schema file test -- not passed through files(): +schemas +=3D [meson.current_source_dir() / 'missing-schema.json'] =20 # Because people may want to use test-qapi.py from the command line, we # are not using the "#! /usr/bin/env python3" trick here. See # docs/devel/build-system.txt -test('QAPI schema regression tests', python, args: files('test-qapi.py', s= chemas), +test('QAPI schema regression tests', python, + args: files('test-qapi.py') + schemas, env: test_env, suite: ['qapi-schema', 'qapi-frontend']) =20 diff =3D find_program('diff') diff --git a/tests/qapi-schema/missing-schema.err b/tests/qapi-schema/missi= ng-schema.err new file mode 100644 index 0000000000..b4d9ff1fb2 --- /dev/null +++ b/tests/qapi-schema/missing-schema.err @@ -0,0 +1 @@ +can't read schema file 'missing-schema.json': No such file or directory diff --git a/tests/qapi-schema/missing-schema.out b/tests/qapi-schema/missi= ng-schema.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621533299; cv=none; d=zohomail.com; s=zohoarc; b=d5vrZMisnNx12GXnAcPVivoBlOPdnVVrpTCqesNBG/8GZbDEsMLRPa7FN77YSaxgXsh1PC9ADQ8WESxtk8/gHnSWHjBmMG1dMO78S25x+Kvt1D7lcBjUAfnHEn7BfypF1NIPtvnsMpMeVL35FvDfk0Ujoo9CouLuTsqSyAQGPl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621533299; 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=vqpZSkG9ZDrPtDa0QqRSNgCGX7MW2yyDXgUF7Am+AfI=; b=QdeMlrDZ4LumSbSy1BJI9hXWErCeJQZTLJBO49CCZrC/cEsZkiqlVNRRNPa/2neXsh6JP0s0EZDSYH6KMK5HgWh+V1v7FhvGl7cJqE7XFS0uQ8Hr8TYPyXIwtKMhvYpnqlAqf3ENrlRH3ZcgP5KyE5idT869UfVPnxVV8R2Pves= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 16215332991866.420346105832209; Thu, 20 May 2021 10:54:59 -0700 (PDT) Received: from localhost ([::1]:42604 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljmss-0005fE-4F for importer2@patchew.org; Thu, 20 May 2021 13:54:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrX-0002sU-IU for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr9-0006dr-Av for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53: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-300-2P1giw3kP2KmsIEy0jd87Q-1; Thu, 20 May 2021 13:52:58 -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 C5C6A501ED; Thu, 20 May 2021 17:52:57 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9976F5D74D; Thu, 20 May 2021 17:52:57 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 3F97811384A2; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533188; 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=vqpZSkG9ZDrPtDa0QqRSNgCGX7MW2yyDXgUF7Am+AfI=; b=LyViRd0KHqLb4D8BSPLULaUT5laOT2ITGjCs4C1nbBWMjS3iMRs1WlAGg5oGf7GnaMGq92 B2hcJVLa5nyvStV1fjas7wm50wE6875sg5zhSWR5BzvJC5f/nNNVV5/HLuFoxoKrbgfTpT aNM/VLj71k3wjhR5IaCq6uVZUDl5YZk= X-MC-Unique: 2P1giw3kP2KmsIEy0jd87Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 03/15] qapi/source: Remove line number from QAPISourceInfo initializer Date: Thu, 20 May 2021 19:52:44 +0200 Message-Id: <20210520175256.1119684-4-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@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=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow With the QAPISourceInfo(None, None, None) construct gone, there's no longer any reason to have to specify that a file starts on the first line. Remove it from the initializer and default it to 1. Remove the last vestiges where we check for 'line' being unset, that can't happen, now. Signed-off-by: John Snow Message-Id: <20210519183951.3946870-4-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 2 +- scripts/qapi/source.py | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index a53b735e7d..39dbcc4eac 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -47,7 +47,7 @@ def __init__(self, fname, previously_included=3DNone, inc= l_info=3DNone): if self.src =3D=3D '' or self.src[-1] !=3D '\n': self.src +=3D '\n' self.cursor =3D 0 - self.info =3D QAPISourceInfo(fname, 1, incl_info) + self.info =3D QAPISourceInfo(fname, incl_info) self.line_pos =3D 0 self.exprs =3D [] self.docs =3D [] diff --git a/scripts/qapi/source.py b/scripts/qapi/source.py index 1ade864d7b..04193cc964 100644 --- a/scripts/qapi/source.py +++ b/scripts/qapi/source.py @@ -31,10 +31,9 @@ def __init__(self) -> None: class QAPISourceInfo: T =3D TypeVar('T', bound=3D'QAPISourceInfo') =20 - def __init__(self, fname: str, line: int, - parent: Optional['QAPISourceInfo']): + def __init__(self, fname: str, parent: Optional['QAPISourceInfo']): self.fname =3D fname - self.line =3D line + self.line =3D 1 self.parent =3D parent self.pragma: QAPISchemaPragma =3D ( parent.pragma if parent else QAPISchemaPragma() @@ -52,10 +51,7 @@ def next_line(self: T) -> T: return info =20 def loc(self) -> str: - ret =3D self.fname - if self.line is not None: - ret +=3D ':%d' % self.line - return ret + return f"{self.fname}:{self.line}" =20 def in_defn(self) -> str: if self.defn_name: --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621534816; cv=none; d=zohomail.com; s=zohoarc; b=gw0sEIvd5t0yqnkLZFoUqHW8+v9oP7y4vCFwvVinQ+ovLp4ymOS7E9occyKJ3nKjrpesW7xrInj85O3A5eeFpG+ORaQWeIXROzAW/2de2Sn5qnMWIeBOwaAOUw55DwUnd/OMFFhaGGjFfCBSuP3XECaUAbRwD62DRfU5dQivSWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621534816; 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=NIjrC4I2gBVvk4OuX/ExltCFxOjqL0VWvWQ2KCvQJ/Y=; b=MRcXNE591tMAQHknMPTLxzGVQAhHB/2+DYPXBsojI7NFjCyEnZ3tc2CQI/W6W1uP2DJWP/0g1Lwx/VjITFTe0BcVRul1gIj8d3EqLsNGdo/DHOV1j/PIDv42m1TnDOo8ylWrKaFPciC5ym4D8prfiR1hllAxRNi9OdtVlxY3jfI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621534816573941.7504596708446; Thu, 20 May 2021 11:20:16 -0700 (PDT) Received: from localhost ([::1]:34432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljnHL-0005Iy-80 for importer2@patchew.org; Thu, 20 May 2021 14:20:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrU-0002q9-KG for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59910) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr3-0006d0-Cl for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:27 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-57-tOzloE1fPkuL_zArRs-2lA-1; Thu, 20 May 2021 13:52:58 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C9437801B15; Thu, 20 May 2021 17:52:57 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A4D75C261; Thu, 20 May 2021 17:52:57 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 42F3C1138461; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533184; 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=NIjrC4I2gBVvk4OuX/ExltCFxOjqL0VWvWQ2KCvQJ/Y=; b=Hxfc8E34z4y6bdjMotIHzOAgaS1PDGt+4h/9fCzVc/UiPmrjaazsDeDKpakkLyJwoXgOLI aNcdUfGo2tWP53PID7iy5AI33ljp6lGiWWwksnN3xbvkUNvrO8gwhDaK9949qTPBIk+I9U axDHFuTwBuvfylgnF1D9wgpBURY6YFw= X-MC-Unique: tOzloE1fPkuL_zArRs-2lA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 04/15] qapi/parser: factor parsing routine into method Date: Thu, 20 May 2021 19:52:45 +0200 Message-Id: <20210520175256.1119684-5-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow For the sake of keeping __init__ smaller (and treating it more like a gallery of what state variables we can expect to see), put the actual parsing action into a parse method. It remains invoked from the init method to reduce churn. To accomplish this, @previously_included becomes the private data member ._included, and the filename is stashed as ._fname. Add any missing declarations to the init method, and group them by function so they can be understood quickly at a glance. Signed-off-by: John Snow Message-Id: <20210519183951.3946870-5-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 39dbcc4eac..d620706fff 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -37,23 +37,39 @@ def __init__(self, parser, msg): class QAPISchemaParser: =20 def __init__(self, fname, previously_included=3DNone, incl_info=3DNone= ): - previously_included =3D previously_included or set() - previously_included.add(os.path.abspath(fname)) + self._fname =3D fname + self._included =3D previously_included or set() + self._included.add(os.path.abspath(self._fname)) + self.src =3D '' =20 - # May raise OSError; allow the caller to handle it. - with open(fname, 'r', encoding=3D'utf-8') as fp: - self.src =3D fp.read() - - if self.src =3D=3D '' or self.src[-1] !=3D '\n': - self.src +=3D '\n' + # Lexer state (see `accept` for details): + self.info =3D QAPISourceInfo(self._fname, incl_info) + self.tok =3D None + self.pos =3D 0 self.cursor =3D 0 - self.info =3D QAPISourceInfo(fname, incl_info) + self.val =3D None self.line_pos =3D 0 + + # Parser output: self.exprs =3D [] self.docs =3D [] - self.accept() + + # Showtime! + self._parse() + + def _parse(self): cur_doc =3D None =20 + # May raise OSError; allow the caller to handle it. + with open(self._fname, 'r', encoding=3D'utf-8') as fp: + self.src =3D fp.read() + if self.src =3D=3D '' or self.src[-1] !=3D '\n': + self.src +=3D '\n' + + # Prime the lexer: + self.accept() + + # Parse until done: while self.tok is not None: info =3D self.info if self.tok =3D=3D '#': @@ -71,12 +87,12 @@ def __init__(self, fname, previously_included=3DNone, i= ncl_info=3DNone): if not isinstance(include, str): raise QAPISemError(info, "value of 'include' must be a strin= g") - incl_fname =3D os.path.join(os.path.dirname(fname), + incl_fname =3D os.path.join(os.path.dirname(self._fname), include) self.exprs.append({'expr': {'include': incl_fname}, 'info': info}) exprs_include =3D self._include(include, info, incl_fname, - previously_included) + self._included) if exprs_include: self.exprs.extend(exprs_include.exprs) self.docs.extend(exprs_include.docs) --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621534091; cv=none; d=zohomail.com; s=zohoarc; b=Xg5dvf87ixEWabBvK7LdpM00xejp5zv3gYJv7C3KMy5RgB/Vp9lbF9JHsoYvo9qambE8HCpS6hdg1iaa9XnYAqzNyxZD19Bjo0H3pyiesHw+yRbunx+IHxbMjjt4IC5OqjJmXJV+Y+R0IF/sJvIk9Jk12lzt7qw77WuI0mMAGiA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621534091; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=B+anRg/0RPO2Euj/9Ppbrr5zyoz8p3qnHbW6T6AUoso=; b=m7kvY1P6nF16fpWn+BDyCquDhDgvg6PvrZerkRRYGI6PsdDMUAuD7WHJACQvZozmo3mdisfx4gJKGztFwAzDvu/FzY3yKSxoVRVxiFrONKaPSxCbr4Qsr0Dvyprs0wTbktOoAl9WUOGywAVDOu5kAhstirhqrtSkzEU64C/DfQc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621534091269795.1731287337432; Thu, 20 May 2021 11:08:11 -0700 (PDT) Received: from localhost ([::1]:45338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljn5e-0001qz-5d for importer2@patchew.org; Thu, 20 May 2021 14:08:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrY-0002ux-7C for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:29711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr3-0006dC-EF for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53: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-109-hvvkvqeZNIePWCV0i-u8uA-1; Thu, 20 May 2021 13:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 750FF801B19; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F1BF6064B; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 483EB1138468; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533184; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B+anRg/0RPO2Euj/9Ppbrr5zyoz8p3qnHbW6T6AUoso=; b=H2/JbHFrRzzBnBYtlhCbjbY53fjEKFpM7H5bTpr6TbpJfIxGpOSskSZfFoinziv+//noT8 DOxNXSkL3hcbQCSSQp2PEF/mDnkqppRrgVpn14u6vkJATACK46SOPb9ZMURUWrVMbk46fM 3qmPJTLaT2dqnbESsUhLJ3ApkK5I+D4= X-MC-Unique: hvvkvqeZNIePWCV0i-u8uA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 05/15] qapi/parser: Assert lexer value is a string Date: Thu, 20 May 2021 19:52:46 +0200 Message-Id: <20210520175256.1119684-6-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow The type checker can't narrow the type of the token value to string, because it's only loosely correlated with the return token. We know that a token of '#' should always have a "str" value. Add an assertion. Signed-off-by: John Snow Message-Id: <20210519183951.3946870-6-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index d620706fff..0bc852eda7 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -304,6 +304,7 @@ def get_doc(self, info): cur_doc =3D QAPIDoc(self, info) self.accept(False) while self.tok =3D=3D '#': + assert isinstance(self.val, str) if self.val.startswith('##'): # End of doc comment if self.val !=3D '##': --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621534163; cv=none; d=zohomail.com; s=zohoarc; b=EueeeM4NM6uh3WB/rP88VTNgj3s0pjaZrg56AXlFRLtWNQeeELeo8fZLfQc5ACaNdxtnSCyjtfa6OTu3z/1lFDSBWM07uR9K/oG9upBSfLzaR7MbMVDPSX0DKvGTMwXAbOPPqEswP3wr4YfHI8SuV0ub+aPPGsS2cRkTSDTmYWU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621534163; 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=p3t2zKU0mg+50vXcwjkyMJ2OJtWitEQR+GSzr+7nDu0=; b=MHKKZ9CxZdJ9gfp942ablum+f8iyQhDc2MkIWPw4rMVEcVT5a3zK0wB3a/cuFaQn8DzXktsthGym3eZzkpfwEK8pnYmE3tOMiHbsYBBuNyVX8ND7kMIu6/Q3+vTuDyQ08EChBQQpTxHsw1XGo6tgiCUw2rNGDOdeMDjpWoN0QQE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621534163826948.4177121475618; Thu, 20 May 2021 11:09:23 -0700 (PDT) Received: from localhost ([::1]:47302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljn6o-0003Aj-Ni for importer2@patchew.org; Thu, 20 May 2021 14:09:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrJ-0002oX-58 for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:48888) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr1-0006ab-3m for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53: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-188-dznmRNSaNeOHAwFdHrfynQ-1; Thu, 20 May 2021 13:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 737BA1007B06; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F5CB687DB; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4A3C71138469; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533182; 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=p3t2zKU0mg+50vXcwjkyMJ2OJtWitEQR+GSzr+7nDu0=; b=X6oK12D1zG6cXIQ1GuSPJkWu/1DK0LHCgR1xCZau8eZrSX23SY0xWe3wmJ5Glg4WODbq+J zMmasRrv8owSUA/6s4VdC42HCsA/hR5NkBbSFv2XNscnJ+q2fFA9WVzRa1IJMqzs3Wfmtg jRw753VanfHpNPXKmlfZpBj7kgutA5c= X-MC-Unique: dznmRNSaNeOHAwFdHrfynQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 06/15] qapi/parser: enforce all top-level expressions must be dict in _parse() Date: Thu, 20 May 2021 19:52:47 +0200 Message-Id: <20210520175256.1119684-7-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Instead of using get_expr nested=3DFalse, allow get_expr to always return any expression. In exchange, add a new error message to the top-level parser that explains the semantic error: Top-level expressions must always be JSON objects. This helps mypy understand the rest of this function which assumes that get_expr did indeed return a dict. The exception type changes from QAPIParseError to QAPISemError as a result, and the error message in two tests now changes. Signed-off-by: John Snow Message-Id: <20210519183951.3946870-7-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 14 ++++++++------ tests/qapi-schema/non-objects.err | 2 +- tests/qapi-schema/quoted-structural-chars.err | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 0bc852eda7..ffdd4298b6 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -78,7 +78,11 @@ def _parse(self): self.docs.append(cur_doc) continue =20 - expr =3D self.get_expr(False) + expr =3D self.get_expr() + if not isinstance(expr, dict): + raise QAPISemError( + info, "top-level expression must be an object") + if 'include' in expr: self.reject_expr_doc(cur_doc) if len(expr) !=3D 1: @@ -251,7 +255,7 @@ def get_members(self): self.accept() if key in expr: raise QAPIParseError(self, "duplicate key '%s'" % key) - expr[key] =3D self.get_expr(True) + expr[key] =3D self.get_expr() if self.tok =3D=3D '}': self.accept() return expr @@ -270,7 +274,7 @@ def get_values(self): raise QAPIParseError( self, "expected '{', '[', ']', string, or boolean") while True: - expr.append(self.get_expr(True)) + expr.append(self.get_expr()) if self.tok =3D=3D ']': self.accept() return expr @@ -278,9 +282,7 @@ def get_values(self): raise QAPIParseError(self, "expected ',' or ']'") self.accept() =20 - def get_expr(self, nested): - if self.tok !=3D '{' and not nested: - raise QAPIParseError(self, "expected '{'") + def get_expr(self): if self.tok =3D=3D '{': self.accept() expr =3D self.get_members() diff --git a/tests/qapi-schema/non-objects.err b/tests/qapi-schema/non-obje= cts.err index 3a4ea36966..23bdb69c71 100644 --- a/tests/qapi-schema/non-objects.err +++ b/tests/qapi-schema/non-objects.err @@ -1 +1 @@ -non-objects.json:1:1: expected '{' +non-objects.json:1: top-level expression must be an object diff --git a/tests/qapi-schema/quoted-structural-chars.err b/tests/qapi-sch= ema/quoted-structural-chars.err index 07d1561d1f..af6c1e173d 100644 --- a/tests/qapi-schema/quoted-structural-chars.err +++ b/tests/qapi-schema/quoted-structural-chars.err @@ -1 +1 @@ -quoted-structural-chars.json:1:1: expected '{' +quoted-structural-chars.json:1: top-level expression must be an object --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621533516; cv=none; d=zohomail.com; s=zohoarc; b=lQiNuhyCnqZVTgqzXEgyEjcrp/akboYHoiSLn6jib1Iw7gOTu28Ho83kIge+eMiO/S1AH2+AJxf8tfoZ+lmMAEZgP426FLEekCjrr1/j+VP+V5karDSgha9nQYRY2jJb2P6rK75blqWcaze8PreEWYrURoJ0zXA2a9T0g7A4l0I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621533516; 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=06ohp+Con83nXYQwjS6Htzm1dEFGIK0OvrkHpfyCXHs=; b=BfDCgUFCid5RobETucwDPd7UcaAcE0CJqpkG3IfVNx+JQGwikcxhJAcKjmXbmyHMMsiPerKEb1OswelDTMDLp/SOR7/xEZU69s3BatTfz7CPrA8LVwgfrQIaIK0skfTfLlctM/JdIC4ns1Aur8nnAf7lUk14Ly2yCDPAq+1gT08= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621533516016536.5698704927815; Thu, 20 May 2021 10:58:36 -0700 (PDT) Received: from localhost ([::1]:50668 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljmwN-0002qx-0q for importer2@patchew.org; Thu, 20 May 2021 13:58:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrQ-0002pP-GR for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:43286) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr1-0006ah-Av for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53: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-258-R2RHcfkTOCi7VKOYG3OVgw-1; Thu, 20 May 2021 13:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75718107ACED; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4041419C59; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 4E5CB1132FD3; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533182; 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=06ohp+Con83nXYQwjS6Htzm1dEFGIK0OvrkHpfyCXHs=; b=hEEtd6Kz5owdui1Y5Nq+6srkATRXS5nzHV4OfyDAXEMcfOVhIlchLnkAb63b1ib+z0LNZH r5gk99Y/71HkdqzvY8b3QyqeadisRGoYIAdbp91hvcnjwFdkezYu3rEnuQ0A1lSMVxVxrs DbhDRw8llqHcoTmU0BBI3602ZZAm98o= X-MC-Unique: R2RHcfkTOCi7VKOYG3OVgw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 07/15] qapi/parser: assert object keys are strings Date: Thu, 20 May 2021 19:52:48 +0200 Message-Id: <20210520175256.1119684-8-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow The single quote token implies the value is a string. Assert this to be the case, to allow us to write an accurate return type for get_members. Signed-off-by: John Snow Message-Id: <20210519183951.3946870-8-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index ffdd4298b6..4959630ce6 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -249,6 +249,8 @@ def get_members(self): raise QAPIParseError(self, "expected string or '}'") while True: key =3D self.val + assert isinstance(key, str) # Guaranteed by tok =3D=3D "'" + self.accept() if self.tok !=3D ':': raise QAPIParseError(self, "expected ':'") --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621534669; cv=none; d=zohomail.com; s=zohoarc; b=AbPAnsBMv0m9UUkEERvJl7qQTVREitUGV5upDPKeiBtjNIM9gYyFWyLZWV8DnsEUNJgtgTp2bCV1V4H2yGbYToKPev3QJC/0vVeFw4nYbd5G5m7vEWwk5q5rJmTEb9RZe74VZhGQqDlQbmiTXFSYzPuu+cJm2nZE92nCAfIR8Gw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621534669; 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=0C52TrnyhfAOaUUdChEgL2M/lmN0mybT/R1jeCqMkZY=; b=ChaAvf0b4QRT924yq5EgwF9ckdoHHDepyZQuvE5Gux5oyT6C5zRZUjD+y/aSRvXzblD82NUpFHonQ1c34okanfbXsmLkg3np6SmgOVVViSRayV5XhhNHV/T+OnXYtPJlxRkBgeZcGPAVQSq1VlJv5CpOihk+JnuFO5ZT6ziuHoc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621534669526448.24259680367743; Thu, 20 May 2021 11:17:49 -0700 (PDT) Received: from localhost ([::1]:58434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljnEy-0002Mm-Ft for importer2@patchew.org; Thu, 20 May 2021 14:17:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrS-0002pu-NE for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31199) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr1-0006ar-DX for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-DL7cz8s-MA-imBt6m77SDw-1; Thu, 20 May 2021 13:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 74802802B4F; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3EB1519CBE; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 51C281132E9A; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533182; 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=0C52TrnyhfAOaUUdChEgL2M/lmN0mybT/R1jeCqMkZY=; b=Up53N1gXWOR3l4KjMEZ3xYSjCNstolqNQGc5rE5SZJ0b7SNAYkPgLHY+4x6EQt7uIItvEt 2ZsZ0QHftTwNZH/khxpNmS7j6tnovz/q/wbm4gqgzaac/4MR3aniFXlHmHXJ+yga/MYCB1 S6RR5EiI8KPZvJtyEQekC0UH5fDpjc4= X-MC-Unique: DL7cz8s-MA-imBt6m77SDw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 08/15] qapi/parser: Use @staticmethod where appropriate Date: Thu, 20 May 2021 19:52:49 +0200 Message-Id: <20210520175256.1119684-9-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow No self, no thank you! (Quiets pylint warnings.) Signed-off-by: John Snow Message-Id: <20210519183951.3946870-9-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 4959630ce6..7c71866195 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -130,7 +130,8 @@ def reject_expr_doc(doc): "documentation for '%s' is not followed by the definition" % doc.symbol) =20 - def _include(self, include, info, incl_fname, previously_included): + @staticmethod + def _include(include, info, incl_fname, previously_included): incl_abs_fname =3D os.path.abspath(incl_fname) # catch inclusion cycle inf =3D info @@ -151,7 +152,8 @@ def _include(self, include, info, incl_fname, previousl= y_included): f"can't read include file '{incl_fname}': {err.strerror}" ) from err =20 - def _check_pragma_list_of_str(self, name, value, info): + @staticmethod + def _check_pragma_list_of_str(name, value, info): if (not isinstance(value, list) or any([not isinstance(elt, str) for elt in value])): raise QAPISemError( --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621533297; cv=none; d=zohomail.com; s=zohoarc; b=gJrMEnoBvVmTnl06W5Va7XGoiM0KzRkgYiBBajZFLebj8HSdo+7mugrtNa78Z9vB6tf3HtrSxJyGIRTpgiO9axcL5MJBAP2UGUYTuQ5oTkLfLqZXzR9Jjn3Jwb3v0UvEsYm+TcU+x1CxQ0077h1T2snvFHqfQx2q+fBRxGn1kso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621533297; 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=os7xo38UCBmwKhLI/0JiqPA9x0+dfdx06a5GGU04Az0=; b=QL8CRXmfaAHXjXHUjx1hgmzIn8kyB+mhi25L7ZLjIHpfqMh1oOLb9QoxvAAAVV9nCK3pN5HKUUWD/22tRCzo2zVV7ReX1qzMCQ6EVjjPGmdGHEf+j4HQVUbY8zY1D5Y3Dn4ttKnDNeWoptiDFj3fqlXYceIC623oQ7r4sveJv1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621533297744391.0991352980227; Thu, 20 May 2021 10:54:57 -0700 (PDT) Received: from localhost ([::1]:42396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljmsq-0005XA-Kz for importer2@patchew.org; Thu, 20 May 2021 13:54:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrF-0002ny-AQ for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23063) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr1-0006an-AP for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:11 -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-319-rTFWMTmfMp6n_Z0WWh1G4Q-1; Thu, 20 May 2021 13:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 91EC91926DA9; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F515610B0; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5521D1132EA4; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533182; 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=os7xo38UCBmwKhLI/0JiqPA9x0+dfdx06a5GGU04Az0=; b=CWOhsn3UPe+bBtZ7/MEgrN97eMZ3EGpeo7v4XRBFNODQANJaxBZSzSfthcHKZyNeizj3q3 hNyYLYr2o0u+NWUQHzvoloNbMVc8YVKZUExrE08bx9J4HqyfudFk/UnxL1zOCXcdquFhh8 2NDhtGvVaWHH4M3EoYY/aJotnAKjT9A= X-MC-Unique: rTFWMTmfMp6n_Z0WWh1G4Q-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 09/15] qapi: add must_match helper Date: Thu, 20 May 2021 19:52:50 +0200 Message-Id: <20210520175256.1119684-10-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Mypy cannot generally understand that these regex functions cannot possibly fail. Add a "must_match" helper that makes this clear for mypy. Signed-off-by: John Snow Message-Id: <20210519183951.3946870-10-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/common.py | 8 +++++++- scripts/qapi/main.py | 6 ++---- scripts/qapi/parser.py | 13 +++++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index cbd3fd81d3..6ad1eeb61d 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -12,7 +12,7 @@ # See the COPYING file in the top-level directory. =20 import re -from typing import Optional, Sequence +from typing import Match, Optional, Sequence =20 =20 #: Magic string that gets removed along with all space to its right. @@ -210,3 +210,9 @@ def gen_endif(ifcond: Sequence[str]) -> str: #endif /* %(cond)s */ ''', cond=3Difc) return ret + + +def must_match(pattern: str, string: str) -> Match[str]: + match =3D re.match(pattern, string) + assert match is not None + return match diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index 703e7ed1ed..f2ea6e0ce4 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -8,11 +8,11 @@ """ =20 import argparse -import re import sys from typing import Optional =20 from .commands import gen_commands +from .common import must_match from .error import QAPIError from .events import gen_events from .introspect import gen_introspect @@ -22,9 +22,7 @@ =20 =20 def invalid_prefix_char(prefix: str) -> Optional[str]: - match =3D re.match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', prefix) - # match cannot be None, but mypy cannot infer that. - assert match is not None + match =3D must_match(r'([A-Za-z_.-][A-Za-z0-9_.-]*)?', prefix) if match.end() !=3D len(prefix): return prefix[match.end()] return None diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 7c71866195..48137d3fbe 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -18,6 +18,7 @@ import os import re =20 +from .common import must_match from .error import QAPISemError, QAPISourceError from .source import QAPISourceInfo =20 @@ -238,8 +239,8 @@ def accept(self, skip_comment=3DTrue): elif not self.tok.isspace(): # Show up to next structural, whitespace or quote # character - match =3D re.match('[^[\\]{}:,\\s\'"]+', - self.src[self.cursor-1:]) + match =3D must_match('[^[\\]{}:,\\s\'"]+', + self.src[self.cursor-1:]) raise QAPIParseError(self, "stray '%s'" % match.group(0)) =20 def get_members(self): @@ -369,7 +370,7 @@ def append(self, line): # Strip leading spaces corresponding to the expected indent le= vel # Blank lines are always OK. if line: - indent =3D re.match(r'\s*', line).end() + indent =3D must_match(r'\s*', line).end() if indent < self._indent: raise QAPIParseError( self._parser, @@ -505,7 +506,7 @@ def _append_args_line(self, line): # from line and replace it with spaces so that 'f' has the # same index as it did in the original line and can be # handled the same way we will handle following lines. - indent =3D re.match(r'@\S*:\s*', line).end() + indent =3D must_match(r'@\S*:\s*', line).end() line =3D line[indent:] if not line: # Line was just the "@arg:" header; following lines @@ -540,7 +541,7 @@ def _append_features_line(self, line): # from line and replace it with spaces so that 'f' has the # same index as it did in the original line and can be # handled the same way we will handle following lines. - indent =3D re.match(r'@\S*:\s*', line).end() + indent =3D must_match(r'@\S*:\s*', line).end() line =3D line[indent:] if not line: # Line was just the "@arg:" header; following lines @@ -586,7 +587,7 @@ def _append_various_line(self, line): # from line and replace it with spaces so that 'f' has the # same index as it did in the original line and can be # handled the same way we will handle following lines. - indent =3D re.match(r'\S*:\s*', line).end() + indent =3D must_match(r'\S*:\s*', line).end() line =3D line[indent:] if not line: # Line was just the "Section:" header; following lines --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621533958; cv=none; d=zohomail.com; s=zohoarc; b=CEQ6zW5kC9x27/20w3OLwrvfdBcSXKggrmP31ZPiIevOAhunS8LHlfYir+ExFAqfJhNAYVOBLx5Y+C5hc/0/35ttPwR0c9wQpOLx4ohb3DfXCEINKbZIWRn7vGk+voG/G1NjNCLSh0YcAAPWkRGPbK18jK7SA45Z1ozVI3O5ftw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621533958; 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=zrqb7lw2bTq/g8wW4I8g/x/t5ncK2P3WOmeOOeb2bzo=; b=i2vp3mb2cdTDt4aA8MClOAof7H5Pstr1O5IGSLd9gA6ScMn2aonp/LVk7IJhSjVgliFl6xW+c6oNrU7MFfd3rymhcXTt+uOmnoTnR2grFtXH49yNM+6EMO2ku2k2jb11ISNZKyDI4FoJsjZ8u0XJ+Kui7SnVuW6YDsh8DTOpiSU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621533958418975.8073299404871; Thu, 20 May 2021 11:05:58 -0700 (PDT) Received: from localhost ([::1]:41010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljn3V-0007IH-Aq for importer2@patchew.org; Thu, 20 May 2021 14:05:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56176) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrF-0002nx-AW for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr1-0006ag-66 for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:13 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-442-EKMvtytvM7ePyVlfPNn6ew-1; Thu, 20 May 2021 13:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90923107ACF3; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F6255C261; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5872E1132D67; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533182; 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=zrqb7lw2bTq/g8wW4I8g/x/t5ncK2P3WOmeOOeb2bzo=; b=T8/wooEEL8bXYUopfSorQ4ExXiuTQqvJ0r5XDoGfxdBI15CYUZLOFx50X5AuwzzkorhlyK G9QcOoCyBJHzDMrjIxQqm3xxS11Uux7VfVlyQ6ymAVmr2RXSVWDsFQn46z+E747eH0Rv0h qPepxk+2cylD1wa6G69hvml3JHsvdO8= X-MC-Unique: EKMvtytvM7ePyVlfPNn6ew-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 10/15] qapi/parser: Fix token membership tests when token can be None Date: Thu, 20 May 2021 19:52:51 +0200 Message-Id: <20210520175256.1119684-11-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow When the token can be None (EOF), we can't use 'x in "abc"' style membership tests to group types of tokens together, because 'None in "abc"' is a TypeError. Easy enough to fix. (Use a tuple: It's neither a static typing error nor a runtime error to check for None in Tuple[str, ...]) Add tests to prevent a regression. (Note: they cannot be added prior to this fix, as the unhandled stack trace will not match test output in the CI system.) Signed-off-by: John Snow Message-Id: <20210519183951.3946870-11-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 5 +++-- tests/qapi-schema/meson.build | 2 ++ tests/qapi-schema/missing-array-rsqb.err | 1 + tests/qapi-schema/missing-array-rsqb.json | 1 + tests/qapi-schema/missing-array-rsqb.out | 0 tests/qapi-schema/missing-object-member-element.err | 1 + tests/qapi-schema/missing-object-member-element.json | 1 + tests/qapi-schema/missing-object-member-element.out | 0 8 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tests/qapi-schema/missing-array-rsqb.err create mode 100644 tests/qapi-schema/missing-array-rsqb.json create mode 100644 tests/qapi-schema/missing-array-rsqb.out create mode 100644 tests/qapi-schema/missing-object-member-element.err create mode 100644 tests/qapi-schema/missing-object-member-element.json create mode 100644 tests/qapi-schema/missing-object-member-element.out diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 48137d3fbe..9f980f7513 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -275,7 +275,7 @@ def get_values(self): if self.tok =3D=3D ']': self.accept() return expr - if self.tok not in "{['tf": + if self.tok not in tuple("{['tf"): raise QAPIParseError( self, "expected '{', '[', ']', string, or boolean") while True: @@ -294,7 +294,8 @@ def get_expr(self): elif self.tok =3D=3D '[': self.accept() expr =3D self.get_values() - elif self.tok in "'tf": + elif self.tok in tuple("'tf"): + assert isinstance(self.val, (str, bool)) expr =3D self.val self.accept() else: diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index dc448e8f74..9e8f658ce3 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -134,9 +134,11 @@ schemas =3D [ 'indented-expr.json', 'leading-comma-list.json', 'leading-comma-object.json', + 'missing-array-rsqb.json', 'missing-colon.json', 'missing-comma-list.json', 'missing-comma-object.json', + 'missing-object-member-element.json', 'missing-type.json', 'nested-struct-data.json', 'nested-struct-data-invalid-dict.json', diff --git a/tests/qapi-schema/missing-array-rsqb.err b/tests/qapi-schema/m= issing-array-rsqb.err new file mode 100644 index 0000000000..b5f58b8c12 --- /dev/null +++ b/tests/qapi-schema/missing-array-rsqb.err @@ -0,0 +1 @@ +missing-array-rsqb.json:1:44: expected '{', '[', string, or boolean diff --git a/tests/qapi-schema/missing-array-rsqb.json b/tests/qapi-schema/= missing-array-rsqb.json new file mode 100644 index 0000000000..7fca1df923 --- /dev/null +++ b/tests/qapi-schema/missing-array-rsqb.json @@ -0,0 +1 @@ +['Daisy,', 'Daisy,', 'Give me your answer', diff --git a/tests/qapi-schema/missing-array-rsqb.out b/tests/qapi-schema/m= issing-array-rsqb.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/missing-object-member-element.err b/tests/qa= pi-schema/missing-object-member-element.err new file mode 100644 index 0000000000..c08a3dc307 --- /dev/null +++ b/tests/qapi-schema/missing-object-member-element.err @@ -0,0 +1 @@ +missing-object-member-element.json:1:8: expected '{', '[', string, or bool= ean diff --git a/tests/qapi-schema/missing-object-member-element.json b/tests/q= api-schema/missing-object-member-element.json new file mode 100644 index 0000000000..f52d0106f3 --- /dev/null +++ b/tests/qapi-schema/missing-object-member-element.json @@ -0,0 +1 @@ +{'key': diff --git a/tests/qapi-schema/missing-object-member-element.out b/tests/qa= pi-schema/missing-object-member-element.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621534419; cv=none; d=zohomail.com; s=zohoarc; b=OWBv+lc8MHfpqYpiKxAgwFhdL2AL4H8GCu5ee9xY1WZnp86nEUJChZp31uG7B3yy6xaslqSDo7/AbPgi0a+QtytoUhGwzsxoJGx4lKY68x+IJlnnAJ5pmYIxnKfz3xRrwnq82/5Xj55AmZpSfhIoL3H5CBhKRLrmFvCnwoKh1cQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621534419; 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=hwtjx5OUopMjJQeTcMhySgii1zl3rOiyfCnfBv7eSNE=; b=NLh6T4Op0qrNMYXVxpRgxLbOEakkoARP9K0YBw0OI6aTg9j+cv5WWmaKAz8u2S4rF46TwFAKp1EWKo++fS7v20GlqwKaatJbiyp+Dh2VdlTVX10MGHPwrvuHVnSoZJchsm3q7eIEdGnZT7EjWZCnb/GQ3KVPUD3C3vS2uD1jwlY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621534419297920.690381657377; Thu, 20 May 2021 11:13:39 -0700 (PDT) Received: from localhost ([::1]:53958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljnAu-0007l4-9B for importer2@patchew.org; Thu, 20 May 2021 14:13:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrJ-0002oZ-5B for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24278) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr1-0006aZ-3f for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:16 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-442-K3pIQRg-M6OYPpd0inoLvA-1; Thu, 20 May 2021 13:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 748C2107ACC7; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E28236D5; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5BE081132CB1; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533182; 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=hwtjx5OUopMjJQeTcMhySgii1zl3rOiyfCnfBv7eSNE=; b=R2kfXyNYwS0zyvogIy7kdkoRDthNgAqI5UnO+jKM5oiPBF7SCoFoUPW39PxL9JsFfThwI4 GvSFrOL1cCy6WkF/7jSAjsL2zNGMtWid1S8KlXGFO1iWIyYqX5N5QFANbYbqv2+1Xvp6TL kSS2n65dmiphyAeR9kgeRfKV1oQiLac= X-MC-Unique: K3pIQRg-M6OYPpd0inoLvA-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 11/15] qapi/parser: Rework _check_pragma_list_of_str as a TypeGuard Date: Thu, 20 May 2021 19:52:52 +0200 Message-Id: <20210520175256.1119684-12-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow TypeGuards wont exist in Python proper until 3.10. Ah well. We can hack up our own by declaring this function to return the type we claim it checks for and using this to safely downcast object -> List[str]. In so doing, I bring this function under _pragma so it can use the 'info' object in its closure. Having done this, _pragma also now no longer needs to take a 'self' parameter, so drop it. To help with line-length, and with the context evident from its new scope, rename the function to the shorter check_list_str(). Signed-off-by: John Snow Message-Id: <20210519183951.3946870-12-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 9f980f7513..8a58e1228f 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -17,6 +17,7 @@ from collections import OrderedDict import os import re +from typing import List =20 from .common import must_match from .error import QAPISemError, QAPISourceError @@ -154,28 +155,29 @@ def _include(include, info, incl_fname, previously_in= cluded): ) from err =20 @staticmethod - def _check_pragma_list_of_str(name, value, info): - if (not isinstance(value, list) - or any([not isinstance(elt, str) for elt in value])): - raise QAPISemError( - info, - "pragma %s must be a list of strings" % name) + def _pragma(name, value, info): + + def check_list_str(name, value) -> List[str]: + if (not isinstance(value, list) or + any([not isinstance(elt, str) for elt in value])): + raise QAPISemError( + info, + "pragma %s must be a list of strings" % name) + return value + + pragma =3D info.pragma =20 - def _pragma(self, name, value, info): if name =3D=3D 'doc-required': if not isinstance(value, bool): raise QAPISemError(info, "pragma 'doc-required' must be boolean") - info.pragma.doc_required =3D value + pragma.doc_required =3D value elif name =3D=3D 'command-name-exceptions': - self._check_pragma_list_of_str(name, value, info) - info.pragma.command_name_exceptions =3D value + pragma.command_name_exceptions =3D check_list_str(name, value) elif name =3D=3D 'command-returns-exceptions': - self._check_pragma_list_of_str(name, value, info) - info.pragma.command_returns_exceptions =3D value + pragma.command_returns_exceptions =3D check_list_str(name, val= ue) elif name =3D=3D 'member-name-exceptions': - self._check_pragma_list_of_str(name, value, info) - info.pragma.member_name_exceptions =3D value + pragma.member_name_exceptions =3D check_list_str(name, value) else: raise QAPISemError(info, "unknown pragma '%s'" % name) =20 --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621533933; cv=none; d=zohomail.com; s=zohoarc; b=cyIFstI1uEbVs5m0VW/shuU98J8p/pJXqtHQeZ+Ly3qLJdyfBCEJwFfIliK9dtkzPwL+Qw7M3J0Ol71JlL4XKExfp3h9e/KE1f9sdk5HJCEyhPMZ9x1vtBS78znruDASk8RBUCJgLZXvF8g8YMmh4jqpU9fgoxHDqgbtnCnt79w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621533933; 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=g9wP+baT2byIg48eexoBT2PZEMW3ivRwuxw61478WG8=; b=h5vA9OQNvfJNdz1Gd872vxY73cRLrr0L7K+tDfCFMH5R2LjrZ+pXeHsiQW/3u3RJXP5YYXp6w4v9/VEpwvlC3thMHw1LSMYQyfMsGP6kVQ3Qni61UQ9/dJ7SibDi7PK9S6yOijNHqkix8t4aDib2ElM9r+wzG7cXmaHjMv6VFck= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 162153393327741.425662022397546; Thu, 20 May 2021 11:05:33 -0700 (PDT) Received: from localhost ([::1]:38732 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljn36-0005hh-4x for importer2@patchew.org; Thu, 20 May 2021 14:05:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrX-0002s0-D2 for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35869) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr3-0006c8-DS for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:28 -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-369-FnjvCFkmPAamS4RntFiv4g-1; Thu, 20 May 2021 13:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9335A8030A0; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 404AA385; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5F86411329AC; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533183; 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=g9wP+baT2byIg48eexoBT2PZEMW3ivRwuxw61478WG8=; b=aAeKWrej4VzJHBsPMdyITy2hpFkTaH0BHgt4kv6vfbDQAN649op0XkxmO5vE1qu75Dp+E3 n6Jn9g0dLycQN2EMRGpGwz/y0jGsR67k37Ka4hIQaTWsOBqwHH/E8wkWqgPK/GepOIRvC2 nbcQdFdKsuNWobyeUIS2o9InDuGVlKs= X-MC-Unique: FnjvCFkmPAamS4RntFiv4g-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 12/15] qapi/parser: add type hint annotations Date: Thu, 20 May 2021 19:52:53 +0200 Message-Id: <20210520175256.1119684-13-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Annotations do not change runtime behavior. This commit *only* adds annotations. (Annotations for QAPIDoc are in a forthcoming commit.) Signed-off-by: John Snow Message-Id: <20210519183951.3946870-13-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 58 +++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 8a58e1228f..419e36c870 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -17,16 +17,26 @@ from collections import OrderedDict import os import re -from typing import List +from typing import ( + Dict, + List, + Optional, + Set, + Union, +) =20 from .common import must_match from .error import QAPISemError, QAPISourceError from .source import QAPISourceInfo =20 =20 +# Return value alias for get_expr(). +_ExprValue =3D Union[List[object], Dict[str, object], str, bool] + + class QAPIParseError(QAPISourceError): """Error class for all QAPI schema parsing errors.""" - def __init__(self, parser, msg): + def __init__(self, parser: 'QAPISchemaParser', msg: str): col =3D 1 for ch in parser.src[parser.line_pos:parser.pos]: if ch =3D=3D '\t': @@ -38,7 +48,10 @@ def __init__(self, parser, msg): =20 class QAPISchemaParser: =20 - def __init__(self, fname, previously_included=3DNone, incl_info=3DNone= ): + def __init__(self, + fname: str, + previously_included: Optional[Set[str]] =3D None, + incl_info: Optional[QAPISourceInfo] =3D None): self._fname =3D fname self._included =3D previously_included or set() self._included.add(os.path.abspath(self._fname)) @@ -46,20 +59,20 @@ def __init__(self, fname, previously_included=3DNone, i= ncl_info=3DNone): =20 # Lexer state (see `accept` for details): self.info =3D QAPISourceInfo(self._fname, incl_info) - self.tok =3D None + self.tok: Union[None, str] =3D None self.pos =3D 0 self.cursor =3D 0 - self.val =3D None + self.val: Optional[Union[bool, str]] =3D None self.line_pos =3D 0 =20 # Parser output: - self.exprs =3D [] - self.docs =3D [] + self.exprs: List[Dict[str, object]] =3D [] + self.docs: List[QAPIDoc] =3D [] =20 # Showtime! self._parse() =20 - def _parse(self): + def _parse(self) -> None: cur_doc =3D None =20 # May raise OSError; allow the caller to handle it. @@ -125,7 +138,7 @@ def _parse(self): self.reject_expr_doc(cur_doc) =20 @staticmethod - def reject_expr_doc(doc): + def reject_expr_doc(doc: Optional['QAPIDoc']) -> None: if doc and doc.symbol: raise QAPISemError( doc.info, @@ -133,10 +146,14 @@ def reject_expr_doc(doc): % doc.symbol) =20 @staticmethod - def _include(include, info, incl_fname, previously_included): + def _include(include: str, + info: QAPISourceInfo, + incl_fname: str, + previously_included: Set[str] + ) -> Optional['QAPISchemaParser']: incl_abs_fname =3D os.path.abspath(incl_fname) # catch inclusion cycle - inf =3D info + inf: Optional[QAPISourceInfo] =3D info while inf: if incl_abs_fname =3D=3D os.path.abspath(inf.fname): raise QAPISemError(info, "inclusion loop for %s" % include) @@ -155,9 +172,9 @@ def _include(include, info, incl_fname, previously_incl= uded): ) from err =20 @staticmethod - def _pragma(name, value, info): + def _pragma(name: str, value: object, info: QAPISourceInfo) -> None: =20 - def check_list_str(name, value) -> List[str]: + def check_list_str(name: str, value: object) -> List[str]: if (not isinstance(value, list) or any([not isinstance(elt, str) for elt in value])): raise QAPISemError( @@ -181,7 +198,7 @@ def check_list_str(name, value) -> List[str]: else: raise QAPISemError(info, "unknown pragma '%s'" % name) =20 - def accept(self, skip_comment=3DTrue): + def accept(self, skip_comment: bool =3D True) -> None: while True: self.tok =3D self.src[self.cursor] self.pos =3D self.cursor @@ -245,8 +262,8 @@ def accept(self, skip_comment=3DTrue): self.src[self.cursor-1:]) raise QAPIParseError(self, "stray '%s'" % match.group(0)) =20 - def get_members(self): - expr =3D OrderedDict() + def get_members(self) -> Dict[str, object]: + expr: Dict[str, object] =3D OrderedDict() if self.tok =3D=3D '}': self.accept() return expr @@ -272,8 +289,8 @@ def get_members(self): if self.tok !=3D "'": raise QAPIParseError(self, "expected string") =20 - def get_values(self): - expr =3D [] + def get_values(self) -> List[object]: + expr: List[object] =3D [] if self.tok =3D=3D ']': self.accept() return expr @@ -289,7 +306,8 @@ def get_values(self): raise QAPIParseError(self, "expected ',' or ']'") self.accept() =20 - def get_expr(self): + def get_expr(self) -> _ExprValue: + expr: _ExprValue if self.tok =3D=3D '{': self.accept() expr =3D self.get_members() @@ -305,7 +323,7 @@ def get_expr(self): self, "expected '{', '[', string, or boolean") return expr =20 - def get_doc(self, info): + def get_doc(self, info: QAPISourceInfo) -> List['QAPIDoc']: if self.val !=3D '##': raise QAPIParseError( self, "junk after '##' at start of documentation comment") --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621533767; cv=none; d=zohomail.com; s=zohoarc; b=dZOJJAzTR8Zq2jzRJz0DCtn/K7NLLa8g3pewjrdmzY9xOURM8991hImQ0GfWScgxlqoYuTCSM9RH4cfHDGgs0+wSHiwd2hoq9wuSEBtnhGQoAfSuNtGJyVeVt/7U+zHdmaTTnJ+8XlYiU1wd42ZFqgDNGH0VarfXgwDmZMNsq0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621533767; 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=nHy31fW9dae76RZ2ijQDRtQLmSAbZhGMZZ1drMbee+4=; b=fI2oQDnOnI9ii0ViNZtsgq9aXWkYkMWQpbfbGd5BpfC9K5TgwJilQkAoH1zmGGMy5R04FdLUW0I7E+e0XlJYhflXnG3HQdQ1omF6+5ac4441nj6HqSx88uEYVgMRrw/vYL0O0O35Gth2GW1eKDIPI2QI5505+MM3yW6esybNRLw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621533767290963.6903455473455; Thu, 20 May 2021 11:02:47 -0700 (PDT) Received: from localhost ([::1]:33816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljn0Q-0002MD-7u for importer2@patchew.org; Thu, 20 May 2021 14:02:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56308) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrX-0002s4-Fq for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51296) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr3-0006d4-Dj for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:33 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-339-KRrMcoxAMIO-0LITzDf8ng-1; Thu, 20 May 2021 13:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 735351007B02; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F8D35DDAD; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 62FA311329B3; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533184; 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=nHy31fW9dae76RZ2ijQDRtQLmSAbZhGMZZ1drMbee+4=; b=eF8uWLwU8VjdIcy3EnZQWNM/vmr3+nB+soDvHWtL7r651OMMr51kgzcaxDv417stxAYQB1 vOd19wCzUwqj//zBg44/6KnLWu2OaYMmIX+wzDltePDLYGMeuEIc9ox/rM3om6StjP8Mm4 XGs4RIrD4hrP6nFm/RBQqAEmLSAMfuA= X-MC-Unique: KRrMcoxAMIO-0LITzDf8ng-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 13/15] qapi/parser: Remove superfluous list comprehension Date: Thu, 20 May 2021 19:52:54 +0200 Message-Id: <20210520175256.1119684-14-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow A generator suffices (and quiets a pylint warning). Signed-off-by: John Snow Message-Id: <20210519183951.3946870-14-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 419e36c870..b0f18c0d17 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -176,7 +176,7 @@ def _pragma(name: str, value: object, info: QAPISourceI= nfo) -> None: =20 def check_list_str(name: str, value: object) -> List[str]: if (not isinstance(value, list) or - any([not isinstance(elt, str) for elt in value])): + any(not isinstance(elt, str) for elt in value)): raise QAPISemError( info, "pragma %s must be a list of strings" % name) --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621533737; cv=none; d=zohomail.com; s=zohoarc; b=U8FQYCgd7VffN5PIkWbaD4C2YJ0IktMfYBnDVXAmV0G8lwP29kp9aSNzFCT7uhZL5h0pOi3hP/rTYA1nH6vSy7uoiHuaJyp1ZnAltJM/SSKSt+ou+lttbMwIATEMI3JOtPk56jitGeqGmcpA/VBi7DBXTwcNjOIW88k9OT9tuak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621533737; 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=bdmqn0N8uzm2FKv+U9S5FX5fDeNnNRE512vUe599u2g=; b=NPGa96rneBZD/4l5ippTEYjMTprJKn5450twY3HPRK2QcGxww3piGbfyShFYyiju6jEfXNi7QNuk3ZOW+57Vod5CpFzJqHMgt/YmUPL5BOjNqmv6GND/AViZaeCbBCs+FBaJnZ7Rdr8vC7sinS2xQbwACSLXZ6RaUJGaOMDVOHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621533737850990.9221740566292; Thu, 20 May 2021 11:02:17 -0700 (PDT) Received: from localhost ([::1]:59350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljmzw-0000Nb-LT for importer2@patchew.org; Thu, 20 May 2021 14:02:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrX-0002s5-GZ for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr3-0006dF-EM for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:31 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-UsM-zI6pNdioDNkHBjqOjQ-1; Thu, 20 May 2021 13:53:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 749C4801B13; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E6BB299C4; Thu, 20 May 2021 17:52:59 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 665F511329BE; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533184; 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=bdmqn0N8uzm2FKv+U9S5FX5fDeNnNRE512vUe599u2g=; b=T2tPjyIaSBNo3XoWkrjKwW03ckemWt9OPSCFJ9uZShyA+dn9kRZEP811akORXhxq9CNU7w bFKebfJ1xBF2t5W62XytC9YGG8o6hVZj8KZTnfWwCY5mKqmIxTUMxjIDEbDAMmRqcfNUlY +lS6YsH6t3zXiiOGyWa+eGzyKU/3fTY= X-MC-Unique: UsM-zI6pNdioDNkHBjqOjQ-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 14/15] qapi/parser: allow 'ch' variable name Date: Thu, 20 May 2021 19:52:55 +0200 Message-Id: <20210520175256.1119684-15-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow We can have a two-letter variable name, as a treat. Signed-off-by: John Snow Message-Id: <20210519183951.3946870-15-jsnow@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Markus Armbruster --- scripts/qapi/pylintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index 88efbf71cb..c5275d5f59 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -43,6 +43,7 @@ good-names=3Di, _, fp, # fp =3D open(...) fd, # fd =3D os.open(...) + ch, =20 [VARIABLES] =20 --=20 2.26.3 From nobody Fri May 3 06:50:48 2024 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1621533737; cv=none; d=zohomail.com; s=zohoarc; b=i/MIfYs56WNNJYV/6oZoY8y0XSH6r25eXjwZ34bzFlIsT6ai0XOe17w1S4v3mjWzKpBv1Ovoya5h0+hsWNtfR7+pSO893iKUcf8j25dn/klgk6mQJU3qhlpEfdOTcCtK8sDHj91W4rG6LBA+H33d5BYGmqiGr1GwJJgWpDoSBmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621533737; 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=dYC3Y2MQb8D/rZywfCIDucYCueVHKE+1f9M2XkMhdSk=; b=i0ZPUBWvZecJpxrY1L0nkUYF+pO4anDN4I+hWzAZogvjK4sK8ijCLGpBwu2vE9cLMTI3SQggmLwFE6Zja23xthXOutkcQ4robSoKyW2YqB8lJgBBpzHM0KgvEBbtPiosrY6mlhLFmTw7ubDIzaZfArypkIwPkwreaa8aLywvxcI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass 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 1621533737598553.8055554313008; Thu, 20 May 2021 11:02:17 -0700 (PDT) Received: from localhost ([::1]:59308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljmzw-0000LM-8t for importer2@patchew.org; Thu, 20 May 2021 14:02:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmrU-0002q8-2J for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:23909) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljmr3-0006bO-8i for qemu-devel@nongnu.org; Thu, 20 May 2021 13:53:27 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-102-VzZHqvXWPJ6rh8VE1u1_7g-1; Thu, 20 May 2021 13:53:01 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C98F01926DA3; Thu, 20 May 2021 17:53:00 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-114-17.ams2.redhat.com [10.36.114.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A81A19C59; Thu, 20 May 2021 17:53:00 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 69DFD1132922; Thu, 20 May 2021 19:52:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621533183; 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=dYC3Y2MQb8D/rZywfCIDucYCueVHKE+1f9M2XkMhdSk=; b=Qkf6ObgxdB1Sitet9n/hUxgs+W7Gl+jKyfYDN7bJOvFvoufsjUw2Qw7xUaJpO5EZM8QENQ xEJ24Gp6WDcBHXGlN7/sgyqs9/KXOhmdAWfHgn4ZPmrphKGErCUmeaX8qjH7uuy9ZnyiPa eiNH/accf0BNq2rS9wEpaOiYX8rbhMg= X-MC-Unique: VzZHqvXWPJ6rh8VE1u1_7g-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 15/15] qapi/parser: add docstrings Date: Thu, 20 May 2021 19:52:56 +0200 Message-Id: <20210520175256.1119684-16-armbru@redhat.com> In-Reply-To: <20210520175256.1119684-1-armbru@redhat.com> References: <20210520175256.1119684-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.39, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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@linaro.org, John Snow Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: John Snow Signed-off-by: John Snow Message-Id: <20210519183951.3946870-16-jsnow@redhat.com> Reviewed-by: Markus Armbruster [Doc string spacing tweaked slightly] Signed-off-by: Markus Armbruster --- scripts/qapi/parser.py | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index b0f18c0d17..f03ba2cfec 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -47,7 +47,27 @@ def __init__(self, parser: 'QAPISchemaParser', msg: str): =20 =20 class QAPISchemaParser: + """ + Parse QAPI schema source. =20 + Parse a JSON-esque schema file and process directives. See + qapi-code-gen.txt section "Schema Syntax" for the exact syntax. + Grammatical validation is handled later by `expr.check_exprs()`. + + :param fname: Source file name. + :param previously_included: + The absolute names of previously included source files, + if being invoked from another parser. + :param incl_info: + `QAPISourceInfo` belonging to the parent module. + ``None`` implies this is the root module. + + :ivar exprs: Resulting parsed expressions. + :ivar docs: Resulting parsed documentation blocks. + + :raise OSError: For problems reading the root schema document. + :raise QAPIError: For errors in the schema source. + """ def __init__(self, fname: str, previously_included: Optional[Set[str]] =3D None, @@ -73,6 +93,11 @@ def __init__(self, self._parse() =20 def _parse(self) -> None: + """ + Parse the QAPI schema document. + + :return: None. Results are stored in ``.exprs`` and ``.docs``. + """ cur_doc =3D None =20 # May raise OSError; allow the caller to handle it. @@ -199,6 +224,50 @@ def check_list_str(name: str, value: object) -> List[s= tr]: raise QAPISemError(info, "unknown pragma '%s'" % name) =20 def accept(self, skip_comment: bool =3D True) -> None: + """ + Read and store the next token. + + :param skip_comment: + When false, return COMMENT tokens ("#"). + This is used when reading documentation blocks. + + :return: + None. Several instance attributes are updated instead: + + - ``.tok`` represents the token type. See below for values. + - ``.info`` describes the token's source location. + - ``.val`` is the token's value, if any. See below. + - ``.pos`` is the buffer index of the first character of + the token. + + * Single-character tokens: + + These are "{", "}", ":", ",", "[", and "]". + ``.tok`` holds the single character and ``.val`` is None. + + * Multi-character tokens: + + * COMMENT: + + This token is not normally returned by the lexer, but it can + be when ``skip_comment`` is False. ``.tok`` is "#", and + ``.val`` is a string including all chars until end-of-line, + including the "#" itself. + + * STRING: + + ``.tok`` is "'", the single quote. ``.val`` contains the + string, excluding the surrounding quotes. + + * TRUE and FALSE: + + ``.tok`` is either "t" or "f", ``.val`` will be the + corresponding bool value. + + * EOF: + + ``.tok`` and ``.val`` will both be None at EOF. + """ while True: self.tok =3D self.src[self.cursor] self.pos =3D self.cursor --=20 2.26.3