From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616652446; cv=none; d=zohomail.com; s=zohoarc; b=dBp/6UcAAavmYTsbDaY4A6Tvg1wCYPEmkJajhZp4wKm/u6HqqjPeIBUzyHi8UM/srZi4gxWOUiU7/f9cK2SeEI+RU/Di+qav1hOkb+96EwrEnmKn8rpHxC/ejQI1KpQrZUoj5W37PeE1f2Nd3LOH2x6fLrfM/mLRhoJlB/QGqjU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616652446; 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=7W4yf5T+oeaYa8VypARThBhSOPBSTqOKs0QIY3adB4Y=; b=ZCbPGAJsH6iQ0bcI0ADHVRZQHm72Y1UGgOq8Zq9BeU2WW8DEfbb7kosiH7CwNqjP9niazCM0J/2RXhHP8lBcKbrhuqc/pZRVVtN8Z5QZTY/fOOaBxLCAiLbXJ4k034+sVrjiROJQESumHEN7bZhxiExVBTMoZK6Hhr8jfDW3ZRA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616652446437363.80917577844434; Wed, 24 Mar 2021 23:07:26 -0700 (PDT) Received: from localhost ([::1]:33468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJ9Q-0003e0-AH for importer@patchew.org; Thu, 25 Mar 2021 02:07:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6E-00022a-EZ for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35561) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6B-0008K3-No for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:05 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-419-zPnQ0Q6AOYmwVpEFolBOVg-1; Thu, 25 Mar 2021 02:04: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 E24B157054; Thu, 25 Mar 2021 06:03:58 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 35A3C866C7; Thu, 25 Mar 2021 06:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652242; 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=7W4yf5T+oeaYa8VypARThBhSOPBSTqOKs0QIY3adB4Y=; b=ezJO2jGkJ3TllwdbZjCUrhQzpe3oYwb/IA0UpOt80GmWEF0K9rbW+p+TWWzyzeaHOIcqgL cP0aOTnSyRhCZ5uuito/jxJPHHGNQUUSoW3P4ASglrZk9Ug/Ru4QAJzFsV1OIkNCpyPIux CrBX4OmQpPeUyjNl1pOmle5+gpyCUsQ= X-MC-Unique: zPnQ0Q6AOYmwVpEFolBOVg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 01/19] qapi/expr: Comment cleanup Date: Thu, 25 Mar 2021 02:03:38 -0400 Message-Id: <20210325060356.4040114-2-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Fixes: 0825f62c842 Signed-off-by: John Snow --- scripts/qapi/expr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 540b3982b1..c207481f7e 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -241,7 +241,7 @@ def check_enum(expr, info): source =3D "%s '%s'" % (source, member_name) # Enum members may start with a digit if member_name[0].isdigit(): - member_name =3D 'd' + member_name # Hack: hide the digit + member_name =3D 'd' + member_name # Hack: hide the digit check_name_lower(member_name, info, source, permit_upper=3Dpermissive, permit_underscore=3Dpermissive) --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616652730; cv=none; d=zohomail.com; s=zohoarc; b=jHprT/wNzBmyPsJay5paXyJmX1eI9XUcRa1qj4kRZrIbW2h+8/QapIgrN+v1FbFJOJhHK2JsqyCtjUjclNhKOK/u9Lzk7cv1M7JA5hfNh31kEj82l+FUZg0j/VCr7Eb+cXAgQz+yoi1YWjBbXg7rB+uYrniyh1nn8DMQN3Ni940= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616652730; 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=Fm4JAmHSZoelC8dOMDZzC9eOtxUxAJqYbsrxRdaNRA8=; b=LB1Na9yH30ZiNH+2ktfZfXXMZgs+K8ntvhApzU243NR1omEFrirHwccnJeT8KX/QcnzjuqLsoB3M+yNRaWvYDvhsGqGlidx+Nsl0w+Vx+YnCEkhd6nhWd0W0bx/y9MuVtzqLTJe8yThCnXSJIkwvOaXUhHhI1/mcg27mFNT7WMU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616652730237904.5497940785291; Wed, 24 Mar 2021 23:12:10 -0700 (PDT) Received: from localhost ([::1]:41896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJE1-0007Bw-EY for importer@patchew.org; Thu, 25 Mar 2021 02:12:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39802) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6G-000236-Nu for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22025) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6E-0008MK-Ay for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:08 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-595-qHvZa1lWNByh65ntZpZ_Aw-1; Thu, 25 Mar 2021 02:04: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 A8A4E190B2A1; Thu, 25 Mar 2021 06:03:59 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F39F866C7; Thu, 25 Mar 2021 06:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652245; 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=Fm4JAmHSZoelC8dOMDZzC9eOtxUxAJqYbsrxRdaNRA8=; b=fwW2g1u+oQFQ/ibqsUEZ2goHKZVb/dci3qJMg+zTRDNFP0sF0I96QDUOjggD6enduc+iJT zxokvgrAx74kRusHWQ1wHB10fR0XW2p149D3pjWKySo4AcEJmcMkG8MxJqMso3HEJJ//gk 08bHXc+JJ+/alg3yZdTKMej+/mzYDmU= X-MC-Unique: qHvZa1lWNByh65ntZpZ_Aw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 02/19] flake8: Enforce shorter line length for comments and docstrings Date: Thu, 25 Mar 2021 02:03:39 -0400 Message-Id: <20210325060356.4040114-3-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" PEP8's BDFL writes: "For flowing long blocks of text with fewer structural restrictions (docstrings or comments), the line length should be limited to 72 characters." I do not like this patch. I have included it explicitly to recommend we do not pay any further heed to the 72 column limit. Signed-off-by: John Snow --- scripts/qapi/.flake8 | 1 + scripts/qapi/common.py | 8 +++++--- scripts/qapi/events.py | 9 +++++---- scripts/qapi/gen.py | 8 ++++---- scripts/qapi/introspect.py | 8 +++++--- scripts/qapi/main.py | 4 ++-- scripts/qapi/parser.py | 15 ++++++++------- scripts/qapi/schema.py | 23 +++++++++++++---------- scripts/qapi/types.py | 7 ++++--- 9 files changed, 47 insertions(+), 36 deletions(-) diff --git a/scripts/qapi/.flake8 b/scripts/qapi/.flake8 index 6b158c68b8..4f00455290 100644 --- a/scripts/qapi/.flake8 +++ b/scripts/qapi/.flake8 @@ -1,2 +1,3 @@ [flake8] extend-ignore =3D E722 # Prefer pylint's bare-except checks to flake8's +max-doc-length =3D 72 \ No newline at end of file diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index cbd3fd81d3..6e3d9b8ecd 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -41,7 +41,8 @@ def camel_to_upper(value: str) -> str: length =3D len(c_fun_str) for i in range(length): char =3D c_fun_str[i] - # When char is upper case and no '_' appears before, do more checks + # When char is upper case and no '_' appears before, + # do more checks if char.isupper() and (i > 0) and c_fun_str[i - 1] !=3D '_': if i < length - 1 and c_fun_str[i + 1].islower(): new_name +=3D '_' @@ -78,8 +79,9 @@ def c_name(name: str, protect: bool =3D True) -> str: protect=3DTrue: 'int' -> 'q_int'; protect=3DFalse: 'int' -> 'int' =20 :param name: The name to map. - :param protect: If true, avoid returning certain ticklish identifiers - (like C keywords) by prepending ``q_``. + :param protect: If true, avoid returning certain ticklish + identifiers (like C keywords) by prepending + ``q_``. """ # ANSI X3J11/88-090, 3.1.1 c89_words =3D set(['auto', 'break', 'case', 'char', 'const', 'continue= ', diff --git a/scripts/qapi/events.py b/scripts/qapi/events.py index fee8c671e7..210b56974f 100644 --- a/scripts/qapi/events.py +++ b/scripts/qapi/events.py @@ -48,7 +48,8 @@ def gen_param_var(typ: QAPISchemaObjectType) -> str: """ Generate a struct variable holding the event parameters. =20 - Initialize it with the function arguments defined in `gen_event_send`. + Initialize it with the function arguments defined in + `gen_event_send`. """ assert not typ.variants ret =3D mcgen(''' @@ -86,9 +87,9 @@ def gen_event_send(name: str, # FIXME: Our declaration of local variables (and of 'errp' in the # parameter list) can collide with exploded members of the event's # data type passed in as parameters. If this collision ever hits in - # practice, we can rename our local variables with a leading _ prefix, - # or split the code into a wrapper function that creates a boxed - # 'param' object then calls another to do the real work. + # practice, we can rename our local variables with a leading _ + # prefix, or split the code into a wrapper function that creates a + # boxed 'param' object then calls another to do the real work. have_args =3D boxed or (arg_type and not arg_type.is_empty()) =20 ret =3D mcgen(''' diff --git a/scripts/qapi/gen.py b/scripts/qapi/gen.py index 1fa503bdbd..c54980074e 100644 --- a/scripts/qapi/gen.py +++ b/scripts/qapi/gen.py @@ -63,9 +63,9 @@ def _bottom(self) -> str: return '' =20 def write(self, output_dir: str) -> None: - # Include paths starting with ../ are used to reuse modules of the= main - # schema in specialised schemas. Don't overwrite the files that are - # already generated for the main schema. + # Include paths starting with ../ are used to reuse modules + # of the main schema in specialised schemas. Don't overwrite + # the files that are already generated for the main schema. if self.fname.startswith('../'): return pathname =3D os.path.join(output_dir, self.fname) @@ -189,7 +189,7 @@ def _bottom(self) -> str: @contextmanager def ifcontext(ifcond: Sequence[str], *args: QAPIGenCCode) -> Iterator[None= ]: """ - A with-statement context manager that wraps with `start_if()` / `end_i= f()`. + A context manager that wraps output with `start_if()` / `end_if()`. =20 :param ifcond: A sequence of conditionals, passed to `start_if()`. :param args: any number of `QAPIGenCCode`. diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py index 9a348ca2e5..faf00013ad 100644 --- a/scripts/qapi/introspect.py +++ b/scripts/qapi/introspect.py @@ -61,8 +61,9 @@ # With optional annotations, the type of all values is: # JSONValue =3D Union[_Value, Annotated[_Value]] # -# Sadly, mypy does not support recursive types; so the _Stub alias is used= to -# mark the imprecision in the type model where we'd otherwise use JSONValu= e. +# Sadly, mypy does not support recursive types; so the _Stub alias is +# used to mark the imprecision in the type model where we'd otherwise +# use JSONValue. _Stub =3D Any _Scalar =3D Union[str, bool, None] _NonScalar =3D Union[Dict[str, _Stub], List[_Stub]] @@ -217,7 +218,8 @@ def visit_end(self) -> None: self._name_map =3D {} =20 def visit_needed(self, entity: QAPISchemaEntity) -> bool: - # Ignore types on first pass; visit_end() will pick up used types + # Ignore types on first pass; + # visit_end() will pick up used types return not isinstance(entity, QAPISchemaType) =20 def _name(self, name: str) -> str: diff --git a/scripts/qapi/main.py b/scripts/qapi/main.py index 703e7ed1ed..5bcac83985 100644 --- a/scripts/qapi/main.py +++ b/scripts/qapi/main.py @@ -1,5 +1,5 @@ -# This work is licensed under the terms of the GNU GPL, version 2 or later. -# See the COPYING file in the top-level directory. +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. =20 """ QAPI Generator diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 58267c3db9..d5bf91f2b0 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -331,8 +331,8 @@ def __init__(self, parser, name=3DNone, indent=3D0): self._indent =3D indent =20 def append(self, line): - # Strip leading spaces corresponding to the expected indent le= vel - # Blank lines are always OK. + # Strip leading spaces corresponding to the expected indent + # level. Blank lines are always OK. if line: indent =3D re.match(r'\s*', line).end() if indent < self._indent: @@ -353,10 +353,10 @@ def connect(self, member): self.member =3D member =20 def __init__(self, parser, info): - # self._parser is used to report errors with QAPIParseError. The - # resulting error position depends on the state of the parser. - # It happens to be the beginning of the comment. More or less - # servicable, but action at a distance. + # self._parser is used to report errors with QAPIParseError. + # The resulting error position depends on the state of the + # parser. It happens to be the beginning of the comment. More + # or less servicable, but action at a distance. self._parser =3D parser self.info =3D info self.symbol =3D None @@ -430,7 +430,8 @@ def _append_body_line(self, line): if not line.endswith(':'): raise QAPIParseError(self._parser, "line should end with '= :'") self.symbol =3D line[1:-1] - # FIXME invalid names other than the empty string aren't flagg= ed + # FIXME invalid names other than the empty string aren't + # flagged if not self.symbol: raise QAPIParseError(self._parser, "invalid name") elif self.symbol: diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 703b446fd2..01cdd753cd 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -166,9 +166,10 @@ def is_user_module(cls, name: str) -> bool: @classmethod def is_builtin_module(cls, name: str) -> bool: """ - The built-in module is a single System module for the built-in typ= es. + Return true when given the built-in module name. =20 - It is always "./builtin". + The built-in module is a specific System module for the built-in + types. It is always "./builtin". """ return name =3D=3D cls.BUILTIN_MODULE_NAME =20 @@ -294,7 +295,8 @@ def connect_doc(self, doc=3DNone): m.connect_doc(doc) =20 def is_implicit(self): - # See QAPISchema._make_implicit_enum_type() and ._def_predefineds() + # See QAPISchema._make_implicit_enum_type() and + # ._def_predefineds() return self.name.endswith('Kind') or self.name =3D=3D 'QType' =20 def c_type(self): @@ -421,9 +423,9 @@ def check(self, schema): =20 self.members =3D members # mark completed =20 - # Check that the members of this type do not cause duplicate JSON memb= ers, - # and update seen to track the members seen so far. Report any errors - # on behalf of info, which is not necessarily self.info + # Check that the members of this type do not cause duplicate JSON + # members, and update seen to track the members seen so far. Report + # any errors on behalf of info, which is not necessarily self.info def check_clash(self, info, seen): assert self._checked assert not self.variants # not implemented @@ -494,11 +496,12 @@ def __init__(self, name, info, doc, ifcond, features,= variants): def check(self, schema): super().check(schema) self.variants.tag_member.check(schema) - # Not calling self.variants.check_clash(), because there's nothing - # to clash with + # Not calling self.variants.check_clash(), because there's + # nothing to clash with self.variants.check(schema, {}) - # Alternate branch names have no relation to the tag enum values; - # so we have to check for potential name collisions ourselves. + # Alternate branch names have no relation to the tag enum + # values; so we have to check for potential name collisions + # ourselves. seen =3D {} types_seen =3D {} for v in self.variants.variants: diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py index 20d572a23a..2e67ab1752 100644 --- a/scripts/qapi/types.py +++ b/scripts/qapi/types.py @@ -35,8 +35,8 @@ from .source import QAPISourceInfo =20 =20 -# variants must be emitted before their container; track what has already -# been output +# variants must be emitted before their container; track what has +# already been output objects_seen =3D set() =20 =20 @@ -297,7 +297,8 @@ def _begin_user_module(self, name: str) -> None: ''')) =20 def visit_begin(self, schema: QAPISchema) -> None: - # gen_object() is recursive, ensure it doesn't visit the empty type + # gen_object() is recursive, ensure + # it doesn't visit the empty type objects_seen.add(schema.the_empty_object_type.name) =20 def _gen_type_cleanup(self, name: str) -> None: --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653021; cv=none; d=zohomail.com; s=zohoarc; b=S9VG9GLxLetYyFMjSuAsbUZVdd2VJurfoFC/ZJ9tmk93+ElP/6Tod56YR5JOTOVXr6lAVpbVEENne5D2NvppDuHelvYMJaPXShSdTYZn9XD6zVG6wP9SuptJYaQ/KieeLdSbvAwQ3MHzq65nsQ0NtX8eSAmBnZsMjUf4aniy2OY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653021; 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=X5MK1566Qqh8zMWNLG0j78hHjGaPqgCh1H+IX4f/0p0=; b=BlqXT4+zRE/SusqkaEncKiou2t2LfIWow7oqDHRJ0gcBlN/q+CISvdL/C7gjnepp+D+gsA/sbn6cXf53FvE5BcgqakNlA7Tol7QHIvfhSew3XkGj7g51zy92OP2nYchTSxiYJ0QRRSt6dpZyAaKLI/ETM0pPQHt327oVg9qbxfw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16166530218840.6162956905676538; Wed, 24 Mar 2021 23:17:01 -0700 (PDT) Received: from localhost ([::1]:50526 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJIh-0002PF-Hv for importer@patchew.org; Thu, 25 Mar 2021 02:16:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6H-00023h-7l for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21938) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6F-0008Ml-GN for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:09 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-537-2QbHV82iMrmyu9cix71ctQ-1; Thu, 25 Mar 2021 02:04:04 -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 1B4641083E80; Thu, 25 Mar 2021 06:04:03 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B27688EE3; Thu, 25 Mar 2021 06:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652247; 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=X5MK1566Qqh8zMWNLG0j78hHjGaPqgCh1H+IX4f/0p0=; b=Pa8bztJcl+xc9ztQRDW6n4rYGwkxFh8/8Vgv/cisXClrgVRUNvJ+waFbNrb1KxC+m72zgn MqoAWgcnV0eeYyn+VteSjndhH92pQLA2feg7vyl3KN7en/ws8Fnn8Evp47bK/FQRW2fVe4 1M3iPHcIJwNSTzDIIIJpS53iAYOLSX4= X-MC-Unique: 2QbHV82iMrmyu9cix71ctQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 03/19] qapi/expr.py: Remove 'info' argument from nested check_if_str Date: Thu, 25 Mar 2021 02:03:40 -0400 Message-Id: <20210325060356.4040114-4-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The function can just use the argument from the scope above. Otherwise, we get shadowed argument errors because the parameter name clashes with the name of a variable already in-scope. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa --- scripts/qapi/expr.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index c207481f7e..3fda5d5082 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -122,7 +122,7 @@ def check_flags(expr, info): =20 def check_if(expr, info, source): =20 - def check_if_str(ifcond, info): + def check_if_str(ifcond): if not isinstance(ifcond, str): raise QAPISemError( info, @@ -142,9 +142,9 @@ def check_if_str(ifcond, info): raise QAPISemError( info, "'if' condition [] of %s is useless" % source) for elt in ifcond: - check_if_str(elt, info) + check_if_str(elt) else: - check_if_str(ifcond, info) + check_if_str(ifcond) expr['if'] =3D [ifcond] =20 =20 --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616652730; cv=none; d=zohomail.com; s=zohoarc; b=HQhRPL2Y9zNI2Tl0t4joQ5oIFkWD0d53tsR52DSqonchFVE6msQvSqQt/ANYnfjTEF5SJcGFZUtnqyOT1I6Q9h1mdWKHaFT3MAITbzAa50Vrax82F2IjHbywGOOm0UQmzEoYLl8brSA3zlSh63DrEKFRu+vxJJ5BG7oMT/8Pl7g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616652730; 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=ZePtIkGAzcOoHwMSErefF+OjYEyTIgl5PYSXhSPTbkA=; b=f/8l9xwjG8wWcxuIXFK8tK6KOndv8ttQcWuWL26OPoha/T9uLXHcwihFNI1NOMY+0rtzvN7r8rKuB/q+Pp06lEmhR20ZBeaol9w6HewEHGTY2OIm7ra8duzZZEgEuxcmAUO2nQ3RG0PZzH3jElN879EBQ5354SWxWp8gmlrpVDU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616652730012677.5722831942816; Wed, 24 Mar 2021 23:12:10 -0700 (PDT) Received: from localhost ([::1]:41822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJE1-00079r-65 for importer@patchew.org; Thu, 25 Mar 2021 02:12:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6I-00025B-53 for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48469) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6G-0008Mo-80 for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:09 -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-225-KgdUlHcQPXW3W0uVZYx8yQ-1; Thu, 25 Mar 2021 02:04:04 -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 D472C1083E81; Thu, 25 Mar 2021 06:04:03 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B2C7866C7; Thu, 25 Mar 2021 06:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652247; 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=ZePtIkGAzcOoHwMSErefF+OjYEyTIgl5PYSXhSPTbkA=; b=AXAKdQP11WiVJudWUjPdE8BesiGLiNXgH5GrB1DjJAIefv8vG29pHzcS8cRo4T9spFHwVp BXmaLCdodMa5GAwhwL9a3EAODe+izjYVZvrm1LjDG+XcEA6NKQMr4WRrpLLlVfAlfgA+WR yoS357IY95hNa1GTl0etle5z7KJTk5Y= X-MC-Unique: KgdUlHcQPXW3W0uVZYx8yQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 04/19] qapi/expr.py: Check for dict instead of OrderedDict Date: Thu, 25 Mar 2021 02:03:41 -0400 Message-Id: <20210325060356.4040114-5-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" OrderedDict is a subtype of dict, so we can check for a more general form. These functions do not themselves depend on it being any particular type. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa --- scripts/qapi/expr.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 3fda5d5082..b4bbcd54c0 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -14,7 +14,6 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 -from collections import OrderedDict import re =20 from .common import c_name @@ -149,7 +148,7 @@ def check_if_str(ifcond): =20 =20 def normalize_members(members): - if isinstance(members, OrderedDict): + if isinstance(members, dict): for key, arg in members.items(): if isinstance(arg, dict): continue @@ -180,7 +179,7 @@ def check_type(value, info, source, if not allow_dict: raise QAPISemError(info, "%s should be a type name" % source) =20 - if not isinstance(value, OrderedDict): + if not isinstance(value, dict): raise QAPISemError(info, "%s should be an object or type name" % source) =20 --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653298; cv=none; d=zohomail.com; s=zohoarc; b=FC4i9qBj5UiI3cmakBnFIc2r4tS715XSmVlH1H9YwQqI9dGo3/DmbRtqziIjdkdpEGdShV9F+tUSG786iyBCmSnVted+M5iNVxLbzwYCNw82iTdy/nvFTn6UmxVRO8566PuQMqAxhNpQk4F3Of6++sMJdRBe+UG3UhHT8Kl3RRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653298; 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=010H8UE+Xsp3/CHqNy0PO37B9Jwy6Q1LEJWdA7wtABU=; b=EWDkvEMZ2hEu3Y3PZAgA99VUNmL3PhwaC2g46P48HIM6mnemRo1spTHtbrwTYqH7QRdMhE7HQMrZ8+7t/MvVR05GzEb1aSPKeQPhQUuy2Uxn12/8OSq+46qXvDR1z2eCM3OfrMGMxll5+emQeSoj2u4bBhYrQfEne8XVoUvrHs8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616653298913663.1435869312315; Wed, 24 Mar 2021 23:21:38 -0700 (PDT) Received: from localhost ([::1]:59128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJNC-00064V-4k for importer@patchew.org; Thu, 25 Mar 2021 02:21:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6I-00026i-WA for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6G-0008Mx-EN for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:10 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-125-5phYSoHRMe6z__OhQRdLIQ-1; Thu, 25 Mar 2021 02:04:05 -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 BA5E35704F; Thu, 25 Mar 2021 06:04:04 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01E0B866C7; Thu, 25 Mar 2021 06:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652247; 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=010H8UE+Xsp3/CHqNy0PO37B9Jwy6Q1LEJWdA7wtABU=; b=aeiPUY1MFJOVDasg9wAVLLk4W2VfHOArPWQ9G1s0QUOQjxHeHca5A8mXpREFV3KVqBeeVD uJ2aQ6A1R80qY+t4IAyie9U26C+cUanOtBnaAAwi816sLR5mfDKSbt8gqTbmv0Mxdy1qrY O7JO5ym7p94tmrlMDf0A/Q81pnx8AJM= X-MC-Unique: 5phYSoHRMe6z__OhQRdLIQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 05/19] qapi/expr.py: constrain incoming expression types Date: Thu, 25 Mar 2021 02:03:42 -0400 Message-Id: <20210325060356.4040114-6-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" mypy does not know the types of values stored in Dicts that masquerade as objects. Help the type checker out by constraining the type. Signed-off-by: John Snow --- scripts/qapi/expr.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index b4bbcd54c0..b75c85c160 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -15,9 +15,18 @@ # See the COPYING file in the top-level directory. =20 import re +from typing import Dict, Optional =20 from .common import c_name from .error import QAPISemError +from .parser import QAPIDoc +from .source import QAPISourceInfo + + +# Deserialized JSON objects as returned by the parser; +# The values of this mapping are not necessary to exhaustively type +# here, because the purpose of this module is to interrogate that type. +_JSONObject =3D Dict[str, object] =20 =20 # Names consist of letters, digits, -, and _, starting with a letter. @@ -315,9 +324,20 @@ def check_event(expr, info): =20 def check_exprs(exprs): for expr_elem in exprs: - expr =3D expr_elem['expr'] - info =3D expr_elem['info'] - doc =3D expr_elem.get('doc') + # Expression + assert isinstance(expr_elem['expr'], dict) + for key in expr_elem['expr'].keys(): + assert isinstance(key, str) + expr: _JSONObject =3D expr_elem['expr'] + + # QAPISourceInfo + assert isinstance(expr_elem['info'], QAPISourceInfo) + info: QAPISourceInfo =3D expr_elem['info'] + + # Optional[QAPIDoc] + tmp =3D expr_elem.get('doc') + assert tmp is None or isinstance(tmp, QAPIDoc) + doc: Optional[QAPIDoc] =3D tmp =20 if 'include' in expr: continue --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616652766; cv=none; d=zohomail.com; s=zohoarc; b=mfXrMEZs2moP6k+66UAZ6IpUuTUTL+WivgdWfM8hGEGrvx6Nci6uKiVXRj4/qMHZPCZDR8RksZOt8He5TBI/i7W2A4iAuzL6GKgSq4LGYhB5gNW8b6TyYdQPWnUy+JSafWBtV9+4fcGEO6HmCjIh4teKeSbH3ZbTBwU5AKuO2Zg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616652766; 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=0Qsi8bMa5ywrgo0c+jTBnCQ12OxKuv8GEdBcTce5R/8=; b=LiOu3FXWiPbvb9JQ9sz0whTrNdIF0JzVIczvn9dErFnrk/HSl8g2eCaH/Rem/9Q3LompOtREZmsZ8GkUQQmuhWW2EsCFIljTr86OapuLiufrOjmZXKo5WqB5DFcuizGvxW8uFqqV8NiGh9/y5ACbQSDcKe40HgGXsB2PODAZR1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616652766352399.7506096045249; Wed, 24 Mar 2021 23:12:46 -0700 (PDT) Received: from localhost ([::1]:42572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJEb-0007SQ-MS for importer@patchew.org; Thu, 25 Mar 2021 02:12:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6K-0002AE-OA for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42540) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6J-0008OH-2N for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-566-AeWSrgSoP16f861iQBkLtg-1; Thu, 25 Mar 2021 02:04:06 -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 7CA0884E20A; Thu, 25 Mar 2021 06:04:05 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id D83B2866C7; Thu, 25 Mar 2021 06:04:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652248; 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=0Qsi8bMa5ywrgo0c+jTBnCQ12OxKuv8GEdBcTce5R/8=; b=UyZSjt5OZrYkHdVpespK5vHQcHV4TNEMAAFs9635lh4hxHSWfIMtUjtbas1lx2/EW5N6Fi A03BFj4AIeLlkRbFgCHxBJtOtrm2Y2bkG+yqDwpuCwf4OJ8w14tY8/WB1mE2M/GYy9gN+J JGgkGXMxKnHehTjWJcqsNOd6qROCIX0= X-MC-Unique: AeWSrgSoP16f861iQBkLtg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 06/19] qapi/expr.py: Add assertion for union type 'check_dict' Date: Thu, 25 Mar 2021 02:03:43 -0400 Message-Id: <20210325060356.4040114-7-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" mypy isn't fond of allowing you to check for bool membership in a collection of str elements. Guard this lookup for precisely when we were given a name. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa --- scripts/qapi/expr.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index b75c85c160..2a2cf7064f 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -192,7 +192,9 @@ def check_type(value, info, source, raise QAPISemError(info, "%s should be an object or type name" % source) =20 - permissive =3D allow_dict in info.pragma.member_name_exceptions + permissive =3D False + if isinstance(allow_dict, str): + permissive =3D allow_dict in info.pragma.member_name_exceptions =20 # value is a dictionary, check that each member is okay for (key, arg) in value.items(): --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616652596; cv=none; d=zohomail.com; s=zohoarc; b=naSAHWib9/VfOnRHvYRMt1DWVJRUrFrNLUA/UZj9uy7RsNTbMjeruRDOF1Xi6yJKv7Hz8aWAl3J807/E36oRVh+vugRyiC4+vYjZnNmU16xNY4ZzOVNvqgmV60JyvCyFOPpvYxXKq4AWoJ9oBB0ghp35fDqT4yhKGI38d+7LFig= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616652596; 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=7f/AvFdr21PpuGtG6YguoqEBpnXCTo9cGd7OW2vyeec=; b=UvRg0QAlo+TlToXiONvNVVoLOhwHLwjMeK3v0kafjZjnXUyL+sydPZQxnTmAaYLSDI3bwUwVqbME6KN+Xc87SEVTQoJdDGIyt17c4sexfqWcbzt3IDTKmAbHUsyo1o3549N5bEOTfxl0pku6XkU8QOQNjRVWWS/igCG1lgNbkXc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616652596373285.50784726413985; Wed, 24 Mar 2021 23:09:56 -0700 (PDT) Received: from localhost ([::1]:34094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJ9n-0003to-VP for importer@patchew.org; Thu, 25 Mar 2021 02:07:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6K-0002AT-UI for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52671) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6J-0008OV-9V for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:12 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-570--AIr5BErPmCTVGA5viBpPg-1; Thu, 25 Mar 2021 02:04:07 -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 4AD2F108BD06; Thu, 25 Mar 2021 06:04:06 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id A212F866C7; Thu, 25 Mar 2021 06:04:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652249; 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=7f/AvFdr21PpuGtG6YguoqEBpnXCTo9cGd7OW2vyeec=; b=ZXSEavHg5cfbjhNubmf61foxK2KSwIMFPGSkx2MZ1+ZQT3ssQA74t87xk9by3Fa9nC6Rva i/1SUNOP7Y0Ve8cwOCDXKlVMUOUn0ZkHYpwWLYY7XZEExXuVTj7QsWzojfeZbivLpADLsX VCvW7iHdpJw5/vQZRAWiczld0t00xvc= X-MC-Unique: -AIr5BErPmCTVGA5viBpPg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 07/19] qapi/expr.py: move string check upwards in check_type Date: Thu, 25 Mar 2021 02:03:44 -0400 Message-Id: <20210325060356.4040114-8-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For readability purposes only, shimmy the early return upwards to the top of the function, so cases proceed in order from least to most complex. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa --- scripts/qapi/expr.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 2a2cf7064f..73e7d8cb0d 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -169,6 +169,10 @@ def check_type(value, info, source, if value is None: return =20 + # Type name + if isinstance(value, str): + return + # Array type if isinstance(value, list): if not allow_array: @@ -179,10 +183,6 @@ def check_type(value, info, source, source) return =20 - # Type name - if isinstance(value, str): - return - # Anonymous type =20 if not allow_dict: --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653054; cv=none; d=zohomail.com; s=zohoarc; b=f513J6sby2DJxrN50iP0BX94u3rQKn2+JbWi6Gn+9wDi24fwLG4XFmOmdWyJNnTimBwldYXAc97E3afsZdMrMeTW1ETFrmBBdMaLkhXzhNK4Z38LM3BBLVEsvDp/Nr6Qcv3Mdk+wCMHuKmtlhPRwTuRZTIrTAK0JefOftluGVCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653054; 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=8SNUZmla9aQCG2+1/B1ldVak0N1SDNJTYTjIkq5pNrM=; b=depC4XBBkUXpDggVNR+yWMUSpb36YhrGZ2nGz0C3hKNHG5WsIhJIH6GRTLwyl8lUVvwA9nuFkXP9/1T03dARomGO2oZ3+YEuZRlOVukcXoYN5CF/HO04/giNQN1lC+iILLqBOxLbz1xg8o9DzEIaedc+QBOiZ/2UpJJmG0VCOf0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16166530543231012.4038985275084; Wed, 24 Mar 2021 23:17:34 -0700 (PDT) Received: from localhost ([::1]:51012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJJF-0002bC-E1 for importer@patchew.org; Thu, 25 Mar 2021 02:17:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6M-0002Dd-Mr for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:37067) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6K-0008QT-Ud for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04: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-423-kuDvg5fjM0afaHHflBEjBw-1; Thu, 25 Mar 2021 02:04:10 -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 3F1F9190B2A1; Thu, 25 Mar 2021 06:04:09 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89E76866C7; Thu, 25 Mar 2021 06:04:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652252; 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=8SNUZmla9aQCG2+1/B1ldVak0N1SDNJTYTjIkq5pNrM=; b=eZLs4i8xIQnh2u+1ueqAwdeMzFJl8glTs3SNSyNY/5TDmLuXygeVdkDP6dkk3jt83DpBDb 35NuIObMwtGz/LOj5u1s30cqT+BWGs6cYTkwVigHSiQMqSDDR60T/B+w2zgUqDCtAyu+YF enc106IFlABv9oDW82IvC3Iva34Z5Q4= X-MC-Unique: kuDvg5fjM0afaHHflBEjBw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 08/19] qapi: add tests for invalid 'data' field type Date: Thu, 25 Mar 2021 02:03:45 -0400 Message-Id: <20210325060356.4040114-9-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It needs to be an object (dict), not anything else. Signed-off-by: John Snow --- Note: this actually doesn't ... work, but on-list, we discussed wanting tests first, then the fix. That can't happen here, because QAPI crashes at runtime. So uh, just squash this into the following patch, I guess? I tried. Signed-off-by: John Snow --- tests/qapi-schema/alternate-invalid-data-type.err | 0 tests/qapi-schema/alternate-invalid-data-type.json | 4 ++++ tests/qapi-schema/alternate-invalid-data-type.out | 0 tests/qapi-schema/meson.build | 2 ++ tests/qapi-schema/union-invalid-data-type.err | 0 tests/qapi-schema/union-invalid-data-type.json | 13 +++++++++++++ tests/qapi-schema/union-invalid-data-type.out | 0 7 files changed, 19 insertions(+) create mode 100644 tests/qapi-schema/alternate-invalid-data-type.err create mode 100644 tests/qapi-schema/alternate-invalid-data-type.json create mode 100644 tests/qapi-schema/alternate-invalid-data-type.out create mode 100644 tests/qapi-schema/union-invalid-data-type.err create mode 100644 tests/qapi-schema/union-invalid-data-type.json create mode 100644 tests/qapi-schema/union-invalid-data-type.out diff --git a/tests/qapi-schema/alternate-invalid-data-type.err b/tests/qapi= -schema/alternate-invalid-data-type.err new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/alternate-invalid-data-type.json b/tests/qap= i-schema/alternate-invalid-data-type.json new file mode 100644 index 0000000000..7d5d905581 --- /dev/null +++ b/tests/qapi-schema/alternate-invalid-data-type.json @@ -0,0 +1,4 @@ +# Alternate type requires an object for 'data' +{ 'alternate': 'Alt', + 'data': ['rubbish', 'nonsense'] +} diff --git a/tests/qapi-schema/alternate-invalid-data-type.out b/tests/qapi= -schema/alternate-invalid-data-type.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index 8ba6917132..cc5b136cfb 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -15,6 +15,7 @@ schemas =3D [ 'alternate-conflict-bool-string.json', 'alternate-conflict-num-string.json', 'alternate-empty.json', + 'alternate-invalid-data-type.json', 'alternate-invalid-dict.json', 'alternate-nested.json', 'alternate-unknown.json', @@ -192,6 +193,7 @@ schemas =3D [ 'union-clash-branches.json', 'union-empty.json', 'union-invalid-base.json', + 'union-invalid-data-type.json', 'union-optional-branch.json', 'union-unknown.json', 'unknown-escape.json', diff --git a/tests/qapi-schema/union-invalid-data-type.err b/tests/qapi-sch= ema/union-invalid-data-type.err new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/union-invalid-data-type.json b/tests/qapi-sc= hema/union-invalid-data-type.json new file mode 100644 index 0000000000..5a32d267bf --- /dev/null +++ b/tests/qapi-schema/union-invalid-data-type.json @@ -0,0 +1,13 @@ +# the union data type must be an object. + +{ 'struct': 'TestTypeA', + 'data': { 'string': 'str' } } + +{ 'struct': 'TestTypeB', + 'data': { 'integer': 'int' } } + +{ 'union': 'TestUnion', + 'base': 'int', + 'discriminator': 'int', + 'data': ['TestTypeA', 'TestTypeB'] +} diff --git a/tests/qapi-schema/union-invalid-data-type.out b/tests/qapi-sch= ema/union-invalid-data-type.out new file mode 100644 index 0000000000..e69de29bb2 --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653018; cv=none; d=zohomail.com; s=zohoarc; b=PxXJdauKfFjqt6uFkeyOavHgEEIy4V8sACFDbA9BAoZ9duwymLQ5QrdDcdaKlEej5QMmTDzqIBuaGUnuvbEib/0fMBNNi7XRSYQW3mdDjG0uQ4GPCGdT6vWcSx7cE8BoKCp+86tKIzrltdVkf1tci+otvZgp20cc38tTQN38Z4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653018; 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=MTcs+o8bFClbnyDq0anB2OcQJj/dqwkc6Wzwv++081A=; b=XbPQXsX/RdbeVYf8jj6lFPN2HcZZnP5sPRBj69Mu/GP/pDo5Eq+UP2y5uQn0obG5992uixEgaSjQA5VL3s+oZZ+BGM5akQ/T414hRzi1Wvvaao1iNo6SlLGOtb5v/ptM4KnMFFvTgcuU2Y1t9AUDN+eGaCoBy/5QpoAD6fsNEHs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616653018236547.6646380736443; Wed, 24 Mar 2021 23:16:58 -0700 (PDT) Received: from localhost ([::1]:50374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJIf-0002LH-DE for importer@patchew.org; Thu, 25 Mar 2021 02:16:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6N-0002FO-KI for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29672) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6L-0008Qf-UF for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:15 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-86-cJUYkuoOOgasalC0RLjIVw-1; Thu, 25 Mar 2021 02:04:10 -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 05C5085EE8B; Thu, 25 Mar 2021 06:04:10 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60967866C7; Thu, 25 Mar 2021 06:04:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652253; 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=MTcs+o8bFClbnyDq0anB2OcQJj/dqwkc6Wzwv++081A=; b=g6ldBjEgCAL9LHbST7HNtCUfWoTtE2mjmoSnucANjpo9jNSkXfKCOHY6VikHPGTYj71nub RAYOAdDRYsq7BjiX0huI5f443PBEy4qbuz8Ry4ikEPe/CviT5BbEEYfvpiNlJmTndbUhLt DGJBUMqw2s1+PGR0noJLrULxPni/BjM= X-MC-Unique: cJUYkuoOOgasalC0RLjIVw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 09/19] qapi/expr.py: Check type of 'data' member Date: Thu, 25 Mar 2021 02:03:46 -0400 Message-Id: <20210325060356.4040114-10-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" We don't actually check, so the user can get some unpleasant stacktraces. Formalize it. Signed-off-by: John Snow --- scripts/qapi/expr.py | 7 +++++++ tests/qapi-schema/alternate-invalid-data-type.err | 2 ++ tests/qapi-schema/union-invalid-data-type.err | 2 ++ 3 files changed, 11 insertions(+) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 73e7d8cb0d..ca5ab7bfda 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -281,6 +281,9 @@ def check_union(expr, info): raise QAPISemError(info, "'discriminator' requires 'base'") check_name_is_str(discriminator, info, "'discriminator'") =20 + if not isinstance(members, dict): + raise QAPISemError(info, "'data' must be an object") + for (key, value) in members.items(): source =3D "'data' member '%s'" % key if discriminator is None: @@ -296,6 +299,10 @@ def check_alternate(expr, info): =20 if not members: raise QAPISemError(info, "'data' must not be empty") + + if not isinstance(members, dict): + raise QAPISemError(info, "'data' must be an object") + for (key, value) in members.items(): source =3D "'data' member '%s'" % key check_name_lower(key, info, source) diff --git a/tests/qapi-schema/alternate-invalid-data-type.err b/tests/qapi= -schema/alternate-invalid-data-type.err index e69de29bb2..c7301ccb00 100644 --- a/tests/qapi-schema/alternate-invalid-data-type.err +++ b/tests/qapi-schema/alternate-invalid-data-type.err @@ -0,0 +1,2 @@ +alternate-invalid-data-type.json: In alternate 'Alt': +alternate-invalid-data-type.json:2: 'data' must be an object diff --git a/tests/qapi-schema/union-invalid-data-type.err b/tests/qapi-sch= ema/union-invalid-data-type.err index e69de29bb2..b71c3400c5 100644 --- a/tests/qapi-schema/union-invalid-data-type.err +++ b/tests/qapi-schema/union-invalid-data-type.err @@ -0,0 +1,2 @@ +union-invalid-data-type.json: In union 'TestUnion': +union-invalid-data-type.json:9: 'data' must be an object --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653309; cv=none; d=zohomail.com; s=zohoarc; b=Tf5EQtkaEJ/RKml06tofpnxh06GdGOmYy7ez7KQTjChvYsnLagjmdPHH716zXAehEfKWPQQkGk5E5rkiebt8pjVQlji1axQQNwlz1KBFDTfW6JtJShlb99RIBbg4dK6YTVx2VrT0J3NJk6rthh1vNRcIi8L5yJVqrmWON+TODqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653309; 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=GMeU10YaYmX+kMXtzWNhDtCj8O+0nRuKJD7OBVq6Ovw=; b=A5aN0v4NMW3JVkBjID66qx4V3qWsli4Xhz9TqbFh+W+aRXuSwwYFueQCHV9p1vqTsXkoF8u7gqE/i+bLBhdh4HHrB47rNChJlH5IvFkT6fccROhFqCFt1gtd52n8owWWetDb1oTlKBg7NZxWd+d3REqqimD+rUKMT4depAUC6to= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616653309581455.62995412303417; Wed, 24 Mar 2021 23:21:49 -0700 (PDT) Received: from localhost ([::1]:59572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJNM-0006HZ-Ar for importer@patchew.org; Thu, 25 Mar 2021 02:21:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39896) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6Q-0002Ka-Na for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:18 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35420) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6P-0008Si-0U for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:18 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-467-8Lo1hafdM6Kd0IdXMLcTmQ-1; Thu, 25 Mar 2021 02:04:14 -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 3B6041083E80; Thu, 25 Mar 2021 06:04:13 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F5BC866C7; Thu, 25 Mar 2021 06:04:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652256; 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=GMeU10YaYmX+kMXtzWNhDtCj8O+0nRuKJD7OBVq6Ovw=; b=BBQXz/1Ddfr6JgYtodGGpbcvHlh64nstUT2UVIfNgCK9TzV/rGgyEuikK3QuR22cbC47hR VbmKwkbWpghb+cw8JZi8nZLEmrVUqS5wR8lomEpjhiowauBsHYG+54Zh2qGPQoWrsD4uda P5m2BX0/hsvZV8Y2cIp7/MObxROIBpY= X-MC-Unique: 8Lo1hafdM6Kd0IdXMLcTmQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 10/19] qapi/expr.py: Add casts in a few select cases Date: Thu, 25 Mar 2021 02:03:47 -0400 Message-Id: <20210325060356.4040114-11-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Casts are instructions to the type checker only, they aren't "safe" and should probably be avoided in general. In this case, when we perform type checking on a nested structure, the type of each field does not "stick". (See PEP 647 for an example of "type narrowing" that does "stick". It is available in Python 3.10, so we can't use it yet.) We don't need to assert that something is a str if we've already checked or asserted that it is -- use a cast instead for these cases. Signed-off-by: John Snow --- scripts/qapi/expr.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index ca5ab7bfda..505e67bd21 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -15,7 +15,7 @@ # See the COPYING file in the top-level directory. =20 import re -from typing import Dict, Optional +from typing import Dict, Optional, cast =20 from .common import c_name from .error import QAPISemError @@ -259,7 +259,7 @@ def check_enum(expr, info): =20 =20 def check_struct(expr, info): - name =3D expr['struct'] + name =3D cast(str, expr['struct']) # Asserted in check_exprs members =3D expr['data'] =20 check_type(members, info, "'data'", allow_dict=3Dname) @@ -267,7 +267,7 @@ def check_struct(expr, info): =20 =20 def check_union(expr, info): - name =3D expr['union'] + name =3D cast(str, expr['union']) # Asserted in check_exprs base =3D expr.get('base') discriminator =3D expr.get('discriminator') members =3D expr['data'] @@ -366,8 +366,8 @@ def check_exprs(exprs): else: raise QAPISemError(info, "expression is missing metatype") =20 - name =3D expr[meta] - check_name_is_str(name, info, "'%s'" % meta) + check_name_is_str(expr[meta], info, "'%s'" % meta) + name =3D cast(str, expr[meta]) info.set_defn(meta, name) check_defn_name_str(name, info, meta) =20 --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616652911; cv=none; d=zohomail.com; s=zohoarc; b=kOScfj4w4YEEpWyZqYNccMgkE65NqI/mV5j5fpIVC1oZcaZ9izflhcQjLnk1MLO3QJKQi9w4ibSucLWN/3cGm5v5YCyjI4Y/alt8zTM+a/6N2AWpzMbvqlHdIU4o5GEXprrYRAffX40CG0g3tcLCxgPCcCTfdlgg5VpJi0gtI7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616652911; 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=58vMjUiEmXKmPmO0gjjkRE8fcgGQ+DRkcI0Sp3kmdeE=; b=YFIbE6N9P8ylqczQnoazlTZpn6a+dEi3Y/f9uXKp25eape2NWHztvsVJxF2Hb1jM0o9ohxep9WRmBnsoWUR/v8CpT9desZnddyuxwhyrLf2EeyeANybZsfkRsbMaOXddjbFcCKihmCQx+0pUB+hN4+BnXNwUyh2mEZfa+3wQFns= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616652911318259.4835530738434; Wed, 24 Mar 2021 23:15:11 -0700 (PDT) Received: from localhost ([::1]:46688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJGw-0000kP-2M for importer@patchew.org; Thu, 25 Mar 2021 02:15:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6R-0002Le-NR for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:44943) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6P-0008TI-BJ for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:19 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-300-sQPEB-XCM1yqVA1FG06NUA-1; Thu, 25 Mar 2021 02:04:14 -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 031FD80D6A8; Thu, 25 Mar 2021 06:04:14 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5CBD7866C7; Thu, 25 Mar 2021 06:04:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652256; 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=58vMjUiEmXKmPmO0gjjkRE8fcgGQ+DRkcI0Sp3kmdeE=; b=BtNhvLBZ+CaCpSqIfk12qqiL6Rex4SHI5rz2+8ENLqwedsAKF42b9SsDeWonXJnGLx0p+W sHbUnau38txE8LoH+noTq2WPz3o8JSXdJWPj1XjrZDTb/mEIGbQEkHqpLUBQPb0qRuLQ58 FvhxeIKsqzIi3l/FRz1nlL7fPPXIuK4= X-MC-Unique: sQPEB-XCM1yqVA1FG06NUA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 11/19] qapi/expr.py: Modify check_keys to accept any Collection Date: Thu, 25 Mar 2021 02:03:48 -0400 Message-Id: <20210325060356.4040114-12-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is a minor adjustment that allows the 'required' and 'optional' keys fields to take a default value of an empty, immutable sequence (the empty tuple). This reveals a quirk of this function, which is that "a + b" is list-specific behavior. We can accept a wider variety of types if we avoid that behavior. Using Collection allows us to accept things like lists, tuples, sets, and so on. (Iterable would also have worked, but Iterable also includes things like generator expressions which are consumed upon iteration, which would require a rewrite to make sure that each input was only traversed once.) Signed-off-by: John Snow --- scripts/qapi/expr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 505e67bd21..7e22723b50 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -100,7 +100,7 @@ def pprint(elems): "%s misses key%s %s" % (source, 's' if len(missing) > 1 else '', pprint(missing))) - allowed =3D set(required + optional) + allowed =3D set(required) | set(optional) unknown =3D set(value) - allowed if unknown: raise QAPISemError( --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653637; cv=none; d=zohomail.com; s=zohoarc; b=PXKRPfQsgdDb2N78Ede7Z2MBc0Mr2Wn+6LkkRfb1VkXBUbHSZHyM1h0LrAvG0fAMQ/dIziXEvO0eD1l5NVahK1dbP0nB6ferDeeZwjRPHiJJlbip5faXavZ0Mx4NJIbGZ+vllnQIKvr2A2uNVKuqJ3PfNLzsMbrYHVnG4J2ieKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653637; 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=aI1DqCHDMOwRH4eVuX2MLP4sz4erf8MUt7oEgFn+W7w=; b=BQOvPPEFECp3/2NYgnS3M1OpIvjw+7+uZXa3HicN0e0JspT89OMYKp2fezu0Bsn3YgiJRsODb2t6fSMFKcUrEFULU92LohdjO0xF/AD/QMV2HLOZIXpMcwjGWtoYSCVIG6mHg3C8EcDMNiFnN5yBcnxH7ZqpUID9ycEykhwr6s4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616653637018188.19464524490377; Wed, 24 Mar 2021 23:27:17 -0700 (PDT) Received: from localhost ([::1]:39876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJSd-0001Rd-Mk for importer@patchew.org; Thu, 25 Mar 2021 02:27:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39944) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6V-0002N2-6R for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:50227) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6S-0008V8-4d for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04: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-365-DECAvpxXO0OBes3CnXPL0g-1; Thu, 25 Mar 2021 02:04:15 -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 BA44A190B2A5; Thu, 25 Mar 2021 06:04:14 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 219B8866C7; Thu, 25 Mar 2021 06:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652259; 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=aI1DqCHDMOwRH4eVuX2MLP4sz4erf8MUt7oEgFn+W7w=; b=HA67bNGrzE1mv8ZWvcSoM3pKB5K+0T4z4nPbGGIvpH9Vr34NoLXlg6+G5jooar5m2P0rfC 2RSc5h+p2hgPuOHAKm9X23/PjDYlOQq+rTZE6Rdci3uoxP2v4ES7rQT3NIyKF6y/DmT2U5 2cDx1MDNdC4M9izK1RazYYCVSXk2juY= X-MC-Unique: DECAvpxXO0OBes3CnXPL0g-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 12/19] qapi/expr.py: add type hint annotations Date: Thu, 25 Mar 2021 02:03:49 -0400 Message-Id: <20210325060356.4040114-13-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow --- scripts/qapi/expr.py | 68 +++++++++++++++++++++++++++---------------- scripts/qapi/mypy.ini | 5 ---- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 7e22723b50..ea9d39fcf2 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -15,7 +15,15 @@ # See the COPYING file in the top-level directory. =20 import re -from typing import Dict, Optional, cast +from typing import ( + Collection, + Dict, + Iterable, + List, + Optional, + Union, + cast, +) =20 from .common import c_name from .error import QAPISemError @@ -37,12 +45,14 @@ r'([a-z][a-z0-9_-]*)$', re.IGNORECASE) =20 =20 -def check_name_is_str(name, info, source): +def check_name_is_str(name: object, + info: QAPISourceInfo, + source: str) -> None: if not isinstance(name, str): raise QAPISemError(info, "%s requires a string name" % source) =20 =20 -def check_name_str(name, info, source): +def check_name_str(name: str, info: QAPISourceInfo, source: str) -> str: # Reserve the entire 'q_' namespace for c_name(), and for 'q_empty' # and 'q_obj_*' implicit type names. match =3D valid_name.match(name) @@ -51,16 +61,16 @@ def check_name_str(name, info, source): return match.group(3) =20 =20 -def check_name_upper(name, info, source): +def check_name_upper(name: str, info: QAPISourceInfo, source: str) -> None: stem =3D check_name_str(name, info, source) if re.search(r'[a-z-]', stem): raise QAPISemError( info, "name of %s must not use lowercase or '-'" % source) =20 =20 -def check_name_lower(name, info, source, - permit_upper=3DFalse, - permit_underscore=3DFalse): +def check_name_lower(name: str, info: QAPISourceInfo, source: str, + permit_upper: bool =3D False, + permit_underscore: bool =3D False) -> None: stem =3D check_name_str(name, info, source) if ((not permit_upper and re.search(r'[A-Z]', stem)) or (not permit_underscore and '_' in stem)): @@ -68,13 +78,13 @@ def check_name_lower(name, info, source, info, "name of %s must not use uppercase or '_'" % source) =20 =20 -def check_name_camel(name, info, source): +def check_name_camel(name: str, info: QAPISourceInfo, source: str) -> None: stem =3D check_name_str(name, info, source) if not re.match(r'[A-Z][A-Za-z0-9]*[a-z][A-Za-z0-9]*$', stem): raise QAPISemError(info, "name of %s must use CamelCase" % source) =20 =20 -def check_defn_name_str(name, info, meta): +def check_defn_name_str(name: str, info: QAPISourceInfo, meta: str) -> Non= e: if meta =3D=3D 'event': check_name_upper(name, info, meta) elif meta =3D=3D 'command': @@ -88,9 +98,13 @@ def check_defn_name_str(name, info, meta): info, "%s name should not end in '%s'" % (meta, name[-4:])) =20 =20 -def check_keys(value, info, source, required, optional): +def check_keys(value: _JSONObject, + info: QAPISourceInfo, + source: str, + required: Collection[str], + optional: Collection[str]) -> None: =20 - def pprint(elems): + def pprint(elems: Iterable[str]) -> str: return ', '.join("'" + e + "'" for e in sorted(elems)) =20 missing =3D set(required) - set(value) @@ -110,7 +124,7 @@ def pprint(elems): pprint(unknown), pprint(allowed))) =20 =20 -def check_flags(expr, info): +def check_flags(expr: _JSONObject, info: QAPISourceInfo) -> None: for key in ['gen', 'success-response']: if key in expr and expr[key] is not False: raise QAPISemError( @@ -128,9 +142,9 @@ def check_flags(expr, info): "are incompatible") =20 =20 -def check_if(expr, info, source): +def check_if(expr: _JSONObject, info: QAPISourceInfo, source: str) -> None: =20 - def check_if_str(ifcond): + def check_if_str(ifcond: object) -> None: if not isinstance(ifcond, str): raise QAPISemError( info, @@ -156,7 +170,7 @@ def check_if_str(ifcond): expr['if'] =3D [ifcond] =20 =20 -def normalize_members(members): +def normalize_members(members: object) -> None: if isinstance(members, dict): for key, arg in members.items(): if isinstance(arg, dict): @@ -164,8 +178,11 @@ def normalize_members(members): members[key] =3D {'type': arg} =20 =20 -def check_type(value, info, source, - allow_array=3DFalse, allow_dict=3DFalse): +def check_type(value: Optional[object], + info: QAPISourceInfo, + source: str, + allow_array: bool =3D False, + allow_dict: Union[bool, str] =3D False) -> None: if value is None: return =20 @@ -212,7 +229,8 @@ def check_type(value, info, source, check_type(arg['type'], info, key_source, allow_array=3DTrue) =20 =20 -def check_features(features, info): +def check_features(features: Optional[object], + info: QAPISourceInfo) -> None: if features is None: return if not isinstance(features, list): @@ -229,7 +247,7 @@ def check_features(features, info): check_if(f, info, source) =20 =20 -def check_enum(expr, info): +def check_enum(expr: _JSONObject, info: QAPISourceInfo) -> None: name =3D expr['enum'] members =3D expr['data'] prefix =3D expr.get('prefix') @@ -258,7 +276,7 @@ def check_enum(expr, info): check_if(member, info, source) =20 =20 -def check_struct(expr, info): +def check_struct(expr: _JSONObject, info: QAPISourceInfo) -> None: name =3D cast(str, expr['struct']) # Asserted in check_exprs members =3D expr['data'] =20 @@ -266,7 +284,7 @@ def check_struct(expr, info): check_type(expr.get('base'), info, "'base'") =20 =20 -def check_union(expr, info): +def check_union(expr: _JSONObject, info: QAPISourceInfo) -> None: name =3D cast(str, expr['union']) # Asserted in check_exprs base =3D expr.get('base') discriminator =3D expr.get('discriminator') @@ -294,7 +312,7 @@ def check_union(expr, info): check_type(value['type'], info, source, allow_array=3Dnot base) =20 =20 -def check_alternate(expr, info): +def check_alternate(expr: _JSONObject, info: QAPISourceInfo) -> None: members =3D expr['data'] =20 if not members: @@ -311,7 +329,7 @@ def check_alternate(expr, info): check_type(value['type'], info, source) =20 =20 -def check_command(expr, info): +def check_command(expr: _JSONObject, info: QAPISourceInfo) -> None: args =3D expr.get('data') rets =3D expr.get('returns') boxed =3D expr.get('boxed', False) @@ -322,7 +340,7 @@ def check_command(expr, info): check_type(rets, info, "'returns'", allow_array=3DTrue) =20 =20 -def check_event(expr, info): +def check_event(expr: _JSONObject, info: QAPISourceInfo) -> None: args =3D expr.get('data') boxed =3D expr.get('boxed', False) =20 @@ -331,7 +349,7 @@ def check_event(expr, info): check_type(args, info, "'data'", allow_dict=3Dnot boxed) =20 =20 -def check_exprs(exprs): +def check_exprs(exprs: List[_JSONObject]) -> List[_JSONObject]: for expr_elem in exprs: # Expression assert isinstance(expr_elem['expr'], dict) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 0a000d58b3..7797c83432 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -8,11 +8,6 @@ disallow_untyped_defs =3D False disallow_incomplete_defs =3D False check_untyped_defs =3D False =20 -[mypy-qapi.expr] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False - [mypy-qapi.parser] disallow_untyped_defs =3D False disallow_incomplete_defs =3D False --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653286; cv=none; d=zohomail.com; s=zohoarc; b=ZbT0Umr6HEaGSQppbyoEULG1yBbLpk+DWfHDN0UW+mAC6wUtD83gdQyChQHlN27Y3II+rtAgONLN0zEkqs2Zkw0ayC8/cXY3bx7mCY4BDaYOH6tG6ELrlvlJ41MnS+XULxfam1QEOBejO8jgJisywNEEilNtU+a4mNsGHBlrweE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653286; 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=TdamAa9AfKk/OtdPcRGYeLifp/ymGMMqaHUuLfUorVY=; b=lsqeSeu02yH5EdwYLb1Km5uS3ZtmQGQNWm75/a+NfRLuvj98E4s+HM5+o2XWqNT51LRD492268yIiK4oXE78K0PdX/eg8ROcxHsXKz4+jo1A/UDrdZ4moxW80E+mYdLAonNEl92tqgFC8CYfnqTW5mt+mOg5FfQZne0b9t6JMLc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 161665328679918.31333986769016; Wed, 24 Mar 2021 23:21:26 -0700 (PDT) Received: from localhost ([::1]:58856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJMz-0005wE-G4 for importer@patchew.org; Thu, 25 Mar 2021 02:21:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39922) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6T-0002Lv-HY for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59457) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6Q-0008U5-Uo for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04: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-367-QJxxawoxOcObhkLvg8ISfw-1; Thu, 25 Mar 2021 02:04:16 -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 867E31083E80; Thu, 25 Mar 2021 06:04:15 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBC27866C7; Thu, 25 Mar 2021 06:04:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652258; 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=TdamAa9AfKk/OtdPcRGYeLifp/ymGMMqaHUuLfUorVY=; b=GfHuFJcDc9fz13kHSe/cV5LbvuMdTnnDtk/XS8d3uBlKiFdiG0q3EXcWqQSHaGp098zCxS JWD8S10w40ne9f7DEBALgd/oC3E+FEhjC6zK6CKAHeqvF4Y8wDpv/buzzz0jBX0cKZCrXv YnKH0icdtwi2ll/HCx37j9YAjmT8vD0= X-MC-Unique: QJxxawoxOcObhkLvg8ISfw-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 13/19] qapi/expr.py: Consolidate check_if_str calls in check_if Date: Thu, 25 Mar 2021 02:03:50 -0400 Message-Id: <20210325060356.4040114-14-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is a small rewrite to address some minor style nits. Don't compare against the empty list to check for the empty condition, and move the normalization forward to unify the check on the now-normalized structure. With the check unified, the local nested function isn't needed anymore and can be brought down into the normal flow of the function. With the nesting level changed, shuffle the error strings around a bit to get them to fit in 79 columns. Note: although ifcond is typed as Sequence[str] elsewhere, we *know* that the parser will produce real, bona-fide lists. It's okay to check isinstance(ifcond, list) here. Signed-off-by: John Snow --- scripts/qapi/expr.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index ea9d39fcf2..5921fa34ab 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -144,30 +144,26 @@ def check_flags(expr: _JSONObject, info: QAPISourceIn= fo) -> None: =20 def check_if(expr: _JSONObject, info: QAPISourceInfo, source: str) -> None: =20 - def check_if_str(ifcond: object) -> None: - if not isinstance(ifcond, str): - raise QAPISemError( - info, - "'if' condition of %s must be a string or a list of string= s" - % source) - if ifcond.strip() =3D=3D '': - raise QAPISemError( - info, - "'if' condition '%s' of %s makes no sense" - % (ifcond, source)) - ifcond =3D expr.get('if') if ifcond is None: return + if isinstance(ifcond, list): - if ifcond =3D=3D []: + if not ifcond: raise QAPISemError( - info, "'if' condition [] of %s is useless" % source) - for elt in ifcond: - check_if_str(elt) + info, f"'if' condition [] of {source} is useless") else: - check_if_str(ifcond) - expr['if'] =3D [ifcond] + # Normalize to a list + ifcond =3D expr['if'] =3D [ifcond] + + for elt in ifcond: + if not isinstance(elt, str): + raise QAPISemError(info, ( + f"'if' condition of {source}" + " must be a string or a list of strings")) + if not elt.strip(): + raise QAPISemError( + info, f"'if' condition '{elt}' of {source} makes no sense") =20 =20 def normalize_members(members: object) -> None: --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653628; cv=none; d=zohomail.com; s=zohoarc; b=V+EpH7zfop9BkP/jJO8KGbtSwouw5bdRwKu4DoBI3rn6i3I6kYi1oQxHsmVW9xBr516NrvyQOaIo658cSOOuiNp0WCcfqQW6/47Srk5LimwOJcaozTJAaQxMSL9maUWQc/4wx91hdVHtyBoCO8sDIKA9sFljkW500/RZbq9wDik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653628; 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=Sw7R1cBgJixnLWr9WuPasbIbALSCCoW/WdvKs56ryik=; b=dvjZtmOBb4HZMTOUeGrcwjuO4nB2kvLLP9FeByTGwSRSkJ8fM7Jq7FgP3zaaWjhmju6Q60+Frp3LEdBaXxvQCFExEgA49g17QwrM5SG7I7OKpkONHyn22qG+ccCYpMNaRPrzHfIzwPuXjThuBHjDJiHwpz6pKUbEYgRg9U5i+2E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616653628084190.9140328418864; Wed, 24 Mar 2021 23:27:08 -0700 (PDT) Received: from localhost ([::1]:39170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJRz-00018P-OX for importer@patchew.org; Thu, 25 Mar 2021 02:26:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6a-0002RJ-QV for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34832) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6U-0008Vh-Tk for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04: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-374-qZos7H-rOhe4vjgLr3MYPQ-1; Thu, 25 Mar 2021 02:04:17 -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 533168042BE; Thu, 25 Mar 2021 06:04:16 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id A75FC866C7; Thu, 25 Mar 2021 06:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652261; 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=Sw7R1cBgJixnLWr9WuPasbIbALSCCoW/WdvKs56ryik=; b=J/iiPEqnQyp8x0kkZW/w47gfJ18tuaF5l8zFbdkNSLOySua1bJHg0WDBdCxu4vABQX0KCn czbOkkB+G2jL+/3vX1AiuuOGnFexCIZx0GY1+mVNlPolt8aCVKO9znnBipKASo2fhrp5iU 1/12ZyH6RhF6q51cY0JIH2J/tMObwWU= X-MC-Unique: qZos7H-rOhe4vjgLr3MYPQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 14/19] qapi/expr.py: Remove single-letter variable Date: Thu, 25 Mar 2021 02:03:51 -0400 Message-Id: <20210325060356.4040114-15-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow --- scripts/qapi/expr.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 5921fa34ab..1869ddf815 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -233,14 +233,14 @@ def check_features(features: Optional[object], raise QAPISemError(info, "'features' must be an array") features[:] =3D [f if isinstance(f, dict) else {'name': f} for f in features] - for f in features: + for feat in features: source =3D "'features' member" - assert isinstance(f, dict) - check_keys(f, info, source, ['name'], ['if']) - check_name_is_str(f['name'], info, source) - source =3D "%s '%s'" % (source, f['name']) - check_name_lower(f['name'], info, source) - check_if(f, info, source) + assert isinstance(feat, dict) + check_keys(feat, info, source, ['name'], ['if']) + check_name_is_str(feat['name'], info, source) + source =3D "%s '%s'" % (source, feat['name']) + check_name_str(feat['name'], info, source) + check_if(feat, info, source) =20 =20 def check_enum(expr: _JSONObject, info: QAPISourceInfo) -> None: --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653799; cv=none; d=zohomail.com; s=zohoarc; b=k65yh0Pl6pelDrhYPJcHsI5ver7PM1dlEjJAz7yfKvSltsZLERpgu4gDzXCiD5sYWFa2rsRIevxXKGFvlt5T4i1QlkUAK7wS+g02K5R55EVppE8mQEJ9RaJBAvtbvVwN+MOEFvFT1AdyIb3sPfSAsrFuW4LX4P065PbOBWuiDgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653799; 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=tfmpS3Re5ITk9mmkshYgSMcA0qFs6+LSCkK6Q4krYis=; b=BZpZCfzVXyqPDmReGyia76YbIIwLBU6K5wE+LoOcyjJTdMxwaWP3gB1Xz7VoMERHPpw0eP4gnw0oAmYomfFvj+OwgVmcebCBqk21HsSv8CvEkw414El84dmFnuRkcsCqdP7MCr4tu4GhmAQL68BRJsIk86XG+FWUmhgZJ9Qklr0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616653799769745.8040790110878; Wed, 24 Mar 2021 23:29:59 -0700 (PDT) Received: from localhost ([::1]:46696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJVG-0004Jf-WC for importer@patchew.org; Thu, 25 Mar 2021 02:29:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6X-0002OP-Me for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49525) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6T-0008VV-8Y for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-558-ZjhKdHBwPJiIuHXwx9n1QQ-1; Thu, 25 Mar 2021 02:04:17 -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 20E8E57083; Thu, 25 Mar 2021 06:04:17 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73065866C7; Thu, 25 Mar 2021 06:04:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652260; 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=tfmpS3Re5ITk9mmkshYgSMcA0qFs6+LSCkK6Q4krYis=; b=FfBhVD5Lxvx9DV0Ok1Q8nojnkxpnqKGaQvy+aKyDD2ePHYCDQwJcK69kAGp7ff0o+qe0Jb rgo45qs2Zr+llWlZ21MrkdNyqDafgKDEC/Obt+DxK3AwjHwDICnSCu/WX3ygPX8uAqWb// BeGmX+q4RrcMHGfJ0vagEI8JeWuwYQk= X-MC-Unique: ZjhKdHBwPJiIuHXwx9n1QQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 15/19] qapi/expr.py: enable pylint checks Date: Thu, 25 Mar 2021 02:03:52 -0400 Message-Id: <20210325060356.4040114-16-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Tested-by: Eduardo Habkost Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa --- scripts/qapi/pylintrc | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index b9e077a164..fb0386d529 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -3,7 +3,6 @@ # Add files or directories matching the regex patterns to the ignore list. # The regex matches against base names, not paths. ignore-patterns=3Derror.py, - expr.py, parser.py, schema.py, =20 --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653635; cv=none; d=zohomail.com; s=zohoarc; b=cy3+F37p6zTQ4mt6QgmZR7HeF5Nji7/58oSCRK2kIY/c02DaHQERcHS0PJOvNADIM+tF7IlhDmHpfche112mKWHPFKe/phwdXZLqhoG+IDFOMFaCUNtnzle+Vqer5YD43y2pCuCHIZuE4b2N4bS9U1/KH5Qsb+VBDkVxQ7Y5nY0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653635; 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=uJKIJ7AXKxuI3sRTJyCpBd3E+6nNoM2l+w/8vBuVWJg=; b=BYOdZ4D/d3STz8lQMZ5s3mI+vSRtacFGX3T57ZL7MK4PXODU2M533g4CUHzcpJX9ZZoSy5ps2CcP6ij2/sf5bEWzNfiAnX5XVmJCZzA8QKQhyIiUfBT1IZ0/5fArgXTka8II/j8X1PAHUJA9ILFAdP7C5/WupW9WKuYMIQwB6/M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616653635560233.48016379501735; Wed, 24 Mar 2021 23:27:15 -0700 (PDT) Received: from localhost ([::1]:39402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJS6-0001Eb-7p for importer@patchew.org; Thu, 25 Mar 2021 02:26:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6X-0002OO-H4 for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26794) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6T-0008VZ-FI for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:25 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-157-nNtAw6OPMDuwzYWz7Raiyg-1; Thu, 25 Mar 2021 02:04:18 -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 DCA0E801817; Thu, 25 Mar 2021 06:04:17 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44168866C7; Thu, 25 Mar 2021 06:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652260; 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=uJKIJ7AXKxuI3sRTJyCpBd3E+6nNoM2l+w/8vBuVWJg=; b=YxXfy1SIOCDR3y7DOPYPP+yA0HNoUuYeC+0SbUt2OOZBzicQVFmMb8i2FWPJ3W6/aBDQdA A7ZUiqM8E7RH/sr4CXXQh/UyO0c+Igx1H2amKcrg9MaOC+SGxSv2Xv4x0zWLOkfr9MlcQu eleoSIO8JSDVX1qRYPgvCUHkvVOPsUY= X-MC-Unique: nNtAw6OPMDuwzYWz7Raiyg-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 16/19] qapi/expr.py: Add docstrings Date: Thu, 25 Mar 2021 02:03:53 -0400 Message-Id: <20210325060356.4040114-17-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow --- scripts/qapi/expr.py | 213 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 208 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 1869ddf815..adc5b903bc 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- # -# Check (context-free) QAPI schema expression structure -# # Copyright IBM, Corp. 2011 # Copyright (c) 2013-2019 Red Hat Inc. # @@ -14,6 +12,25 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 +""" +Normalize and validate (context-free) QAPI schema expression structures. + +After QAPI expressions are parsed from disk, they are stored in +recursively nested Python data structures using Dict, List, str, bool, +and int. This module ensures that those nested structures have the +correct type(s) and key(s) where appropriate for the QAPI context-free +grammar. + +The QAPI schema expression language allows for syntactic sugar; this +module also handles the normalization process of these nested +structures. + +See `check_exprs` for the main entry point. + +See `schema.QAPISchema` for processing into native Python data +structures and contextual semantic validation. +""" + import re from typing import ( Collection, @@ -31,9 +48,10 @@ from .source import QAPISourceInfo =20 =20 -# Deserialized JSON objects as returned by the parser; -# The values of this mapping are not necessary to exhaustively type -# here, because the purpose of this module is to interrogate that type. +#: Deserialized JSON objects as returned by the parser. +#: +#: The values of this mapping are not necessary to exhaustively type +#: here, because the purpose of this module is to interrogate that type. _JSONObject =3D Dict[str, object] =20 =20 @@ -48,11 +66,29 @@ def check_name_is_str(name: object, info: QAPISourceInfo, source: str) -> None: + """Ensures that ``name`` is a string.""" if not isinstance(name, str): raise QAPISemError(info, "%s requires a string name" % source) =20 =20 def check_name_str(name: str, info: QAPISourceInfo, source: str) -> str: + """ + Ensures a string is a legal name. + + A legal name consists of ascii letters, digits, ``-``, and ``_``, + starting with a letter. The names of downstream extensions are + prefixed with an __com.example_ style prefix, allowing ``.`` and + ``-``. An experimental name is prefixed with ``x-``, following the + RFQDN if present. + + A legal name cannot start with ``q_``, which is reserved. + + :param name: Name to check. + :param info: QAPI source file information. + :param source: Human-readable str describing "what" this name is. + + :return: The stem of the valid name, with no prefixes. + """ # Reserve the entire 'q_' namespace for c_name(), and for 'q_empty' # and 'q_obj_*' implicit type names. match =3D valid_name.match(name) @@ -62,6 +98,12 @@ def check_name_str(name: str, info: QAPISourceInfo, sour= ce: str) -> str: =20 =20 def check_name_upper(name: str, info: QAPISourceInfo, source: str) -> None: + """ + Ensures a string is a legal event name. + + Checks the same criteria as `check_name_str`, but requires uppercase + and prohibits ``-``. + """ stem =3D check_name_str(name, info, source) if re.search(r'[a-z-]', stem): raise QAPISemError( @@ -71,6 +113,15 @@ def check_name_upper(name: str, info: QAPISourceInfo, s= ource: str) -> None: def check_name_lower(name: str, info: QAPISourceInfo, source: str, permit_upper: bool =3D False, permit_underscore: bool =3D False) -> None: + """ + Ensures a string is a legal user defined type name. + + Checks the same criteria as `check_name_str`, but may impose + additional constraints. + + :param permit_upper: Prohibits uppercase when false. + :param permit_underscore: Prohibits underscores when false. + """ stem =3D check_name_str(name, info, source) if ((not permit_upper and re.search(r'[A-Z]', stem)) or (not permit_underscore and '_' in stem)): @@ -79,12 +130,31 @@ def check_name_lower(name: str, info: QAPISourceInfo, = source: str, =20 =20 def check_name_camel(name: str, info: QAPISourceInfo, source: str) -> None: + """ + Ensures a string is a legal CamelCase name. + + Checks the same criteria as `check_name_str`, + but additionally imposes a CamelCase constraint. + """ stem =3D check_name_str(name, info, source) if not re.match(r'[A-Z][A-Za-z0-9]*[a-z][A-Za-z0-9]*$', stem): raise QAPISemError(info, "name of %s must use CamelCase" % source) =20 =20 def check_defn_name_str(name: str, info: QAPISourceInfo, meta: str) -> Non= e: + """ + Ensures a name is a legal definition name. + + - 'event' names adhere to `check_name_upper`. + - 'command' names adhere to `check_name_lower`. + - All other names adhere to `check_name_camel`. + + All name types must not end with ``Kind`` nor ``List``. + + :param name: Name to check. + :param info: QAPI source file information. + :param meta: Type name of the QAPI expression. + """ if meta =3D=3D 'event': check_name_upper(name, info, meta) elif meta =3D=3D 'command': @@ -103,6 +173,15 @@ def check_keys(value: _JSONObject, source: str, required: Collection[str], optional: Collection[str]) -> None: + """ + Ensures an object has a specific set of keys. + + :param value: The object to check. + :param info: QAPI source file information. + :param source: Human-readable str describing this value. + :param required: Keys that *must* be present. + :param optional: Keys that *may* be present. + """ =20 def pprint(elems: Iterable[str]) -> str: return ', '.join("'" + e + "'" for e in sorted(elems)) @@ -125,6 +204,12 @@ def pprint(elems: Iterable[str]) -> str: =20 =20 def check_flags(expr: _JSONObject, info: QAPISourceInfo) -> None: + """ + Ensures common fields in an expression are correct. + + :param expr: Expression to validate. + :param info: QAPI source file information. + """ for key in ['gen', 'success-response']: if key in expr and expr[key] is not False: raise QAPISemError( @@ -143,7 +228,22 @@ def check_flags(expr: _JSONObject, info: QAPISourceInf= o) -> None: =20 =20 def check_if(expr: _JSONObject, info: QAPISourceInfo, source: str) -> None: + """ + Syntactically validate and normalize the ``if`` field of an object. =20 + The ``if`` field may be either a ``str`` or a ``List[str]``. + A ``str`` element will be normalized to ``List[str]``. + + :forms: + :sugared: ``Union[str, List[str]]`` + :canonical: ``List[str]`` + + :param expr: A ``dict``. + The ``if`` field, if present, will be validated. + :param info: QAPI source file information. + + :return: None, ``expr`` is normalized in-place as needed. + """ ifcond =3D expr.get('if') if ifcond is None: return @@ -167,6 +267,20 @@ def check_if(expr: _JSONObject, info: QAPISourceInfo, = source: str) -> None: =20 =20 def normalize_members(members: object) -> None: + """ + Normalize a "members" value. + + If ``members`` is an object, for every value in that object, if that + value is not itself already an object, normalize it to + ``{'type': value}``. + + :forms: + :sugared: ``Dict[str, Union[str, TypeRef]]`` + :canonical: ``Dict[str, TypeRef]`` + + :param members: The members object to normalize. + :return: None, ``members`` is normalized in-place as needed. + """ if isinstance(members, dict): for key, arg in members.items(): if isinstance(arg, dict): @@ -179,6 +293,23 @@ def check_type(value: Optional[object], source: str, allow_array: bool =3D False, allow_dict: Union[bool, str] =3D False) -> None: + """ + Check the QAPI type of ``value``. + + Python types of ``str`` or ``None`` are always allowed. + + :param value: The value to check. + :param info: QAPI Source file information. + :param source: Human-readable str describing this value. + :param allow_array: Allow a ``List[str]`` of length 1, + which indicates an Array type. + :param allow_dict: Allow a dict, treated as an anonymous type. + When given a string, check if that name is + allowed to have keys that use uppercase letters, + and modify validation accordingly. + + :return: None, ``value`` is normalized in-place as needed. + """ if value is None: return =20 @@ -227,6 +358,21 @@ def check_type(value: Optional[object], =20 def check_features(features: Optional[object], info: QAPISourceInfo) -> None: + """ + Syntactically validate and normalize the ``features`` field. + + ``features`` may be a ``list`` of either ``str`` or ``dict``. + Any ``str`` element will be normalized to ``{'name': element}``. + + :forms: + :sugared: ``List[Union[str, Feature]]`` + :canonical: ``List[Feature]`` + + :param features: an optional list of either str or dict. + :param info: QAPI Source file information. + + :return: None, ``features`` is normalized in-place as needed. + """ if features is None: return if not isinstance(features, list): @@ -244,6 +390,14 @@ def check_features(features: Optional[object], =20 =20 def check_enum(expr: _JSONObject, info: QAPISourceInfo) -> None: + """ + Validate this expression as an ``enum`` definition. + + :param expr: The expression to validate. + :param info: QAPI source file information. + + :return: None, ``expr`` is normalized in-place as needed. + """ name =3D expr['enum'] members =3D expr['data'] prefix =3D expr.get('prefix') @@ -273,6 +427,14 @@ def check_enum(expr: _JSONObject, info: QAPISourceInfo= ) -> None: =20 =20 def check_struct(expr: _JSONObject, info: QAPISourceInfo) -> None: + """ + Validate this expression as a ``struct`` definition. + + :param expr: The expression to validate. + :param info: QAPI source file information. + + :return: None, ``expr`` is normalized in-place as needed. + """ name =3D cast(str, expr['struct']) # Asserted in check_exprs members =3D expr['data'] =20 @@ -281,6 +443,14 @@ def check_struct(expr: _JSONObject, info: QAPISourceIn= fo) -> None: =20 =20 def check_union(expr: _JSONObject, info: QAPISourceInfo) -> None: + """ + Validate this expression as a ``union`` definition. + + :param expr: The expression to validate. + :param info: QAPI source file information. + + :return: None, ``expr`` is normalized in-place as needed. + """ name =3D cast(str, expr['union']) # Asserted in check_exprs base =3D expr.get('base') discriminator =3D expr.get('discriminator') @@ -309,6 +479,14 @@ def check_union(expr: _JSONObject, info: QAPISourceInf= o) -> None: =20 =20 def check_alternate(expr: _JSONObject, info: QAPISourceInfo) -> None: + """ + Validate this expression as an ``alternate`` definition. + + :param expr: The expression to validate. + :param info: QAPI source file information. + + :return: None, ``expr`` is normalized in-place as needed. + """ members =3D expr['data'] =20 if not members: @@ -326,6 +504,14 @@ def check_alternate(expr: _JSONObject, info: QAPISourc= eInfo) -> None: =20 =20 def check_command(expr: _JSONObject, info: QAPISourceInfo) -> None: + """ + Validate this expression as a ``command`` definition. + + :param expr: The expression to validate. + :param info: QAPI source file information. + + :return: None, ``expr`` is normalized in-place as needed. + """ args =3D expr.get('data') rets =3D expr.get('returns') boxed =3D expr.get('boxed', False) @@ -337,6 +523,14 @@ def check_command(expr: _JSONObject, info: QAPISourceI= nfo) -> None: =20 =20 def check_event(expr: _JSONObject, info: QAPISourceInfo) -> None: + """ + Normalize and validate this expression as an ``event`` definition. + + :param expr: The expression to validate. + :param info: QAPI source file information. + + :return: None, ``expr`` is normalized in-place as needed. + """ args =3D expr.get('data') boxed =3D expr.get('boxed', False) =20 @@ -346,6 +540,15 @@ def check_event(expr: _JSONObject, info: QAPISourceInf= o) -> None: =20 =20 def check_exprs(exprs: List[_JSONObject]) -> List[_JSONObject]: + """ + Validate and normalize a list of parsed QAPI schema expressions. + + This function accepts a list of expressions + metadta as returned by + the parser. It destructively normalizes the expressions in-place. + + :param exprs: The list of expressions to normalize/validate. + :return: The same list of expressions (now modified). + """ for expr_elem in exprs: # Expression assert isinstance(expr_elem['expr'], dict) --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653966; cv=none; d=zohomail.com; s=zohoarc; b=UyLcrTn+iSjL2K27yNBvIBuCoIC73QwY+ncHWccLANiAG8xH8GVxGKlE+AILUZIIfR9u2dG7d3he4iCrcaTF3/QJF5jUxMvjmFsaFfrOF3BdcZs28ZbgDKa2rNYSP5z2w7TawRabFhzkFkIwvMKfoaLPJPJ//kEuiF2LTpGChfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653966; 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=ur7AbEzWUaD40V36F5gxkTTTYwXhJb7hbq2QHyK9IC0=; b=bYHLzy8MTdTKyHwtAIwK8Aawm2kEwX0clQhJAn+AtGDfeVNOIcPXwocr0HMryA0fNDi6yal973YFVf5pcZv8DvD1BWpXw8Orf4lKKCk3t8x8tdmF6uUJ7GZpWu1kGTw/q8mKRllmA/wKRkMsBAJht4LDPdQBTLUdpLM8IUnZ3+c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616653966067373.7597912301509; Wed, 24 Mar 2021 23:32:46 -0700 (PDT) Received: from localhost ([::1]:52054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJXx-0006ez-51 for importer@patchew.org; Thu, 25 Mar 2021 02:32:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40000) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6Z-0002PH-Tt for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:42892) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6X-0008Vw-8V for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04: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-444-fYoGUuSUN5yem_yIb3PNGA-1; Thu, 25 Mar 2021 02:04:19 -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 A2147190B2A0; Thu, 25 Mar 2021 06:04:18 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C14988EE3; Thu, 25 Mar 2021 06:04:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652263; 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=ur7AbEzWUaD40V36F5gxkTTTYwXhJb7hbq2QHyK9IC0=; b=EJ5/895uX1UIkE+yrD3CEBsBSdLuICgbMwLahBs0uo6aRCu/joFYrKoa5d5HixJS+TZ3pk YRDGDIZ2BT5cUv874NndTf2/lE25IsNeAv8rRo+yqzYpTXcDt+XsBZ740MGjkKa/y2kZVZ ai5vJGyNgxCfSkHyYbhGW9vzxRklMfE= X-MC-Unique: fYoGUuSUN5yem_yIb3PNGA-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 17/19] qapi/expr.py: Use tuples instead of lists for static data Date: Thu, 25 Mar 2021 02:03:54 -0400 Message-Id: <20210325060356.4040114-18-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It is -- maybe -- possibly -- three nanoseconds faster. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa --- This can be dropped if desired; it has no real functional impact I could defend in code review court. I just happened to write it this way. Signed-off-by: John Snow --- scripts/qapi/expr.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index adc5b903bc..b11c11b965 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -210,11 +210,11 @@ def check_flags(expr: _JSONObject, info: QAPISourceIn= fo) -> None: :param expr: Expression to validate. :param info: QAPI source file information. """ - for key in ['gen', 'success-response']: + for key in ('gen', 'success-response'): if key in expr and expr[key] is not False: raise QAPISemError( info, "flag '%s' may only use false value" % key) - for key in ['boxed', 'allow-oob', 'allow-preconfig', 'coroutine']: + for key in ('boxed', 'allow-oob', 'allow-preconfig', 'coroutine'): if key in expr and expr[key] is not True: raise QAPISemError( info, "flag '%s' may only use true value" % key) --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616652625; cv=none; d=zohomail.com; s=zohoarc; b=EBPoomn4WmJijF45EYaSy4oXBBd4n6QzGffzGIqFUPegvYaFfPLtFPpfN2Z9an0gGAkwlxOxosq8WZZtxUSKCd/tnjKB2mPPYpi8QyXdTkm826R3TQ2+W4E73C0yywbkVylk/eVkw4pR1GQa1MQ64vW2eCL00nSk7Zz30eBGP5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616652625; 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=lgYU5vMVQfoS727bKbq0A9WBJWCRbRH3TZAp8X/5ul0=; b=FXn76weHwmymqIErJlf/cUrUJxpRtRoN1RruCR6KXulj2fwFyogzaS67vGoeHMn5DXKoORvO89Lk9Rbgpczs7dBbgerTwMMmiwsllpL18wsJl6z7/lGoF/EXZUBg58WQgATfV68bsaN5aUTFs7UdhBqCTjnR8vYK8Rmft+w6yX4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616652625784645.015326475929; Wed, 24 Mar 2021 23:10:25 -0700 (PDT) Received: from localhost ([::1]:34934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJ9w-0004GV-SN for importer@patchew.org; Thu, 25 Mar 2021 02:07:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6Z-0002OT-1O for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:42125) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6V-0008Vn-9A for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:26 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-211-2qd_7hatNLquwt1KP2WmXQ-1; Thu, 25 Mar 2021 02:04:20 -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 74B2B1083E80; Thu, 25 Mar 2021 06:04:19 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id C45B9866C7; Thu, 25 Mar 2021 06:04:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652262; 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=lgYU5vMVQfoS727bKbq0A9WBJWCRbRH3TZAp8X/5ul0=; b=HWo3duh8mqM4tA2rTCG1bgp/TXiX4Wn77nbuZObFioSwoTwcq5fHcpyvXaTjqBMPQEmxtH 47+2BcOqd/ZmfChhOjRH0qeRan5+tSzATAPaB9myBBtfMXh24+iM4jFDVodtv0kDSgaxMt oUrmUHGj9R17jknrOEGP6Dd1vhzUpXM= X-MC-Unique: 2qd_7hatNLquwt1KP2WmXQ-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 18/19] qapi/expr.py: move related checks inside check_xxx functions Date: Thu, 25 Mar 2021 02:03:55 -0400 Message-Id: <20210325060356.4040114-19-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There's not a big obvious difference between the types of checks that happen in the main function versus the kind that happen in the functions. Now they're in one place for each of the main types. As part of the move, spell out the required and optional keywords so they're obvious at a glance. Use tuples instead of lists for immutable data, too. Signed-off-by: John Snow Reviewed-by: Cleber Rosa --- scripts/qapi/expr.py | 55 ++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index b11c11b965..aabbc255d2 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -398,6 +398,10 @@ def check_enum(expr: _JSONObject, info: QAPISourceInfo= ) -> None: =20 :return: None, ``expr`` is normalized in-place as needed. """ + check_keys(expr, info, 'enum', + required=3D('enum', 'data'), + optional=3D('if', 'features', 'prefix')) + name =3D expr['enum'] members =3D expr['data'] prefix =3D expr.get('prefix') @@ -435,6 +439,11 @@ def check_struct(expr: _JSONObject, info: QAPISourceIn= fo) -> None: =20 :return: None, ``expr`` is normalized in-place as needed. """ + check_keys(expr, info, 'struct', + required=3D('struct', 'data'), + optional=3D('base', 'if', 'features')) + normalize_members(expr['data']) + name =3D cast(str, expr['struct']) # Asserted in check_exprs members =3D expr['data'] =20 @@ -451,6 +460,13 @@ def check_union(expr: _JSONObject, info: QAPISourceInf= o) -> None: =20 :return: None, ``expr`` is normalized in-place as needed. """ + check_keys(expr, info, 'union', + required=3D('union', 'data'), + optional=3D('base', 'discriminator', 'if', 'features')) + + normalize_members(expr.get('base')) + normalize_members(expr['data']) + name =3D cast(str, expr['union']) # Asserted in check_exprs base =3D expr.get('base') discriminator =3D expr.get('discriminator') @@ -487,6 +503,11 @@ def check_alternate(expr: _JSONObject, info: QAPISourc= eInfo) -> None: =20 :return: None, ``expr`` is normalized in-place as needed. """ + check_keys(expr, info, 'alternate', + required=3D('alternate', 'data'), + optional=3D('if', 'features')) + normalize_members(expr['data']) + members =3D expr['data'] =20 if not members: @@ -512,6 +533,13 @@ def check_command(expr: _JSONObject, info: QAPISourceI= nfo) -> None: =20 :return: None, ``expr`` is normalized in-place as needed. """ + check_keys(expr, info, 'command', + required=3D('command',), + optional=3D('data', 'returns', 'boxed', 'if', 'features', + 'gen', 'success-response', 'allow-oob', + 'allow-preconfig', 'coroutine')) + normalize_members(expr.get('data')) + args =3D expr.get('data') rets =3D expr.get('returns') boxed =3D expr.get('boxed', False) @@ -531,6 +559,11 @@ def check_event(expr: _JSONObject, info: QAPISourceInf= o) -> None: =20 :return: None, ``expr`` is normalized in-place as needed. """ + check_keys(expr, info, 'event', + required=3D('event',), + optional=3D('data', 'boxed', 'if', 'features')) + normalize_members(expr.get('data')) + args =3D expr.get('data') boxed =3D expr.get('boxed', False) =20 @@ -598,38 +631,16 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JS= ONObject]: "documentation comment required") =20 if meta =3D=3D 'enum': - check_keys(expr, info, meta, - ['enum', 'data'], ['if', 'features', 'prefix']) check_enum(expr, info) elif meta =3D=3D 'union': - check_keys(expr, info, meta, - ['union', 'data'], - ['base', 'discriminator', 'if', 'features']) - normalize_members(expr.get('base')) - normalize_members(expr['data']) check_union(expr, info) elif meta =3D=3D 'alternate': - check_keys(expr, info, meta, - ['alternate', 'data'], ['if', 'features']) - normalize_members(expr['data']) check_alternate(expr, info) elif meta =3D=3D 'struct': - check_keys(expr, info, meta, - ['struct', 'data'], ['base', 'if', 'features']) - normalize_members(expr['data']) check_struct(expr, info) elif meta =3D=3D 'command': - check_keys(expr, info, meta, - ['command'], - ['data', 'returns', 'boxed', 'if', 'features', - 'gen', 'success-response', 'allow-oob', - 'allow-preconfig', 'coroutine']) - normalize_members(expr.get('data')) check_command(expr, info) elif meta =3D=3D 'event': - check_keys(expr, info, meta, - ['event'], ['data', 'boxed', 'if', 'features']) - normalize_members(expr.get('data')) check_event(expr, info) else: assert False, 'unexpected meta type' --=20 2.30.2 From nobody Mon May 6 04:35:15 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616653782; cv=none; d=zohomail.com; s=zohoarc; b=WvSr0mWlbqKWlgP2U8Oc82E9Z9gRt8UT/Sq8LQ8PQrVEtbRHsrLjoa8KFH9yKWzW0+GPExSWqaxqIz2oEp7+1K9M+p4IQ29CMmef9xExP/nbgxyug7XtCOmOCLqHDyt/4V6WzVBiPsrPUS/Qj2KjMyWxutOdcFLo5zmJcMr/IT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616653782; 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=jitr1EUtQ1t43IwpfD9osXFT9H5RNaF+IKMQtxf0DMk=; b=RkBs8RJGd/YpYJ2McYFbYm1dxyoM2jwpUuFmMcisqT972f0ZdoDvlSakJwN65ao4bQ/JX/hA9G6BAdq/rYsbvUr5QGYvuKV/LYh6Or4wltKXC1m3AKhKdqd8VSlU03v9HRWBVvkj5BIq3fmCyKaP2T/guGCwvpGYLsTBEmTjTKg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1616653782673431.9257281974485; Wed, 24 Mar 2021 23:29:42 -0700 (PDT) Received: from localhost ([::1]:46076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lPJUy-00043s-7A for importer@patchew.org; Thu, 25 Mar 2021 02:29:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6b-0002ST-BM for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53626) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lPJ6X-0008WF-8B for qemu-devel@nongnu.org; Thu, 25 Mar 2021 02:04:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-213-fw-FPec3NnC14O3JOLX_0Q-1; Thu, 25 Mar 2021 02:04:21 -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 3385C87A826; Thu, 25 Mar 2021 06:04:20 +0000 (UTC) Received: from scv.redhat.com (ovpn-117-181.rdu2.redhat.com [10.10.117.181]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B427866C7; Thu, 25 Mar 2021 06:04:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616652263; 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=jitr1EUtQ1t43IwpfD9osXFT9H5RNaF+IKMQtxf0DMk=; b=CTgqW/PuVZdGoA35g+hC4PysvmXA4Wfpo/r99eU/JvwKibjghwv6e8CkKZwd3dOmQXTSb9 PM2mUk9vmFwgWuk8ZSYAAKVWTZ48Jet6nMVqNl0x3/g69gA+tUKXsUbwh1tuNPB9Z3OT64 X6RigIU4UOEOEfzsjwpAJSWWdRztTHg= X-MC-Unique: fw-FPec3NnC14O3JOLX_0Q-1 From: John Snow To: Markus Armbruster , qemu-devel@nongnu.org Subject: [PATCH v4 19/19] qapi/expr.py: Use an expression checker dispatch table Date: Thu, 25 Mar 2021 02:03:56 -0400 Message-Id: <20210325060356.4040114-20-jsnow@redhat.com> In-Reply-To: <20210325060356.4040114-1-jsnow@redhat.com> References: <20210325060356.4040114-1-jsnow@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=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: Michael Roth , John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This enforces a type signature against all of the top-level expression check routines without necessarily needing to create some overcomplicated class hierarchy for them. Signed-off-by: John Snow --- scripts/qapi/expr.py | 63 +++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index aabbc255d2..c42d061e68 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -31,8 +31,10 @@ structures and contextual semantic validation. """ =20 +from enum import Enum import re from typing import ( + Callable, Collection, Dict, Iterable, @@ -572,6 +574,29 @@ def check_event(expr: _JSONObject, info: QAPISourceInf= o) -> None: check_type(args, info, "'data'", allow_dict=3Dnot boxed) =20 =20 +class ExpressionType(str, Enum): + INCLUDE =3D 'include' + ENUM =3D 'enum' + UNION =3D 'union' + ALTERNATE =3D 'alternate' + STRUCT =3D 'struct' + COMMAND =3D 'command' + EVENT =3D 'event' + + def __str__(self) -> str: + return str(self.value) + + +_CHECK_FN: Dict[str, Callable[[_JSONObject, QAPISourceInfo], None]] =3D { + 'enum': check_enum, + 'union': check_union, + 'alternate': check_alternate, + 'struct': check_struct, + 'command': check_command, + 'event': check_event, +} + + def check_exprs(exprs: List[_JSONObject]) -> List[_JSONObject]: """ Validate and normalize a list of parsed QAPI schema expressions. @@ -598,24 +623,16 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JS= ONObject]: assert tmp is None or isinstance(tmp, QAPIDoc) doc: Optional[QAPIDoc] =3D tmp =20 - if 'include' in expr: - continue - - if 'enum' in expr: - meta =3D 'enum' - elif 'union' in expr: - meta =3D 'union' - elif 'alternate' in expr: - meta =3D 'alternate' - elif 'struct' in expr: - meta =3D 'struct' - elif 'command' in expr: - meta =3D 'command' - elif 'event' in expr: - meta =3D 'event' + for kind in ExpressionType: + if kind in expr: + meta =3D kind + break else: raise QAPISemError(info, "expression is missing metatype") =20 + if meta =3D=3D ExpressionType.INCLUDE: + continue + check_name_is_str(expr[meta], info, "'%s'" % meta) name =3D cast(str, expr[meta]) info.set_defn(meta, name) @@ -630,21 +647,7 @@ def check_exprs(exprs: List[_JSONObject]) -> List[_JSO= NObject]: raise QAPISemError(info, "documentation comment required") =20 - if meta =3D=3D 'enum': - check_enum(expr, info) - elif meta =3D=3D 'union': - check_union(expr, info) - elif meta =3D=3D 'alternate': - check_alternate(expr, info) - elif meta =3D=3D 'struct': - check_struct(expr, info) - elif meta =3D=3D 'command': - check_command(expr, info) - elif meta =3D=3D 'event': - check_event(expr, info) - else: - assert False, 'unexpected meta type' - + _CHECK_FN[meta](expr, info) check_if(expr, info, meta) check_features(expr.get('features'), info) check_flags(expr, info) --=20 2.30.2