From nobody Fri May 3 10:08:42 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=1600811100; cv=none; d=zohomail.com; s=zohoarc; b=eyumlYYU9irWKi7S98AT1ZGrEJzW6m4eL72AvNNbZuOqiuUTdhKYgwVt14hnNQVsab/EBrCGRu1Ho3pgCNUqWnKaM2xmoJHeoaJvbrbY4nMWxkFRpxBH+EVeiGNBXAjmq3lZMclkuajfkKebC0Zu2YUB29gKgkzp8v8Kp4wW1l8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811100; 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=l3aFvixgKbhP6pi+lbQ0yIOSVJdkTdzW2xDLUdXZuV8=; b=cRGA01Zlac1EV21NgV3I2XVrHKSEfZRzSuMB3T9zuIoCL7z9ruUysqwkaA8h/H2nNVnmcjIcaS8Ye6asEGxCwc94NyJ1Zij6Kmyih+4ZVjhwENSwv76g40YIgKlFZ+oKNl/eVFM4NMZa0Bxhfbsen2JlJrW2rwLLx03UXlKG+3k= 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 1600811100157520.2843916754099; Tue, 22 Sep 2020 14:45:00 -0700 (PDT) Received: from localhost ([::1]:48620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKq5q-0008Ph-T0 for importer@patchew.org; Tue, 22 Sep 2020 17:44:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbJ-0000mu-2J for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:53693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbE-0005zO-6j for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-178-mHUEAdzCMKaeLjYwBMKlvg-1; Tue, 22 Sep 2020 17:13:17 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 354D910BBEC3; Tue, 22 Sep 2020 21:13:16 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id F28FC614F5; Tue, 22 Sep 2020 21:13:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809199; 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=l3aFvixgKbhP6pi+lbQ0yIOSVJdkTdzW2xDLUdXZuV8=; b=WYNkLxObc2b41txYaVtHYVGqhVQk96lR9yu4YiiwaolJI/VOSPsT+ZYQ9x+loDZN+BcXa5 WJB4pEJNNBY+d9SZ5cieygr49D2/o9sDfA2SN4QSiEhw/wXQLD7LnJpvw76wpBG21NRGsT iJX7DP6qjGyMWvYxtnH5QoXw6lSRt+c= X-MC-Unique: mHUEAdzCMKaeLjYwBMKlvg-1 From: John Snow To: Markus Armbruster Subject: [PATCH 01/16] qapi/expr.py: Remove 'info' argument from nested check_if_str Date: Tue, 22 Sep 2020 17:12:58 -0400 Message-Id: <20200922211313.4082880-2-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- 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 03b31ecfc1..de659a54ad 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -96,7 +96,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, @@ -116,9 +116,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.26.2 From nobody Fri May 3 10:08:42 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=1600811178; cv=none; d=zohomail.com; s=zohoarc; b=DalbdUcMRIERIVvhPupuiE6BQLb0lag0R/uHBVT/1gW/1pXlkEnwxY+/F9aTBktwR8fWiEGla+fThtjR+MWIblQViCbmZHZvMV9aEfxNSRaUR0FYE0kz7lz28CmE/xb0imy7cWHztK+V9LcKaXnPfrcYD/aLmB5G+XVvXFZCWPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811178; 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=+WrFPzsy+W9bhbMiGBrTtDEjGrxRPAX22SwGQfV1s7E=; b=bRV7Dq12cJGzJ7jA4rO154KdmRzKDGGvcx1pkvbHzkMqJNueEcIo5W/OIBBxP/FbGGQJQxLKI6GmFN5K67UKJ+B8blM9ztxymqIH70ZPD0zyOvq/xWXmER86aGh12QOaHwn8bAQ6TM4pMviFvhragU60Q6+vLUgp/0Pjn8PsFPg= 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 1600811178370549.4941572312009; Tue, 22 Sep 2020 14:46:18 -0700 (PDT) Received: from localhost ([::1]:53596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKq76-00028w-Ro for importer@patchew.org; Tue, 22 Sep 2020 17:46:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39864) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbJ-0000n2-3n for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41686) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbG-000610-RV for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:24 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-361-yaT8vAfSPYamZX1BAx-GPw-1; Tue, 22 Sep 2020 17:13:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 631EE64088; Tue, 22 Sep 2020 21:13:17 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D88273682; Tue, 22 Sep 2020 21:13:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809201; 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=+WrFPzsy+W9bhbMiGBrTtDEjGrxRPAX22SwGQfV1s7E=; b=eKRutyIRp1ZFZiqL+SRc6gSed+/y7/P8xpek6ylL3IrPsdN9Dyh6As7v9vbJDvBvUNzT8I 4COoUwgB1UWgYAfNS6V4LvnyyhgMh250xT/oZWk7YEScIiAspsFTGY9ROi8Iy4y9BAvOwl 15rWDF8CO//EiHZy9kexI/GY10k8CuA= X-MC-Unique: yaT8vAfSPYamZX1BAx-GPw-1 From: John Snow To: Markus Armbruster Subject: [PATCH 02/16] qapi/expr.py: Check for dict instead of OrderedDict Date: Tue, 22 Sep 2020 17:12:59 -0400 Message-Id: <20200922211313.4082880-3-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- 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 de659a54ad..1872a8a3cc 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 collections import OrderedDict + from .common import c_name from .error import QAPISemError =20 @@ -123,7 +123,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 @@ -154,7 +154,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.26.2 From nobody Fri May 3 10:08:42 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=1600811481; cv=none; d=zohomail.com; s=zohoarc; b=bzFRagxEZ7m+QmgF+3VapirMmm/AMsTpbeYuTHa3Qyhc5ua8k7GDJJEQK63xUe2Sx4fxF4r9U8LGpo3yTTPoUGeomiQ83OYKWwnhcMfZGcHSvjdydaaHRBvvYY767D7vqyooKz1iYdy0Mr6qV+aa8D8K6qXH/ot+hJoULc9VtuU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811481; 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=OviiS+c/KqyWZoTO/aj83Q64YGN4t3Pv8SUuOosZ94s=; b=k8H5qJpLRISvKG88fsE6InczP6avVDpKFD+nDWmZEBsMfrt5L/WM43T6HfgYK+hDfn0dQNsow5gUMN6fR0Ie3GqRwlBMWRvUvcwCAkzx/hnU4VJCdA2zuohT/Vgr3SGYgTSid9d/LZuWhKsEJY3HjlY08cEKxv3lWoZf+80tb0k= 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 1600811481272958.6591967744542; Tue, 22 Sep 2020 14:51:21 -0700 (PDT) Received: from localhost ([::1]:42076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqBz-0000ex-PK for importer@patchew.org; Tue, 22 Sep 2020 17:51:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbK-0000qa-Di for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44132) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbI-00061d-Fh for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13: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-465-BLZwyfbjPA2zRgtjmq3AQw-1; Tue, 22 Sep 2020 17:13:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CE04919611A0; Tue, 22 Sep 2020 21:13:18 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id A13FE73689; Tue, 22 Sep 2020 21:13:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809203; 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=OviiS+c/KqyWZoTO/aj83Q64YGN4t3Pv8SUuOosZ94s=; b=gy+l62ArpM+Jw4lCgpm6VoVMUdrHmf40H3i75Mzv3w+dZ2lp3XICy8I2YXoEQxy+iMqFmR c3eFAOL55wwgL+/ixxfdrkp9BvPp/E9QllsUabP67Y/ow39Hvvqu+XTTpm+caEESAzuJuN doxeCf0oDBtyoYhr13GC60dls2nXFa4= X-MC-Unique: BLZwyfbjPA2zRgtjmq3AQw-1 From: John Snow To: Markus Armbruster Subject: [PATCH 03/16] qapi/expr.py: constrain incoming expression types Date: Tue, 22 Sep 2020 17:13:00 -0400 Message-Id: <20200922211313.4082880-4-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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 Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 1872a8a3cc..f6b55a87c1 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -15,9 +15,17 @@ # See the COPYING file in the top-level directory. =20 import re +from typing import MutableMapping, Optional =20 from .common import c_name from .error import QAPISemError +from .parser import QAPIDoc +from .source import QAPISourceInfo + + +# Expressions in their raw form are JSON-like structures with arbitrary fo= rms. +# Minimally, their top-level form must be a mapping of strings to values. +Expression =3D MutableMapping[str, object] =20 =20 # Names must be letters, numbers, -, and _. They must start with letter, @@ -280,9 +288,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) + expr: Expression =3D expr_elem['expr'] + for key in expr.keys(): + assert isinstance(key, str) + + # 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.26.2 From nobody Fri May 3 10:08:42 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=1600811322; cv=none; d=zohomail.com; s=zohoarc; b=OSArUhJbcf/L0Ioq+UmWO5wxT66el6IqavruFPFOfnoKc+c7kVHeB2hhXkFmeug7OZzIE1Y7/VjyWb6ByGp/gnpALlG3dW/tiI0w7LMePlHY3ViMleSAY1p0izhiMQIoeqNf1n4t40zQ78tpH0UNVFZHhmyH8DcHozf2+HYRjPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811322; 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=kiROWfsWIjfjZEiwsV7fIP+RW6PpLlCUtwamIXrMEmQ=; b=S4rFzTgExdvQI+EsitiZdPwJzI01sCugawQziA+2Zj5CX70vlHvllSv5ckMPvEQRvYzEPFejknUGvA3PHWx3CWvZBnOV/n5IA2jDN/ou5+qtNpe7YrAZTibOf0U8ln7EhFp+s4zwiI51qehYD9u/4Vq9sDVN5wK/++ny/ndcBZ0= 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 1600811322856134.47286735428042; Tue, 22 Sep 2020 14:48:42 -0700 (PDT) Received: from localhost ([::1]:33678 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKq9R-0005YA-Iw for importer@patchew.org; Tue, 22 Sep 2020 17:48:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39878) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbJ-0000oQ-M9 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:25 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36190) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbH-00061N-NI for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13: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-4-8R49_K1jPNSBPcTHcU4WiQ-1; Tue, 22 Sep 2020 17:13:20 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DBE2A64086; Tue, 22 Sep 2020 21:13:19 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0661173689; Tue, 22 Sep 2020 21:13:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809202; 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=kiROWfsWIjfjZEiwsV7fIP+RW6PpLlCUtwamIXrMEmQ=; b=GsgkRqSigQg7OJz2ARHLMbTeY/btcvasSR5SpeN172lM2iphfEq9PWfKX/C/yoh+JPqQ+L yEEtlQZCSlNIrf6R9VZUiL4X2hNtwQkEnieDsNqEp3oUpawKiy38i4wY8pTyW1x3kxAYzj IUQG6a2dOdT5yFS9K0SEwU4FoInJx54= X-MC-Unique: 8R49_K1jPNSBPcTHcU4WiQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 04/16] qapi/expr.py: Add assertion for union type 'check_dict' Date: Tue, 22 Sep 2020 17:13:01 -0400 Message-Id: <20200922211313.4082880-5-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- 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 f6b55a87c1..67892502e9 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -166,7 +166,9 @@ def check_type(value, info, source, raise QAPISemError(info, "%s should be an object or type name" % source) =20 - permit_upper =3D allow_dict in info.pragma.name_case_whitelist + permit_upper =3D False + if isinstance(allow_dict, str): + permit_upper =3D allow_dict in info.pragma.name_case_whitelist =20 # value is a dictionary, check that each member is okay for (key, arg) in value.items(): --=20 2.26.2 From nobody Fri May 3 10:08:42 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=1600810626; cv=none; d=zohomail.com; s=zohoarc; b=Gv5/nwsYLQGaLWOjZuDDjnviS1lEZWpw/M9B9DhjoMK/9XWNZOPc4CP9+G9J/+DoupJIgqGgXU0AG15SApMGAcUgSU+PEA3CnvQlY5GfNFlebIQt/Pl6VkylkNzmz5kMgWrrkivBhymJzJ9XtcpLB7KCTiIQVn3KaLCpCgUiW8c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810626; 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=FMPYL/Fj+O8VtFiDqOGxK2lFd9x8jB/8yhs9MnJy+mE=; b=MUE8nwvYDAqlZAPOPUP0UAOVM3KvXYR2aLvSO2job8OoJGXFpxU+h31X8N0w+/kVW3o/xq7nYtFxYz5PL/dr9J7GEAsWqDGmveLY7PrU7WAVqtn/vNIuOLdc5OyEpE4Sj1C1/YInnOCSIU9PBOT1Euh40rBgfRdTbGroytA30s0= 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 1600810626796923.790496673455; Tue, 22 Sep 2020 14:37:06 -0700 (PDT) Received: from localhost ([::1]:51838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpyD-0005sc-Eh for importer@patchew.org; Tue, 22 Sep 2020 17:37:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbK-0000rB-LD for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:52301) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbI-00061g-Tm for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13: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-252-AVT_yaSgP3SnIg_Sf6SG2g-1; Tue, 22 Sep 2020 17:13:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 46D8A64091; Tue, 22 Sep 2020 21:13:21 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1431873689; Tue, 22 Sep 2020 21:13:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809204; 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=FMPYL/Fj+O8VtFiDqOGxK2lFd9x8jB/8yhs9MnJy+mE=; b=NUrkQbuaJ4GeIJ04qSf5LpoFwYxCHdPtIRHWZDJFZpmJyez5oZ8MdfCwYdABPwNHuEdD2G WFHgSjeisGx0DPY2kwg0feKNEtucDNhSBiC1JZlMoFCTbnnYzGnZGniUNUsSscAScSQq+J 2hlWUx0eMAfVhG2EtdkhEUYJ8U3j3KE= X-MC-Unique: AVT_yaSgP3SnIg_Sf6SG2g-1 From: John Snow To: Markus Armbruster Subject: [PATCH 05/16] qapi/expr.py: move string check upwards in check_type Date: Tue, 22 Sep 2020 17:13:02 -0400 Message-Id: <20200922211313.4082880-6-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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's a simple case, shimmy the early return upwards. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- 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 67892502e9..3f5af5f5e4 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -143,6 +143,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: @@ -153,10 +157,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.26.2 From nobody Fri May 3 10:08:42 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=1600810785; cv=none; d=zohomail.com; s=zohoarc; b=apa/9rFjjVnp33mjMZ3jm7CmMUeaG9PpWKBXRAeutGb8T9T495zXL8gfOHz+q+OeP3OTgNvxI4Y+4pkYOI5mnlmPbIGJHAv/3bbVpqy0oPrmFLiosvVH4KIIfA/iNnCP7vt8kYHeqdIq+aAppD1XQRwghWbgaKSQLpIIOYBrxgo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810785; 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=s4wL7RgGXtDcB4iuiGvtvZNCWhMHLRgOAJBV493C44w=; b=ASofRGu/QvW5l2BAOkudjgIHROSDmsjOovy3Od0UoVpnynsfQJEW4+5fsfe4Mwj5HCTXJeYAk2qIXRoM39QJ4956Ct9V9fXQNHhoDkADT1IEnLjDBCm7tA/Q6gSwQd42opsU+uhaNomj9GEeazqGgNViQr1XV+qFun9x9WeUuFc= 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 1600810785694896.8114009710935; Tue, 22 Sep 2020 14:39:45 -0700 (PDT) Received: from localhost ([::1]:59912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKq0m-0001Aj-4q for importer@patchew.org; Tue, 22 Sep 2020 17:39:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39918) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbL-0000u7-O0 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:39664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbK-00061z-1A for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13: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-320-Y1P6nmWSMWuEF_9670yniA-1; Tue, 22 Sep 2020 17:13:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75CC88BF320; Tue, 22 Sep 2020 21:13:22 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BD17614F5; Tue, 22 Sep 2020 21:13:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809205; 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=s4wL7RgGXtDcB4iuiGvtvZNCWhMHLRgOAJBV493C44w=; b=XC7ZMfpvN6s5ou8xtH1QihlfFVTcbQ5AW4IgMakWCVDYIuucsPsNVq+0pP0QZ9IqqQ5KUu uxfqXofE73pfiLiZAjBeOacPBBujpzIPWwbrypaZYH9mjAkMIMgZY4Fc8UQLhv4g8aXvm5 PceGCGXeVm9J0/khIDXphQQmloAaJ/U= X-MC-Unique: Y1P6nmWSMWuEF_9670yniA-1 From: John Snow To: Markus Armbruster Subject: [PATCH 06/16] qapi/expr.py: Check type of 'data' member Date: Tue, 22 Sep 2020 17:13:03 -0400 Message-Id: <20200922211313.4082880-7-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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" Iterating over the members of data isn't going to work if it's not some form of dict anyway, but for type safety, formalize it. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 3f5af5f5e4..633f9b9172 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -247,6 +247,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 check_name_str(key, info, source) @@ -260,6 +263,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_str(key, info, source) --=20 2.26.2 From nobody Fri May 3 10:08:42 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=1600810925; cv=none; d=zohomail.com; s=zohoarc; b=Abxr8O21hF6VFHeuHOsmETbsYy9TKRkSbju6575MknCMsOb+R4/d3U9yFO91g/gNN84F7VLJzg6HsJP4zIt7eVSwjVcBqXPLvk/t53MNi/nyZpqFTTbyzMwlSozvGkwRk9uRjHoyk6lz8D5kXW5Q+nke8hxe5RzeFFiMtLn6Wzg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600810925; 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=IaMLC8He4A5gFWw6a7qBuxIZ30CJpWYe7mjR0+qBNoE=; b=lsBMs9EiZLPsbzruv1jl8zEa75j0mPkia71xWeyALTFYCyGkDZkKh5ePCaaqECtdRKBnT/Qn5SNH7j/Q2lZrhrIvQvV1IyYgOlmljGcUYlzx/XHXtuLkQznrvd0GBlPfV4wwh6oYmq7o7SbZ1yZ2cxx4ePpSaWL5t2C+AAXOnUA= 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 1600810925712777.0698183340659; Tue, 22 Sep 2020 14:42:05 -0700 (PDT) Received: from localhost ([::1]:39830 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKq32-0004iB-DJ for importer@patchew.org; Tue, 22 Sep 2020 17:42:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbM-0000wc-NI for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:33105) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbK-00062b-Tt for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13: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-515-RcmKZ5txMiuEt9i31lVobQ-1; Tue, 22 Sep 2020 17:13:24 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D44810BBECA; Tue, 22 Sep 2020 21:13:23 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0518614F5; Tue, 22 Sep 2020 21:13:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809206; 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=IaMLC8He4A5gFWw6a7qBuxIZ30CJpWYe7mjR0+qBNoE=; b=PexYHCGKF1Y3oiJPkneztscLoN2GBvOwV/+wx2/joqA8NfzZ4c/18T9Xs1CVfXMPUkwmGK s/ebqiwxfjVpZ7Y+hI1JmMhPoI6bHe1grRcJ3FifDq2PS+I1VoD+P7cwI/SupaLZ6B3q4y RZDh3RpcjBA7zSu2HCzZCKlm8sZ7fk8= X-MC-Unique: RcmKZ5txMiuEt9i31lVobQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 07/16] qapi/expr.py: Add casts in a few select cases Date: Tue, 22 Sep 2020 17:13:04 -0400 Message-Id: <20200922211313.4082880-8-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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". We don't need to assert that something is a str if we've already checked that it is -- use a cast instead for these cases. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 633f9b9172..4a3352a2bd 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -15,7 +15,11 @@ # See the COPYING file in the top-level directory. =20 import re -from typing import MutableMapping, Optional +from typing import ( + MutableMapping, + Optional, + cast, +) =20 from .common import c_name from .error import QAPISemError @@ -225,7 +229,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) @@ -233,7 +237,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'] @@ -330,7 +334,7 @@ def check_exprs(exprs): else: raise QAPISemError(info, "expression is missing metatype") =20 - name =3D expr[meta] + name =3D cast(str, expr[meta]) # asserted right below: check_name_is_str(name, info, "'%s'" % meta) info.set_defn(meta, name) check_defn_name_str(name, info, meta) --=20 2.26.2 From nobody Fri May 3 10:08:42 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=1600811666; cv=none; d=zohomail.com; s=zohoarc; b=AwO6vGGjVDZvbIoCg+0kmM7d0GGzgTMlwQxMVCB1J7TUHoTXLxd/pZe7OnONePHiGVuLdRvi75/R+gKmD9Kl2JMbZWSDodlFVNmdqA54YWn8hU4nZu3g/qT5efSAR4Q40gwnrF1e2qpRp2UBguIpnnNR48xmMaJc2/tPuXTxWM4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811666; 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=qvntVAw7UwIjWN4n9HMRaHDxuagSIVWP9zNN1NsSEL8=; b=ky4Y77Wxm2MBZfwwNR9b69igta5Vaak1DWWUjIKKPJ+tnrMVUWTxjXqE2FsZ7zRVPBkAeoF1Wzwhw/Eg14zo0ne/A5xP//tZ5YOQTGSLU630C4/pQ/sorjqNGgOraKBELkjShoc6JO8tFUfxES4CwnsTT2yoWZyV1EQWQKRqMY4= 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 1600811666070380.08960858944897; Tue, 22 Sep 2020 14:54:26 -0700 (PDT) Received: from localhost ([::1]:53734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqEy-0005PE-RB for importer@patchew.org; Tue, 22 Sep 2020 17:54:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbP-00012t-5z for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:26117) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbN-00063I-2L for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:30 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-569-ZBVXaUMgO4q0rl6R1uaKrQ-1; Tue, 22 Sep 2020 17:13:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0384C805EE4; Tue, 22 Sep 2020 21:13:25 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98462614F5; Tue, 22 Sep 2020 21:13:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809208; 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=qvntVAw7UwIjWN4n9HMRaHDxuagSIVWP9zNN1NsSEL8=; b=iH9JzcxOiSp0p/vXEwZSPCQsryqSWj5/TGKQnk7Dgeb0bSqSg9ORfh79JJa4ls0osZ5D49 XkhDQ8CriwqbaO2m9RtBWQY81UPjHJbUbNGfxOFZjGSV42J/v+6YfsnS0L7W2einEI+fZE MAuTMNAr7dZ7Nif7HRgMxqYnkPJIYWg= X-MC-Unique: ZBVXaUMgO4q0rl6R1uaKrQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 08/16] qapi/expr.py: add type hint annotations Date: Tue, 22 Sep 2020 17:13:05 -0400 Message-Id: <20200922211313.4082880-9-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 65 +++++++++++++++++++++++++++---------------- scripts/qapi/mypy.ini | 5 ---- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 4a3352a2bd..6b064a2138 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -16,8 +16,11 @@ =20 import re from typing import ( + Iterable, + List, MutableMapping, Optional, + Union, cast, ) =20 @@ -27,10 +30,11 @@ from .source import QAPISourceInfo =20 =20 -# Expressions in their raw form are JSON-like structures with arbitrary fo= rms. -# Minimally, their top-level form must be a mapping of strings to values. -Expression =3D MutableMapping[str, object] +# Arbitrary form for a JSON-like object. +_JSObject =3D MutableMapping[str, object] =20 +# Expressions in their raw form are (just) JSON-like objects. +Expression =3D _JSObject =20 # Names must be letters, numbers, -, and _. They must start with letter, # except for downstream extensions which must start with __RFQDN_. @@ -39,14 +43,19 @@ '[a-zA-Z][a-zA-Z0-9_-]*$') =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, - allow_optional=3DFalse, enum_member=3DFalse, - permit_upper=3DFalse): +def check_name_str(name: str, + info: QAPISourceInfo, + source: str, + allow_optional: bool =3D False, + enum_member: bool =3D False, + permit_upper: bool =3D False) -> None: membername =3D name =20 if allow_optional and name.startswith('*'): @@ -66,16 +75,20 @@ def check_name_str(name, info, source, assert not membername.startswith('*') =20 =20 -def check_defn_name_str(name, info, meta): +def check_defn_name_str(name: str, info: QAPISourceInfo, meta: str) -> Non= e: check_name_str(name, info, meta, permit_upper=3DTrue) if name.endswith('Kind') or name.endswith('List'): raise QAPISemError( 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: _JSObject, + info: QAPISourceInfo, + source: str, + required: List[str], + optional: List[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) @@ -95,7 +108,7 @@ def pprint(elems): pprint(unknown), pprint(allowed))) =20 =20 -def check_flags(expr, info): +def check_flags(expr: Expression, info: QAPISourceInfo) -> None: for key in ['gen', 'success-response']: if key in expr and expr[key] is not False: raise QAPISemError( @@ -106,9 +119,9 @@ def check_flags(expr, info): info, "flag '%s' may only use true value" % key) =20 =20 -def check_if(expr, info, source): +def check_if(expr: _JSObject, 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, @@ -134,7 +147,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): @@ -142,8 +155,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 @@ -187,7 +203,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): @@ -204,7 +221,7 @@ def check_features(features, info): check_if(f, info, source) =20 =20 -def check_enum(expr, info): +def check_enum(expr: Expression, info: QAPISourceInfo) -> None: name =3D expr['enum'] members =3D expr['data'] prefix =3D expr.get('prefix') @@ -228,7 +245,7 @@ def check_enum(expr, info): check_if(member, info, source) =20 =20 -def check_struct(expr, info): +def check_struct(expr: Expression, info: QAPISourceInfo) -> None: name =3D cast(str, expr['struct']) # Asserted in check_exprs members =3D expr['data'] =20 @@ -236,7 +253,7 @@ def check_struct(expr, info): check_type(expr.get('base'), info, "'base'") =20 =20 -def check_union(expr, info): +def check_union(expr: Expression, info: QAPISourceInfo) -> None: name =3D cast(str, expr['union']) # Asserted in check_exprs base =3D expr.get('base') discriminator =3D expr.get('discriminator') @@ -262,7 +279,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: Expression, info: QAPISourceInfo) -> None: members =3D expr['data'] =20 if not members: @@ -279,7 +296,7 @@ def check_alternate(expr, info): check_type(value['type'], info, source) =20 =20 -def check_command(expr, info): +def check_command(expr: Expression, info: QAPISourceInfo) -> None: args =3D expr.get('data') rets =3D expr.get('returns') boxed =3D expr.get('boxed', False) @@ -290,7 +307,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: Expression, info: QAPISourceInfo) -> None: args =3D expr.get('data') boxed =3D expr.get('boxed', False) =20 @@ -299,7 +316,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[_JSObject]) -> List[_JSObject]: 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 5ab3433c5f..0d0111930f 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -14,11 +14,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.26.2 From nobody Fri May 3 10:08:42 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=1600811231; cv=none; d=zohomail.com; s=zohoarc; b=EZtxeWvMMPR205TEc7kr3vvJZWct2Rj0yUng0boZF4e1Dh6PrV9T6nQHzwhSFdpgMlfyf37e6KNLsVsbaHrk97AmaGRSgJlXH6mCPagK8TVISbXdYAwXUc8ykEGt/ZIGuw2k3n84L28mOzBBJTEwLvCGL7WUmrMP7VGQstNpO6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811231; 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=3t3h9oDxjRXo+hECtZgRnukmRJ9G3Oo8Skvbxpet8Zc=; b=LsTYTiQGMskSRu3r4+mnCMDfY5U69lsDcTpCDrjlaWe3HnBHYTra0JLAzulqZ1GTvPAqE72zr3y5UbGwOiNj4idxQLY8EMd0KqkaqdOh1IaUh0OqDbyZXkOXuB0D9Iv4wrbYrQ7QET3O3emb6Iiid1zFj6jOE6frSlH9HIOXnmQ= 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 1600811231486623.6680443354219; Tue, 22 Sep 2020 14:47:11 -0700 (PDT) Received: from localhost ([::1]:57034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKq7y-0003YY-2l for importer@patchew.org; Tue, 22 Sep 2020 17:47:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbP-00014q-QN for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbO-00063U-6k for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:31 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-195-dvWLFTBYO9iIO7oiSEvv-w-1; Tue, 22 Sep 2020 17:13:27 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7E74964088; Tue, 22 Sep 2020 21:13:26 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 414EF614F5; Tue, 22 Sep 2020 21:13:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809209; 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=3t3h9oDxjRXo+hECtZgRnukmRJ9G3Oo8Skvbxpet8Zc=; b=enDA81SqhnxAgiqjHXsLVQV+e/aOgVTLgW33A+Gi35HJ40ejtUOgwnIl8TUfcdw1Jbx5as AqOJMzOv0aNfsDYqsEeOiv67JeSjynew1bNKpVnSLyUs6x8KS3BLCMQV29aH0xRp+E4NWu PixSodHHHweLfTi1z2AcWKtPKzu5MY8= X-MC-Unique: dvWLFTBYO9iIO7oiSEvv-w-1 From: John Snow To: Markus Armbruster Subject: [PATCH 09/16] qapi/expr.py: rewrite check_if Date: Tue, 22 Sep 2020 17:13:06 -0400 Message-Id: <20200922211313.4082880-10-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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 only minor 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. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost Tested-by: Cleber Rosa based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 6b064a2138..5d5c3d050d 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -136,15 +136,15 @@ def check_if_str(ifcond: object) -> None: ifcond =3D expr.get('if') if ifcond is None: return - if isinstance(ifcond, list): - if ifcond =3D=3D []: - raise QAPISemError( - info, "'if' condition [] of %s is useless" % source) - for elt in ifcond: - check_if_str(elt) - else: - check_if_str(ifcond) - expr['if'] =3D [ifcond] + + if not isinstance(ifcond, list): + ifcond =3D [ifcond] + expr['if'] =3D ifcond + if not ifcond: + raise QAPISemError( + info, "'if' condition [] of %s is useless" % source) + for elt in ifcond: + check_if_str(elt) =20 =20 def normalize_members(members: object) -> None: --=20 2.26.2 From nobody Fri May 3 10:08:42 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=1600811378; cv=none; d=zohomail.com; s=zohoarc; b=UD+bcbD7c6+xh7Uh7czXKbbVkzhevlh70d1PdanWLcXn8iz6Stk8VjAcV3FlHCyln3YxoIT8/huac1+RhhO6SEUFJCY8Et1Jo1SPC73oz1363JB8fzDwlDQtula0dezYqBroMKzgH637liMZpQYM/Xddjm9L58GUiiHElX3QEVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811378; 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=FttIVxQ9TFGN8XY/kcxNXdK8d88KH8ay5wgIRnTZmA4=; b=RG4m3M1H4ERAZX0Ui+PtzahHGt1CCBI2pEnh582bbd8d7Vs4gFColtBX0aAzfNKLoPY+zrLIDYNBPoRJgrRe4IuqH12iN8o+zDuKup0ogOSNfGgbZ7AbcpPiS9312nQ0STe1rcdzSx0yi85xgR1pEo2vZKX6FA9xp6nCVJLSUYQ= 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 1600811378245481.0851943671262; Tue, 22 Sep 2020 14:49:38 -0700 (PDT) Received: from localhost ([::1]:37148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqAK-0006yW-S2 for importer@patchew.org; Tue, 22 Sep 2020 17:49:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbR-00018B-5I for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:36388) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbP-00063c-EM for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:32 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-522-WeaGhjP6Nr2gBshNV6Ye4A-1; Tue, 22 Sep 2020 17:13:28 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D40A310BBEC8; Tue, 22 Sep 2020 21:13:27 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id C26BA614F5; Tue, 22 Sep 2020 21:13:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809210; 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=FttIVxQ9TFGN8XY/kcxNXdK8d88KH8ay5wgIRnTZmA4=; b=DyW7CMXsixBfjPKtb2nVkPH6qT1bjAI3lyAkAP6vvPqv6EWI4pU6eh0PcAx4nCeowvmKRv laOIefqh6KA5ojwcv8HXoLdRTZx/gwxG9X6VQPlmew+/F69eGlF2dmdHlFHrqpCRqXyS0a rqZu5//NDB+HmFXP+6zrClG1Dwo5Y7I= X-MC-Unique: WeaGhjP6Nr2gBshNV6Ye4A-1 From: John Snow To: Markus Armbruster Subject: [PATCH 10/16] qapi/expr.py: Remove single-letter variable Date: Tue, 22 Sep 2020 17:13:07 -0400 Message-Id: <20200922211313.4082880-11-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- 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 5d5c3d050d..f244e9648c 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -211,14 +211,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 feature 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_str(f['name'], info, source) - check_if(f, info, source) + assert isinstance(feature, dict) + check_keys(feature, info, source, ['name'], ['if']) + check_name_is_str(feature['name'], info, source) + source =3D "%s '%s'" % (source, feature['name']) + check_name_str(feature['name'], info, source) + check_if(feature, info, source) =20 =20 def check_enum(expr: Expression, info: QAPISourceInfo) -> None: --=20 2.26.2 From nobody Fri May 3 10:08:42 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=1600811871; cv=none; d=zohomail.com; s=zohoarc; b=mU9exN/QTZlHZqNZuVQdpTIEc9g+PKP9LNIc160OZfyv9Y30tAwFioSJqoIHyDzfedQ9LA/qFpJ4GkEyoR5AvB8ELQ6l0YEGunycUgyMvGho3Y/DvAcl96v20kD3FpwHWsJuJWxmVekDAXFLU3wSJaAOaGBteXtveoO0cWrDDyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811871; 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=F8Tlcu0rBgiQmhsrhc7FiuFZcAK0dpv8XpiYSQEPdQI=; b=cOfR7rRVGTwo2Q2A6J0F3tlnUyKtpq+oWx8t/P/JwFJMdtGNSeNw2OWmhlDkJL5ZLsRlafBGx95qAS566tGsLQjlaD+19dDetcfAykrti0D9ac7klvRROoDxPbnziuwE059qThbk8ODmAD6r7mo7eyZfm84EjtY7ZsGQYJUGyIs= 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 16008118719721.145451486262914; Tue, 22 Sep 2020 14:57:51 -0700 (PDT) Received: from localhost ([::1]:33320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqII-0000Hg-Bv for importer@patchew.org; Tue, 22 Sep 2020 17:57:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40036) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbT-0001FN-W6 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:36 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:37155 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbQ-00063r-Tp for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-184-9vleCEChPMelxQ12778sRQ-1; Tue, 22 Sep 2020 17:13:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CFBD0802B70; Tue, 22 Sep 2020 21:13:28 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A5CB73682; Tue, 22 Sep 2020 21:13:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809211; 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=F8Tlcu0rBgiQmhsrhc7FiuFZcAK0dpv8XpiYSQEPdQI=; b=bv/MLWFCV2VFbd88AZJEyWj3NWq/SKljV/iNvM4e2dMbPsZWQbJkrBw+jAhR9pYGokDHbS Z/PPkHV0lCo+KQJKuKIH+qYoWiMRkSrVqM0Cf3Hmzn1nsgItiR90+0C1ZMS/ovof4k94Ol iX8BY42ng+BAlBjUD5hDtYE+HOnWXs8= X-MC-Unique: 9vleCEChPMelxQ12778sRQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 11/16] qapi/expr.py: enable pylint checks Date: Tue, 22 Sep 2020 17:13:08 -0400 Message-Id: <20200922211313.4082880-12-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 17:00:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost Tested-by: Cleber Rosa Tested-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- scripts/qapi/pylintrc | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index 581755351b..d7adb2ba33 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -4,7 +4,6 @@ # The regex matches against base names, not paths. ignore-patterns=3Ddoc.py, error.py, - expr.py, parser.py, schema.py, =20 --=20 2.26.2 From nobody Fri May 3 10:08:42 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=1600809801; cv=none; d=zohomail.com; s=zohoarc; b=W/3bAE0YBKAeQ9c77p3ZL2wRrscISDGMRLbhgco93pWVr/ldBWU8trjPLtd5ngwwi9F30wqTyQ3u+atU7qctMnYaFWGjpbVvVCFlmDG4ATpmCjqA3VG1k8tCM9Jz6lzjAQQPvH0rTsSad0ZcKvwVZNIMsR15qB0HC4v3fseku44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809801; 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=7wkfyJxPT7WMs+xQ5yhM6ldyq5c/1HHIx7xgHgPKhcc=; b=DFzhQt+uoq5DUJC06/uAOT9qFgo+YrNxmIKYKBqIZ/n4Z7JwSbCG41EPeAxSBVmRq7Yq4+b95dX6aal6g56fgGGNA57ZsGy8m0RqMG0xBOhvjWw6REsIDAROvtk2tV6J7lTTRHPMELLdY01jLVfSwDl0oeYPUw41wZnNFXtD2O0= 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 1600809801406269.0222086295905; Tue, 22 Sep 2020 14:23:21 -0700 (PDT) Received: from localhost ([::1]:41438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpkt-0004vR-UC for importer@patchew.org; Tue, 22 Sep 2020 17:23:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbU-0001Gg-KN for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:36 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:43756 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbS-000648-74 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:36 -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-354-vE8sbY9yMF67YyODEZxguA-1; Tue, 22 Sep 2020 17:13:31 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3AD3910BBEC3; Tue, 22 Sep 2020 21:13:30 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 07B7973682; Tue, 22 Sep 2020 21:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809213; 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=7wkfyJxPT7WMs+xQ5yhM6ldyq5c/1HHIx7xgHgPKhcc=; b=DsbMFhUXDE5V0lTDLpZC2vPRPMuOuiKIX4EcR2LeO63wB3PtKwxp08kZZOWbbRFdrsmhVA I5gbemwpPEVBJimJCppfHCsR9zNKMmzG/Cc8u8arnGPxJbmWDvHNvCWy7Yfa/p6M5ZP4a6 MwM+JYIaxxgynxKtFoZeYFloa23sxFg= X-MC-Unique: vE8sbY9yMF67YyODEZxguA-1 From: John Snow To: Markus Armbruster Subject: [PATCH 12/16] qapi/expr.py: Add docstrings Date: Tue, 22 Sep 2020 17:13:09 -0400 Message-Id: <20200922211313.4082880-13-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 13:33:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 157 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 155 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index f244e9648c..4bba09f6e5 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 also 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 ( Iterable, @@ -46,6 +63,7 @@ def check_name_is_str(name: object, info: QAPISourceInfo, source: str) -> None: + """Ensures that `name` is a string. [Const]""" if not isinstance(name, str): raise QAPISemError(info, "%s requires a string name" % source) =20 @@ -56,6 +74,24 @@ def check_name_str(name: str, allow_optional: bool =3D False, enum_member: bool =3D False, permit_upper: bool =3D False) -> None: + """ + Ensures a string is a legal name. [Const] + + A name is legal in the default case when: + - It matches ``(__[a-z0-9.-]+_)?[a-z][a-z0-9_-]*`` + - It does not start with ``q_`` or ``q-`` + + :param name: Name to check. + :param info: QAPI source file information. + :param source: Human-readable str describing "what" this name = is. + :param allow_optional: Allow the very first character to be ``*``. + (Cannot be used with `enum_member`) + :param enum_member: Allow the very first character to be a digit. + (Cannot be used with `allow_optional`) + :param permit_upper: Allows upper-case characters wherever + lower-case characters are allowed. + """ + assert not (allow_optional and enum_member) membername =3D name =20 if allow_optional and name.startswith('*'): @@ -76,6 +112,17 @@ def check_name_str(name: str, =20 =20 def check_defn_name_str(name: str, info: QAPISourceInfo, meta: str) -> Non= e: + """ + Ensures a name is a legal definition name. [Const] + + A legal definition name: + - Adheres to the criteria in `check_name_str`, with uppercase permitt= ed + - Does not end with ``Kind`` or ``List``. + + :param name: Name to check. + :param info: QAPI source file information. + :param meta: Type name of the QAPI expression. + """ check_name_str(name, info, meta, permit_upper=3DTrue) if name.endswith('Kind') or name.endswith('List'): raise QAPISemError( @@ -87,6 +134,15 @@ def check_keys(value: _JSObject, source: str, required: List[str], optional: List[str]) -> None: + """ + Ensures an object has a specific set of keys. [Const] + + :param value: The object to check. + :param info: QAPI source file information. + :param source: Human-readable str describing "what" this object is. + :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)) @@ -109,6 +165,12 @@ def pprint(elems: Iterable[str]) -> str: =20 =20 def check_flags(expr: Expression, info: QAPISourceInfo) -> None: + """ + Ensures common fields in an Expression are correct. [Const] + + :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( @@ -120,6 +182,18 @@ def check_flags(expr: Expression, info: QAPISourceInfo= ) -> None: =20 =20 def check_if(expr: _JSObject, info: QAPISourceInfo, source: str) -> None: + """ + Syntactically validate and normalize the ``if`` field of an object. [R= W] + + The ``if`` field may be either a `str` or a `List[str]`. + A `str` element will be normalized to `List[str]`. + + Sugared: `Union[str, List[str]]` + Ifcond: `List[str]` + + :param expr: A `dict`; the ``if`` field, if present, will be validated. + :param info: QAPI source file information. + """ =20 def check_if_str(ifcond: object) -> None: if not isinstance(ifcond, str): @@ -148,6 +222,16 @@ def check_if_str(ifcond: object) -> None: =20 =20 def normalize_members(members: object) -> None: + """ + Normalize a "members" value. [RW] + + 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}``. + + Sugared: `Dict[str, Union[str, TypeRef]]` + Members: `Dict[str, TypeRef]` + """ if isinstance(members, dict): for key, arg in members.items(): if isinstance(arg, dict): @@ -160,6 +244,18 @@ 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`. [RW] + + 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 string describing "what" the value = is. + :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. + """ if value is None: return =20 @@ -205,6 +301,15 @@ def check_type(value: Optional[object], =20 def check_features(features: Optional[object], info: QAPISourceInfo) -> None: + """ + Syntactically validate and normalize the "features" field. [RW] + + `features` may be a List of either `str` or `dict`. + Any `str` element will be normalized to `{'name': element}`. + + Sugared: `List[Union[str, Feature]]` + Features: `List[Feature]` + """ if features is None: return if not isinstance(features, list): @@ -222,6 +327,12 @@ def check_features(features: Optional[object], =20 =20 def check_enum(expr: Expression, info: QAPISourceInfo) -> None: + """ + Validate this `Expression` as an ``enum`` expression. [RW] + + :param expr: `Expression` to validate. + :param info: QAPI source file information. + """ name =3D expr['enum'] members =3D expr['data'] prefix =3D expr.get('prefix') @@ -246,6 +357,12 @@ def check_enum(expr: Expression, info: QAPISourceInfo)= -> None: =20 =20 def check_struct(expr: Expression, info: QAPISourceInfo) -> None: + """ + Validate this `Expression` as a ``struct`` expression. [RW] + + :param expr: `Expression` to validate. + :param info: QAPI source file information. + """ name =3D cast(str, expr['struct']) # Asserted in check_exprs members =3D expr['data'] =20 @@ -254,6 +371,12 @@ def check_struct(expr: Expression, info: QAPISourceInf= o) -> None: =20 =20 def check_union(expr: Expression, info: QAPISourceInfo) -> None: + """ + Validate this `Expression` as a ``union`` expression. [RW] + + :param expr: `Expression` to validate. + :param info: QAPI source file information. + """ name =3D cast(str, expr['union']) # Asserted in check_exprs base =3D expr.get('base') discriminator =3D expr.get('discriminator') @@ -280,6 +403,12 @@ def check_union(expr: Expression, info: QAPISourceInfo= ) -> None: =20 =20 def check_alternate(expr: Expression, info: QAPISourceInfo) -> None: + """ + Validate this `Expression` as an ``alternate`` expression. [RW] + + :param expr: Expression to validate. + :param info: QAPI source file information. + """ members =3D expr['data'] =20 if not members: @@ -297,6 +426,12 @@ def check_alternate(expr: Expression, info: QAPISource= Info) -> None: =20 =20 def check_command(expr: Expression, info: QAPISourceInfo) -> None: + """ + Validate this `Expression` as a ``command`` expression. [RW] + + :param expr: `Expression` to validate. + :param info: QAPI source file information. + """ args =3D expr.get('data') rets =3D expr.get('returns') boxed =3D expr.get('boxed', False) @@ -308,6 +443,16 @@ def check_command(expr: Expression, info: QAPISourceIn= fo) -> None: =20 =20 def check_event(expr: Expression, info: QAPISourceInfo) -> None: + """ + Normalize and syntactically validate the ``event`` expression. [RW] + + Event: + event: `str` + data: `Optional[Dict[str, Member]]` + boxed: `Optional[bool]` + if: `Optional[Ifcond]` + features: `Optional[Features]` + """ args =3D expr.get('data') boxed =3D expr.get('boxed', False) =20 @@ -317,6 +462,14 @@ def check_event(expr: Expression, info: QAPISourceInfo= ) -> None: =20 =20 def check_exprs(exprs: List[_JSObject]) -> List[_JSObject]: + """ + Validate and normalize a list of parsed QAPI schema expressions. [RW] + + 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. + """ for expr_elem in exprs: # Expression assert isinstance(expr_elem['expr'], dict) --=20 2.26.2 From nobody Fri May 3 10:08:42 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=1600811097; cv=none; d=zohomail.com; s=zohoarc; b=kRxiAdAsptQBUAYcfnBxscB3qrXML+tymS0GTBq0QzPqsuIGzzwiAYsFtBqvX7UYunvS/604jpAViLv9MVd/TrqYg3JGIs29dOjn8d5UmLapkovg6jpGwA2/UhlN0SvTQYMA+11KT3H5x/kZl2jBG1EZ+p0ifihOgCxa+lNoZtg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811097; 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=otO27sep0nJ6bA9EFn+q7sPXFbyUG38myhQs4Z2myn0=; b=BLjgT1rUjlZkkzb8MC9KN2Oc126/UNcTAZDW5B7Q3Rr6jKj1YmVZiTXOG3pqDJFv1AWCPElPwqIYW/i1x94zvwFNHQf5F/YXXSGiHwKzFLkYrB4y6iC8pseR8LenixqhJi2COUsB6yWO2aVKWzw2qY+Se2Ob4t+EHVOTCgGq7iE= 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 1600811097401964.1272622913068; Tue, 22 Sep 2020 14:44:57 -0700 (PDT) Received: from localhost ([::1]:48218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKq5n-0008Fu-Qi for importer@patchew.org; Tue, 22 Sep 2020 17:44:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbV-0001J8-T8 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56526) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbS-00064M-T0 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:37 -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-164-iyCikDqyO3K0c0TFUimbZg-1; Tue, 22 Sep 2020 17:13:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4E78C81CBE9; Tue, 22 Sep 2020 21:13:31 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64FC173682; Tue, 22 Sep 2020 21:13:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809214; 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=otO27sep0nJ6bA9EFn+q7sPXFbyUG38myhQs4Z2myn0=; b=W87Hwlnogy3uFwIJZAZR6JoawH3YrS4kpbzHY0SovrKTO279Jn9YbE2R64lUHCGFFihLyx HaUD6orRW/XZLvbAnAEqESUFkhTQOH3It0GlYiJhYf4DkMU5Wf5af2u77WeKKgpgHyyOrU nO1eIT/dgZy6oQHVZOumVxMnnkoLWtM= X-MC-Unique: iyCikDqyO3K0c0TFUimbZg-1 From: John Snow To: Markus Armbruster Subject: [PATCH 13/16] qapi/expr.py: Modify check_keys to accept any Iterable Date: Tue, 22 Sep 2020 17:13:10 -0400 Message-Id: <20200922211313.4082880-14-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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 very minor adjustment. a + b is list-specific behavior, but we can accept a wider variety of types in a more pythonic fashion if we avoid that behavior. Typing it this way allows callers to use things like dict.keys() and other iterables that are not their own discrete lists. Including it just as a statement of practice if nothing else: It's nice to use the least-specific type possible as function input and use the most-specific type for returns. Signed-off-by: John Snow Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- 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 4bba09f6e5..2a1f37ca88 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -132,8 +132,8 @@ def check_defn_name_str(name: str, info: QAPISourceInfo= , meta: str) -> None: def check_keys(value: _JSObject, info: QAPISourceInfo, source: str, - required: List[str], - optional: List[str]) -> None: + required: Iterable[str] =3D (), + optional: Iterable[str] =3D ()) -> None: """ Ensures an object has a specific set of keys. [Const] =20 @@ -154,7 +154,7 @@ def pprint(elems: Iterable[str]) -> str: "%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.26.2 From nobody Fri May 3 10:08:42 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=1600811226; cv=none; d=zohomail.com; s=zohoarc; b=ZGP6bK/whtdnz2PbmzpaufrbNGrAfOIySpmbqX5m/EcmCVul7ppQ+Rs1K2h3OMlbtJsAnDU+qgpHvFDgK5baEa4mZqzldPGwTX4E1NKjaY7FHKZmH9e/+FfgPButBvCBFZepK3VGHFhKEQoxoRCZQpa28Z9cKgSroUH9TMSMPeY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811226; 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=GDER9rbTV2Nwoc53bdkKQyrGiaz2k0Kuh/paR7LTkj8=; b=kUT1HQ+OwPX3V10j9pknmjUs0KtpkC0bjrZzLpeuRYW+qEWOHw34MmzVAFaClzh6TMM5aF3GV+CHGLrEXRQJJzvUM2brUVJCV8otTemLWmx2E70GmVkCou+UPyhQ/z/0KFHV+hNugFaV+yEgNciLzkTQqwGMMnb0OmSWWrXVr4c= 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 1600811226283553.067085098681; Tue, 22 Sep 2020 14:47:06 -0700 (PDT) Received: from localhost ([::1]:56580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKq7t-0003NH-0R for importer@patchew.org; Tue, 22 Sep 2020 17:47:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbX-0001OA-Qt for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21925) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbW-00064k-24 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:39 -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-wq2L9Q8EPgOukuCDyOkBiQ-1; Tue, 22 Sep 2020 17:13:33 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7C75881F005; Tue, 22 Sep 2020 21:13:32 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FEA173682; Tue, 22 Sep 2020 21:13:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809217; 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=GDER9rbTV2Nwoc53bdkKQyrGiaz2k0Kuh/paR7LTkj8=; b=RyUbmmrscUJrjJuTaS4uTOW+it3wj+FVxBTdAqzPHEteNFYyRiynU33xZfw6uDCKozjga5 IS4NgO9g2V+IvzoHHNAl6Zdl8b5UxGDi5rKXZWfO/cJyPqgeAkjBsM+yNcnE+NxwzPmBAZ SGYRmgGSL0/9rjGfoCSsRLiTlXI9WmY= X-MC-Unique: wq2L9Q8EPgOukuCDyOkBiQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 14/16] qapi/expr.py: Use tuples instead of lists for static data Date: Tue, 22 Sep 2020 17:13:11 -0400 Message-Id: <20200922211313.4082880-15-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- 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 2a1f37ca88..69ee9e3f18 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -171,11 +171,11 @@ def check_flags(expr: Expression, info: QAPISourceInf= o) -> 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']: + for key in ('boxed', 'allow-oob', 'allow-preconfig'): if key in expr and expr[key] is not True: raise QAPISemError( info, "flag '%s' may only use true value" % key) --=20 2.26.2 From nobody Fri May 3 10:08:42 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=1600809984; cv=none; d=zohomail.com; s=zohoarc; b=ANdizyIxsMZZRALfxKBb3uZS/ZS9DMNPV+EjUmwmIBap/bz97sDhcGC77bygMod0hhmNHwg7sY/AmE21l7wsATCb76a9O00Tonl5ur9KqF0WNOaPwHRMt8Um3Mu2HsmLp6BOrrJm4RkZMpuX43dFr97xDcs/1I6scUJpqqpuT2k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600809984; 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=Je01v8tianvun5dGhcapKD/fWgdPcSCTuzFS6zyvrOM=; b=flP8dxStaZHvn8+NCFJcrP2sbAFaKHyilXeEOQqUS8E1VcAFku11DzZ79zVWjXlirm/Mnx7AbghnhVnIq4vUsqfTWzVp+ri7o4fgoPYLbOc7gi11yQ6ab/wSNMjyHiwp+tq82ZBQf4IABq2sPrA0DZJngo2n2VXP0mmqehRkMMM= 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 1600809984807570.3796235407692; Tue, 22 Sep 2020 14:26:24 -0700 (PDT) Received: from localhost ([::1]:49894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKpnr-0000IP-DY for importer@patchew.org; Tue, 22 Sep 2020 17:26:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpbX-0001ME-4d for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57641) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbV-00064d-4B for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:38 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-406-tnwVAhegNAic_vT0-kWgmg-1; Tue, 22 Sep 2020 17:13:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8820310BBEC3; Tue, 22 Sep 2020 21:13:33 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id A89DD73670; Tue, 22 Sep 2020 21:13:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809216; 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=Je01v8tianvun5dGhcapKD/fWgdPcSCTuzFS6zyvrOM=; b=Hot9pERbAl/29Zt9984dahKmxrx3IOahAiXR3Zg7h7ocDsWaZUQIc9EAlyDZJ157B3gyIV aAFQZoNZY92K3e5mls1zkegSb6YySGN1kqbLmpq5lc/0/zZ1MMk37DlrJrldeFxcnuZSsk r0m+6nRpl8+8Hsrp8LXQUnmQtl539dc= X-MC-Unique: tnwVAhegNAic_vT0-kWgmg-1 From: John Snow To: Markus Armbruster Subject: [PATCH 15/16] qapi/expr.py: move related checks inside check_xxx functions Date: Tue, 22 Sep 2020 17:13:12 -0400 Message-Id: <20200922211313.4082880-16-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, 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: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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. Signed-off-by: John Snow Reviewed-by: Cleber Rosa based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- 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 69ee9e3f18..74b2681ef8 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -333,6 +333,10 @@ def check_enum(expr: Expression, info: QAPISourceInfo)= -> None: :param expr: `Expression` to validate. :param info: QAPI source file information. """ + 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') @@ -363,6 +367,11 @@ def check_struct(expr: Expression, info: QAPISourceInf= o) -> None: :param expr: `Expression` to validate. :param info: QAPI source file information. """ + 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 @@ -377,6 +386,13 @@ def check_union(expr: Expression, info: QAPISourceInfo= ) -> None: :param expr: `Expression` to validate. :param info: QAPI source file information. """ + 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') @@ -409,6 +425,11 @@ def check_alternate(expr: Expression, info: QAPISource= Info) -> None: :param expr: Expression to validate. :param info: QAPI source file information. """ + 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: @@ -432,6 +453,13 @@ def check_command(expr: Expression, info: QAPISourceIn= fo) -> None: :param expr: `Expression` to validate. :param info: QAPI source file information. """ + check_keys(expr, info, 'command', + required=3D['command'], + optional=3D('data', 'returns', 'boxed', 'if', 'features', + 'gen', 'success-response', 'allow-oob', + 'allow-preconfig')) + normalize_members(expr.get('data')) + args =3D expr.get('data') rets =3D expr.get('returns') boxed =3D expr.get('boxed', False) @@ -453,6 +481,11 @@ def check_event(expr: Expression, info: QAPISourceInfo= ) -> None: if: `Optional[Ifcond]` features: `Optional[Features]` """ + normalize_members(expr.get('data')) + check_keys(expr, info, 'event', + required=3D['event'], + optional=3D('data', 'boxed', 'if', 'features')) + args =3D expr.get('data') boxed =3D expr.get('boxed', False) =20 @@ -519,38 +552,16 @@ def check_exprs(exprs: List[_JSObject]) -> List[_JSOb= ject]: "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']) - 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.26.2 From nobody Fri May 3 10:08:42 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=1600811548; cv=none; d=zohomail.com; s=zohoarc; b=Mn1OKRQq1BOgdnYziIS9X1Z3i0CNhGoF0xayJGy3zypUJin5VuARmXw9JoHI6cEsXzkn8rFu+UlKE9TfxbiuxNtkIzNbIiNv8//3dX6fVUCCvjU8aGY56gVZo/uJerk7WHHsbb2lxYHa4QdOoL4BNA9rTdQENKE9JaXZObH0Fqs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600811548; 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=JgejwXtms9d7shSYi6P2L9OOZ+k6Lw4Sp1jD2446/rY=; b=gNXbEnsyEGY4/UZLGBs7vLHAgbV7zsmQzvudQ5SbCp2QimieL97uFspy2Th8zNO2lYsbqNQ0K3hIdVUwl7LOmEPoo9g41h0YuOduQ9vv3RhjuB8021urDmDDeRBFe5fzlLIfFeo16kLScVkrFTW8roXZHYl7iL3GRn8WC/FUgdQ= 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 16008115481730.7647331763334932; Tue, 22 Sep 2020 14:52:28 -0700 (PDT) Received: from localhost ([::1]:45562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqD3-00025T-S8 for importer@patchew.org; Tue, 22 Sep 2020 17:52:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKpba-0001UM-6v for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60781) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKpbY-00064z-7l for qemu-devel@nongnu.org; Tue, 22 Sep 2020 17:13:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-4Sr2AnaXMUmHdfcYWhWeKg-1; Tue, 22 Sep 2020 17:13:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A13FF19611A1; Tue, 22 Sep 2020 21:13:34 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id B458673682; Tue, 22 Sep 2020 21:13:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600809219; 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=JgejwXtms9d7shSYi6P2L9OOZ+k6Lw4Sp1jD2446/rY=; b=AWxo4zb+sXw9yrSbWdWkF64Gj3O+OTIZt4i0eaRNnaZLEkD1gtGEXq64C/7XAAriWvphNY fzZc9hfsYJNKzw4Z1GqviN68G7U33ECphdRS/Ur9czFvtflHy8DmrAiGrPpkNsR0GXnvJC 14KbtxAclf+X5SmaOJlES5qBks0GVzQ= X-MC-Unique: 4Sr2AnaXMUmHdfcYWhWeKg-1 From: John Snow To: Markus Armbruster Subject: [PATCH 16/16] qapi/expr.py: Use an expression checker dispatch table Date: Tue, 22 Sep 2020 17:13:13 -0400 Message-Id: <20200922211313.4082880-17-jsnow@redhat.com> In-Reply-To: <20200922211313.4082880-1-jsnow@redhat.com> References: <20200922211313.4082880-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth 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 Reviewed-by: Cleber Rosa Reviewed-by: Eduardo Habkost based-on: <20200922210101.4081073-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 69 ++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 74b2681ef8..cfd342aa04 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -31,8 +31,11 @@ structures and contextual semantic validation. """ =20 +from enum import Enum import re from typing import ( + Callable, + Dict, Iterable, List, MutableMapping, @@ -494,6 +497,26 @@ def check_event(expr: Expression, info: QAPISourceInfo= ) -> 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' + + +_CHECK_FN: Dict[str, Callable[[Expression, 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[_JSObject]) -> List[_JSObject]: """ Validate and normalize a list of parsed QAPI schema expressions. [RW] @@ -519,28 +542,20 @@ def check_exprs(exprs: List[_JSObject]) -> List[_JSOb= ject]: 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 + name =3D cast(str, expr[meta]) # asserted right below: - check_name_is_str(name, info, "'%s'" % meta) - info.set_defn(meta, name) - check_defn_name_str(name, info, meta) + check_name_is_str(name, info, "'%s'" % meta.value) + info.set_defn(meta.value, name) + check_defn_name_str(name, info, meta.value) =20 if doc: if doc.symbol !=3D name: @@ -551,22 +566,8 @@ def check_exprs(exprs: List[_JSObject]) -> List[_JSObj= ect]: 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_if(expr, info, meta) + _CHECK_FN[meta](expr, info) + check_if(expr, info, meta.value) check_features(expr.get('features'), info) check_flags(expr, info) =20 --=20 2.26.2