From patchwork Mon Sep 13 09:50:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 1527284 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=N0elxKwU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H7MNl02Mlz9sXV for ; Mon, 13 Sep 2021 19:57:59 +1000 (AEST) Received: from localhost ([::1]:53158 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPiiq-0002ya-NA for incoming@patchwork.ozlabs.org; Mon, 13 Sep 2021 05:57:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPic0-00007S-Fg for qemu-devel@nongnu.org; Mon, 13 Sep 2021 05:50:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32023) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPibv-00073y-3w for qemu-devel@nongnu.org; Mon, 13 Sep 2021 05:50:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631526646; 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=Ih3xKVtC8HRP3geypL4wwOximBaYMWR1t2LiU50XzGY=; b=N0elxKwUn9YJazMv2h46OQZ6oQ0HQNMoE8Vn6uraQTarkGmP7qcOxIQARmXwfHbdUZxCEn zflktNW0Do3jF3q7a8qx2hiqdDUK+nl57qhxC2GiDXKF+coYAimWxbS3lUgWDwz+DzwVcK cUgXt+l9gXPLbfUKWh4+OKVs2kpjiIY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-328-CmEcvYJ4NN6LAzohguJkmQ-1; Mon, 13 Sep 2021 05:50:44 -0400 X-MC-Unique: CmEcvYJ4NN6LAzohguJkmQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1455A1923768; Mon, 13 Sep 2021 09:50:44 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-14.ams2.redhat.com [10.36.112.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D61146A257; Mon, 13 Sep 2021 09:50:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6BB97113861E; Mon, 13 Sep 2021 11:50:38 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 1/5] qapi: Fix a botched type annotation Date: Mon, 13 Sep 2021 11:50:34 +0200 Message-Id: <20210913095038.3040776-2-armbru@redhat.com> In-Reply-To: <20210913095038.3040776-1-armbru@redhat.com> References: <20210913095038.3040776-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.393, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Mypy is unhappy: $ mypy --config-file=scripts/qapi/mypy.ini `git-ls-files scripts/qapi/\*py` scripts/qapi/common.py:208: error: Function is missing a return type annotation scripts/qapi/common.py:227: error: Returning Any from function declared to return "str" Messed up in commit ccea6a8637 "qapi: Factor common recursion out of cgen_ifcond(), docgen_ifcond()". Tidy up. Signed-off-by: Markus Armbruster Message-Id: <20210908045428.2689093-2-armbru@redhat.com> Reviewed-by: Marc-André Lureau --- scripts/qapi/common.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 5f8f76e5b2..c4d11b9637 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -205,7 +205,8 @@ def gen_ifcond(ifcond: Optional[Union[str, Dict[str, Any]]], cond_fmt: str, not_fmt: str, all_operator: str, any_operator: str) -> str: - def do_gen(ifcond: Union[str, Dict[str, Any]], need_parens: bool): + def do_gen(ifcond: Union[str, Dict[str, Any]], + need_parens: bool) -> str: if isinstance(ifcond, str): return cond_fmt % ifcond assert isinstance(ifcond, dict) and len(ifcond) == 1 From patchwork Mon Sep 13 09:50:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 1527279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iRiu1ifT; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H7MFw2Dgrz9sVw for ; Mon, 13 Sep 2021 19:52:04 +1000 (AEST) Received: from localhost ([::1]:37096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPid7-0000Gw-5d for incoming@patchwork.ozlabs.org; Mon, 13 Sep 2021 05:52:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44144) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPibz-00007Q-QM for qemu-devel@nongnu.org; Mon, 13 Sep 2021 05:50:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30458) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPibu-00073x-Vx for qemu-devel@nongnu.org; Mon, 13 Sep 2021 05:50:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631526646; 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=c/c/w4JMkB/UC3DnUfd6qzSk51gfpWLnv30yTdmTG3U=; b=iRiu1ifTdhWWynSsr2RplpQvN9BvF0dZwGBl9+At1UDDBjJEMHvjudWsqc11CuNEI79JJL RwFyFp7dubvFKzRc1R8Ou7AnKqtKem0p6oF+tNZ2/RBS/hwiyxgS8NbdhcT7vDeh+77tNr dIBA2vhXVJKCc3YUFnuAhiORnXmsCTY= 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-44-AQDaUHSmOOOyyOEEsJ0QGw-1; Mon, 13 Sep 2021 05:50:44 -0400 X-MC-Unique: AQDaUHSmOOOyyOEEsJ0QGw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0AEBA1923767; Mon, 13 Sep 2021 09:50:44 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-14.ams2.redhat.com [10.36.112.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D626F10013C1; Mon, 13 Sep 2021 09:50:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 6EE6911385C1; Mon, 13 Sep 2021 11:50:38 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 2/5] qapi: Drop Indentation.__bool__() Date: Mon, 13 Sep 2021 11:50:35 +0200 Message-Id: <20210913095038.3040776-3-armbru@redhat.com> In-Reply-To: <20210913095038.3040776-1-armbru@redhat.com> References: <20210913095038.3040776-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.393, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Intentation.__bool__() is not worth its keep: it has just one user, which can just as well check .__str__() instead. Signed-off-by: Markus Armbruster Message-Id: <20210908045428.2689093-3-armbru@redhat.com> Reviewed-by: Marc-André Lureau --- scripts/qapi/common.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index c4d11b9637..1d62c27fb7 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -142,10 +142,6 @@ def __str__(self) -> str: """Return the current indentation as a string of spaces.""" return ' ' * self._level - def __bool__(self) -> bool: - """True when there is a non-zero indentation.""" - return bool(self._level) - def increase(self, amount: int = 4) -> None: """Increase the indentation level by ``amount``, default 4.""" self._level += amount @@ -169,8 +165,9 @@ def cgen(code: str, **kwds: object) -> str: Obey `indent`, and strip `EATSPACE`. """ raw = code % kwds - if indent: - raw = re.sub(r'^(?!(#|$))', str(indent), raw, flags=re.MULTILINE) + pfx = str(indent) + if pfx: + raw = re.sub(r'^(?!(#|$))', pfx, raw, flags=re.MULTILINE) return re.sub(re.escape(EATSPACE) + r' *', '', raw) From patchwork Mon Sep 13 09:50:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 1527276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LX0IA6aI; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H7MFs4ssDz9sVw for ; Mon, 13 Sep 2021 19:52:00 +1000 (AEST) Received: from localhost ([::1]:36946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPid2-00008H-Ki for incoming@patchwork.ozlabs.org; Mon, 13 Sep 2021 05:51:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPic0-00007d-2X for qemu-devel@nongnu.org; Mon, 13 Sep 2021 05:50:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32364) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPibv-00073t-40 for qemu-devel@nongnu.org; Mon, 13 Sep 2021 05:50:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631526646; 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=VY8nXdKF++rgEXHDxaP6rVmtKqQYPp8Al1wjhdpx6WE=; b=LX0IA6aI4UE21HKzWhN4fNBp4ww4P+TN1B5HpDOvz4SSXQ/kEhCtIPjN2EqxxHXevQ/J26 K+a+HzkU5h0YsK3kRpfk6Mu3sNn6aId9R9RI+hQxQjKP8LEmugTCTZfB7X2rgF2eP+ec+O dSm12Y1c1EIse8J3yR14UcsJOJnfoIQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-NZOCrbsYPsGZvamOStK9iw-1; Mon, 13 Sep 2021 05:50:44 -0400 X-MC-Unique: NZOCrbsYPsGZvamOStK9iw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C27D7802947; Mon, 13 Sep 2021 09:50:43 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-14.ams2.redhat.com [10.36.112.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D63575C1D1; Mon, 13 Sep 2021 09:50:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7494B11385C3; Mon, 13 Sep 2021 11:50:38 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 3/5] qapi: Bury some unused code in class Indentation Date: Mon, 13 Sep 2021 11:50:36 +0200 Message-Id: <20210913095038.3040776-4-armbru@redhat.com> In-Reply-To: <20210913095038.3040776-1-armbru@redhat.com> References: <20210913095038.3040776-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.393, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" .__int__() has never been used. Drop it. .decrease() raises ArithmeticError when asked to decrease indentation level below zero. Nothing catches it. It's a programming error. Dumb down to assert. Signed-off-by: Markus Armbruster Message-Id: <20210908045428.2689093-4-armbru@redhat.com> Reviewed-by: Marc-André Lureau --- scripts/qapi/common.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py index 1d62c27fb7..489273574a 100644 --- a/scripts/qapi/common.py +++ b/scripts/qapi/common.py @@ -132,9 +132,6 @@ class Indentation: def __init__(self, initial: int = 0) -> None: self._level = initial - def __int__(self) -> int: - return self._level - def __repr__(self) -> str: return "{}({:d})".format(type(self).__name__, self._level) @@ -148,9 +145,7 @@ def increase(self, amount: int = 4) -> None: def decrease(self, amount: int = 4) -> None: """Decrease the indentation level by ``amount``, default 4.""" - if self._level < amount: - raise ArithmeticError( - f"Can't remove {amount:d} spaces from {self!r}") + assert amount <= self._level self._level -= amount From patchwork Mon Sep 13 09:50:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 1527278 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QjGOpFep; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H7MFt4nymz9sjJ for ; Mon, 13 Sep 2021 19:52:02 +1000 (AEST) Received: from localhost ([::1]:37006 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPid5-0000Bj-Rj for incoming@patchwork.ozlabs.org; Mon, 13 Sep 2021 05:51:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPic0-000080-Ol for qemu-devel@nongnu.org; Mon, 13 Sep 2021 05:50:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:49048) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPibv-00074H-Kj for qemu-devel@nongnu.org; Mon, 13 Sep 2021 05:50:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631526646; 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=aWJ1+qMZuVE1HEQOHLA/fWb79Jty5MZ57lUwzgr/ADM=; b=QjGOpFepQTSkSCSBbo4GV+wYKGnWBEyFEF5LGIfAEPC1QwiHiiFrDb2pqrmgyQOrqtJq+l 5I/lRLPyVYVT8EBx3O3tA9B4HfEKK0zCNSrkxKG9zcdaU6MvGko75Bp+QRVaekTT6NjcS0 p0x1ErI6GVudpkApdk/NMSq00TDAonQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-109-Y7uqJXr0Mlu0BvnqHVIe0g-1; Mon, 13 Sep 2021 05:50:45 -0400 X-MC-Unique: Y7uqJXr0Mlu0BvnqHVIe0g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 19424824FAB; Mon, 13 Sep 2021 09:50:44 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-14.ams2.redhat.com [10.36.112.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D61E45D9DD; Mon, 13 Sep 2021 09:50:39 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7590D1138526; Mon, 13 Sep 2021 11:50:38 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 4/5] tests/qapi-schema: Cover 'not' condition with empty argument Date: Mon, 13 Sep 2021 11:50:37 +0200 Message-Id: <20210913095038.3040776-5-armbru@redhat.com> In-Reply-To: <20210913095038.3040776-1-armbru@redhat.com> References: <20210913095038.3040776-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) DKIMWL_WL_HIGH=-0.393, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" We flag this, but the error message is bogus: bad-if-not.json:2: 'if' condition [] of struct is useless The next commit will fix it. Signed-off-by: Markus Armbruster Message-Id: <20210908045428.2689093-5-armbru@redhat.com> Reviewed-by: Marc-André Lureau --- tests/qapi-schema/bad-if-not.err | 2 ++ tests/qapi-schema/bad-if-not.json | 3 +++ tests/qapi-schema/bad-if-not.out | 0 tests/qapi-schema/meson.build | 1 + 4 files changed, 6 insertions(+) create mode 100644 tests/qapi-schema/bad-if-not.err create mode 100644 tests/qapi-schema/bad-if-not.json create mode 100644 tests/qapi-schema/bad-if-not.out diff --git a/tests/qapi-schema/bad-if-not.err b/tests/qapi-schema/bad-if-not.err new file mode 100644 index 0000000000..b3acdd679a --- /dev/null +++ b/tests/qapi-schema/bad-if-not.err @@ -0,0 +1,2 @@ +bad-if-not.json: In struct 'TestIfStruct': +bad-if-not.json:2: 'if' condition [] of struct is useless diff --git a/tests/qapi-schema/bad-if-not.json b/tests/qapi-schema/bad-if-not.json new file mode 100644 index 0000000000..9fdaacc47b --- /dev/null +++ b/tests/qapi-schema/bad-if-not.json @@ -0,0 +1,3 @@ +# check 'if not' with empy argument +{ 'struct': 'TestIfStruct', 'data': { 'foo': 'int' }, + 'if': { 'not': '' } } diff --git a/tests/qapi-schema/bad-if-not.out b/tests/qapi-schema/bad-if-not.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/qapi-schema/meson.build b/tests/qapi-schema/meson.build index 4697c070bc..6b2a4ce41a 100644 --- a/tests/qapi-schema/meson.build +++ b/tests/qapi-schema/meson.build @@ -43,6 +43,7 @@ schemas = [ 'bad-if-key.json', 'bad-if-keys.json', 'bad-if-list.json', + 'bad-if-not.json', 'bad-type-bool.json', 'bad-type-dict.json', 'bad-type-int.json', From patchwork Mon Sep 13 09:50:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 1527280 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NVDTnGro; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H7MK86wztz9sW4 for ; Mon, 13 Sep 2021 19:54:52 +1000 (AEST) Received: from localhost ([::1]:45184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPifq-0005r4-MU for incoming@patchwork.ozlabs.org; Mon, 13 Sep 2021 05:54:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPic0-00007h-5v for qemu-devel@nongnu.org; Mon, 13 Sep 2021 05:50:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30134) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPibv-000741-4x for qemu-devel@nongnu.org; Mon, 13 Sep 2021 05:50:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1631526646; 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=IszLxmNLRVkvuJ11uy2cGGtATxpF8YT7u4EJBLAz7lI=; b=NVDTnGroZsmpJw1imGRyfA8CV30890gpZn3lttQtQdhDd9Nwv9yqUi95DuLduYnpli5LQv 1ml/oQcmqfv8XJ5TBsHO5FeEIFUbo9Zjw2PTZsHTffwuncGdNBiJ7D77x213xenXQ1Tdxr oy+C5FS5m7js6qSwf3XJlaUSlYl5Gm4= 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-58-syt8uaFNMK-DCOvGeeXlhQ-1; Mon, 13 Sep 2021 05:50:45 -0400 X-MC-Unique: syt8uaFNMK-DCOvGeeXlhQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D30DEC1A7; Mon, 13 Sep 2021 09:50:44 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-14.ams2.redhat.com [10.36.112.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53D1960853; Mon, 13 Sep 2021 09:50:41 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 7B0E51138529; Mon, 13 Sep 2021 11:50:38 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PULL 5/5] qapi: Fix bogus error for 'if': { 'not': '' } Date: Mon, 13 Sep 2021 11:50:38 +0200 Message-Id: <20210913095038.3040776-6-armbru@redhat.com> In-Reply-To: <20210913095038.3040776-1-armbru@redhat.com> References: <20210913095038.3040776-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.393, 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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Markus Armbruster Message-Id: <20210908045428.2689093-6-armbru@redhat.com> Reviewed-by: Marc-André Lureau [check_infix()'s type hint fixed] --- scripts/qapi/expr.py | 21 +++++++++++++-------- tests/qapi-schema/bad-if-not.err | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index b62f0a3640..90bde501b0 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -293,17 +293,22 @@ def _check_if(cond: Union[str, object]) -> None: info, "'if' condition of %s has conflicting keys" % source) - oper, operands = next(iter(cond.items())) + if 'not' in cond: + _check_if(cond['not']) + elif 'all' in cond: + _check_infix('all', cond['all']) + else: + _check_infix('any', cond['any']) + + def _check_infix(operator: str, operands: object) -> None: + if not isinstance(operands, list): + raise QAPISemError( + info, + "'%s' condition of %s must be an array" + % (operator, source)) if not operands: raise QAPISemError( info, "'if' condition [] of %s is useless" % source) - - if oper == "not": - _check_if(operands) - return - if oper in ("all", "any") and not isinstance(operands, list): - raise QAPISemError( - info, "'%s' condition of %s must be an array" % (oper, source)) for operand in operands: _check_if(operand) diff --git a/tests/qapi-schema/bad-if-not.err b/tests/qapi-schema/bad-if-not.err index b3acdd679a..b33f5e16b8 100644 --- a/tests/qapi-schema/bad-if-not.err +++ b/tests/qapi-schema/bad-if-not.err @@ -1,2 +1,2 @@ bad-if-not.json: In struct 'TestIfStruct': -bad-if-not.json:2: 'if' condition [] of struct is useless +bad-if-not.json:2: 'if' condition '' of struct is not a valid identifier