From nobody Mon Nov 17 09:46:57 2025 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=1603748357; cv=none; d=zohomail.com; s=zohoarc; b=UbZUMwWFspbyR3GE+23R4XfrywfvQJfRu3AtheszsVAvzJJTHSTrbEDF3OtmwPl9Tpx+d+KDGdr2RZcMYHV8w5sguLBJt14eE+oxgsoYtYFDCeZpvoTg6Kveta+XucV9A8lhkNXTZOtcKrfUdhB/d0N1/DFCIrFYXZcJa8i/Mjw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603748357; 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=iNXKETo8JGNIyUIk7CYW1Kx+3IY1lxRFSJg705347q8=; b=FUzdGpak6YwVV7q0lxG2wSAveCULTHOjigNw2xPCdQLGuAWRyT39mj9qe9hbcMK3Jn1nptEQCrpQPEKw2FKu9eT54Wz3t/oRM8tslQOGhnj1ebqpj2RwImSycorIIYmUbhRmy4OZoIVZiHtBiBbhM7E7fGsVoIcVkPStdVDfmX0= 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 1603748357141658.2577722146002; Mon, 26 Oct 2020 14:39:17 -0700 (PDT) Received: from localhost ([::1]:33726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXACx-0005nV-R0 for importer@patchew.org; Mon, 26 Oct 2020 17:39:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAb-00042L-CI for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:20731) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAX-0001Uq-EA for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-538-CIcA9dCvMluVpGQXA83Uag-1; Mon, 26 Oct 2020 17:36:41 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 15EA18064C0 for ; Mon, 26 Oct 2020 21:36:40 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7306919728; Mon, 26 Oct 2020 21:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748202; 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=iNXKETo8JGNIyUIk7CYW1Kx+3IY1lxRFSJg705347q8=; b=eiamI49g2O/F7iAppfVJY6ykcKUzEm1bsGQbpGcGWyhyjHauEyhS9caDm6z8N36Ge55Coi QezxnswvoJyz0Eab34He5J4SjsqMP6n4qYgsBfX5U35QK6GNMgXcOAIAsFRDAvjmvd84OP v8c5S9uxMt1PME2bK1D8CupzYQ3xlfM= X-MC-Unique: CIcA9dCvMluVpGQXA83Uag-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 01/16] qapi/expr.py: Remove 'info' argument from nested check_if_str Date: Mon, 26 Oct 2020 17:36:22 -0400 Message-Id: <20201026213637.47087-2-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/25 21:03:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The function can just use the argument from the scope above. Otherwise, we get shadowed argument errors because the parameter name clashes with the name of a variable already in-scope. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-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 2fcaaa2497a8..35695c4c653b 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -104,7 +104,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, @@ -124,9 +124,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 Mon Nov 17 09:46:57 2025 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=1603748535; cv=none; d=zohomail.com; s=zohoarc; b=LbWn67TkMwaJOVjHQN0xb0AUtpScsnWS5dLnXaY5ryebfZU6iiOAWy15mwyqVzOMnyMpiKl7bHB8eci196IuDQx3Unv+v92EDHRwYkBwsimHPkxGSQBLBHqW6fDdiVZCxN+djHZGHsgkQencCamift7bysXOTBI8Dby2Dmnr09I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603748535; 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=LbSZ037TDABolUMa55Ev3FRzlOwQHHsspgxudE09PqQ=; b=hPMr161d/Pw7ikv6j2KJ59dWl06xYWKwmOmwtLVg2gwMsHoZzNFFQiro5agAsnbq/+Ut6yLVB8gVG0FjWKS0ARYzD/ZcD8Bw7AhkKXOdWKYwVrzSgf9s/jlg4MDiKiEpOGitYSXDfLedvA1e2H8MnxmxBarshXmfrBixpOI69r4= 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 1603748535712120.30467907316506; Mon, 26 Oct 2020 14:42:15 -0700 (PDT) Received: from localhost ([::1]:41932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAFq-0000tV-Eq for importer@patchew.org; Mon, 26 Oct 2020 17:42:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAa-000418-12 for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:31783) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAX-0001Ur-M3 for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-90-g1JXRWtAO8KOlDc_z7eprQ-1; Mon, 26 Oct 2020 17:36:42 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 371A464085 for ; Mon, 26 Oct 2020 21:36:41 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 376A019728; Mon, 26 Oct 2020 21:36:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748204; 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=LbSZ037TDABolUMa55Ev3FRzlOwQHHsspgxudE09PqQ=; b=ds8SVG9WImMpbYWrodyUtaAUwgNyKqQQepknY0iRLBxsz4LtW6fndyeV+USXlAUe3ZEUvq ASWSc4SbzYHPDQBxc+qf/LXQomR4VgL6pQZz6YZRuEsC89Nv18g5zr/JMGdfHKpEJJdzrl zRVtbRRW5QesOCg2sPmi+pq5F8hhfZI= X-MC-Unique: g1JXRWtAO8KOlDc_z7eprQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 02/16] qapi/expr.py: Check for dict instead of OrderedDict Date: Mon, 26 Oct 2020 17:36:23 -0400 Message-Id: <20201026213637.47087-3-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/25 21:03:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" OrderedDict is a subtype of dict, so we can check for a more general form. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 35695c4c653b..5694c501fa38 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -14,7 +14,6 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 -from collections import OrderedDict import re =20 from .common import c_name @@ -131,7 +130,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 @@ -162,7 +161,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 Mon Nov 17 09:46:57 2025 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=1603748725; cv=none; d=zohomail.com; s=zohoarc; b=i8+OOvKagW37z7vCFkXrtx8pN6hXwpEQoUkRhEqDH22WKZQ8ELtHCAuXZH1DgPhM4J3tugH126qVgHMa2r7ZJzkk9PRe2dQ7xq1KLG0Zd6gZ1aoGnraLmOaCrMCF+f7J1m8OTBuzpErh2ELnffOMtmuly4Zr9aIv2eCWsFLIxgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603748725; 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=TVAIaUd0qn/L1hYp8sivghgZfYY52GolNO0IpyKQ81g=; b=STZ+52vo5LOB49mnlxRB/CkUYqdGrDOUsIynC6NlLZaiic6ywf6pZ2OOggJIGY+TxeeIpgjOG8cLWpoPcYgUm1RK3A7XuBtXzU5hkEEBodUN8RusGPmZvsiWzjpNUgwGd8r1HyUG8Rin6tF0YmMTfBUR8Iy5WpEI4bj+82VxC98= 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 1603748725178328.3674442336147; Mon, 26 Oct 2020 14:45:25 -0700 (PDT) Received: from localhost ([::1]:53208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAIu-0005aj-1s for importer@patchew.org; Mon, 26 Oct 2020 17:45:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAa-00041G-9v for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:27835) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAX-0001V1-Or for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:47 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-519-V-tAuQ5TPR2vp6-fHsAByA-1; Mon, 26 Oct 2020 17:36:43 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 770FE8064C0 for ; Mon, 26 Oct 2020 21:36:42 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8047D19728; Mon, 26 Oct 2020 21:36:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748205; 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=TVAIaUd0qn/L1hYp8sivghgZfYY52GolNO0IpyKQ81g=; b=BVOdCwG4qbAoW2J9DX7HQL0Jx1m7htucNaGcUTIyV3WmFnz4YIcIWVs1x5rqt9tVooCtaa v6BpcUJFEBOIkelCFtZ34TjGh+UhFp4Lid2+Db+4IoadZHaeI964EAVGV2nP9LbpaqBrrV 03DaFCkjdyemzBBz5mlD9TKM1QS+Gsg= X-MC-Unique: V-tAuQ5TPR2vp6-fHsAByA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 03/16] qapi/expr.py: constrain incoming expression types Date: Mon, 26 Oct 2020 17:36:24 -0400 Message-Id: <20201026213637.47087-4-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/26 02:39:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" mypy does not know the types of values stored in Dicts that masquerade as objects. Help the type checker out by constraining the type. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-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 5694c501fa38..f7c7f91326ef 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, @@ -287,9 +295,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 Mon Nov 17 09:46:57 2025 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=1603748535; cv=none; d=zohomail.com; s=zohoarc; b=iTo5rTDU1012zqc6hJOOwuy1Z+HaSCUNLtUsgUe58yzKGgVicoVZvNUBaSowNPIDcSzWfl8eb5vKgoDcXLLQ/AgnRYqrooNWFLkAigQL013/KrhqQc3qpwS6yR1hH1p9cJJlz+fi/Y6XXCzT7e8oDgKwlEfRvMIpb7ajRMqjTl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603748535; 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=S8x50cCMSfplV2qAmTGGgGrsddjWRyaUw3FL/uWzI6o=; b=aeSJ/bYOKoo2iTZZJ5cMI2O4r0kNoSeKktilBpp25xsTXwqoBIIbXwy3JE9MHN8nk/yB15HUxQVuosluFCWwoa51/8S3mASpVsMlQjXvWhFmCFVKRRoC87befNqdHCIF5L1kwadAVTC+YCTIBCNO/ZctEuu3ShVAtn9PPcMAV+s= 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 1603748535929998.5501713105889; Mon, 26 Oct 2020 14:42:15 -0700 (PDT) Received: from localhost ([::1]:42042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAFq-0000wJ-Ku for importer@patchew.org; Mon, 26 Oct 2020 17:42:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAa-00041j-QH for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25890) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAZ-0001VB-1O for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:48 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-565-R1ooHltuPGKysM7J8hdq1w-1; Mon, 26 Oct 2020 17:36:44 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D0E918C89D1 for ; Mon, 26 Oct 2020 21:36:43 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A5BD19728; Mon, 26 Oct 2020 21:36:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748206; 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=S8x50cCMSfplV2qAmTGGgGrsddjWRyaUw3FL/uWzI6o=; b=VeYXCWsrW8CxCNibZhgwgxf5MNiF1xUEpVl7MAv3yrpf8PnD1AdYBjelqEHyUa6D5Oosbt 4myp0x6QUlGUy/qKwfz+ji0w3Afz/lmye5d0MA1K4+eFZqVvnGMSGTblP8fBMVfIGr6Xxg rZMSefBn/qEnnfEPEkkguj7nooC4aU0= X-MC-Unique: R1ooHltuPGKysM7J8hdq1w-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 04/16] qapi/expr.py: Add assertion for union type 'check_dict' Date: Mon, 26 Oct 2020 17:36:25 -0400 Message-Id: <20201026213637.47087-5-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/26 02:39:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" mypy isn't fond of allowing you to check for bool membership in a collection of str elements. Guard this lookup for precisely when we were given a name. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-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 f7c7f91326ef..2c4c341d5243 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -173,7 +173,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 Mon Nov 17 09:46:57 2025 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=1603748356; cv=none; d=zohomail.com; s=zohoarc; b=hpQnL+FIhWjLBKiiOajcGUUyg9Jl+BgJ2JcYUa6YoVr7Y2ubyAFbwJ7aZOyYPdRWRuRJ1cwxxdh2r/iBDiORFEftoeT39BragnEUPOC7VbVEzf3efGGgeY19EGB1VKFb5pArj+j66m2JOUb5mc1x2+Xr1Yb7/JLb0g+fuSVkDjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603748356; 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=s6TkbQBjLoReAGUJyoH9pwS17iIr9tGt7G3z++5Tvc8=; b=Mrnomqhj/42j4ybebtywr1zk2DbJoiFhrsyRFAYy2qp/8cpE0QoVcFBWVHaq7uBG675kQNincKXq9aZa4rfuFdoN5jZ12dPSUASMtovzBaB81lHkQWZDJyHRl60QjcBfW58ZxOrO0RJS60D+a5KFjNFZHDZqhEwewtoYpr1E5cc= 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 1603748356642836.9922953619832; Mon, 26 Oct 2020 14:39:16 -0700 (PDT) Received: from localhost ([::1]:33690 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXACx-0005mc-Jn for importer@patchew.org; Mon, 26 Oct 2020 17:39:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAb-00042y-Va for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAa-0001VJ-3C for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-310-o5yPbsc3NE60B2_rtp5EKA-1; Mon, 26 Oct 2020 17:36:45 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 16C4964089 for ; Mon, 26 Oct 2020 21:36:44 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F60A19728; Mon, 26 Oct 2020 21:36:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748207; 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=s6TkbQBjLoReAGUJyoH9pwS17iIr9tGt7G3z++5Tvc8=; b=E4lapc8V8wKstPqvpGvFbTJ0EHbew+v8mWLTK7A/inHBzDLmZcDLwCrqjWUkkYAK0Ad641 8qQNT280OeUusgmGYemHigMhgCNUm+BGzr7a3y47eaEa0O4nyM09MpH/bOJMLYMtuTw+Wj 22VNd9Xh/BeMMJvyRdaI67R/rY+HowM= X-MC-Unique: o5yPbsc3NE60B2_rtp5EKA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 05/16] qapi/expr.py: move string check upwards in check_type Date: Mon, 26 Oct 2020 17:36:26 -0400 Message-Id: <20201026213637.47087-6-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/25 21:03:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It's a simple case, shimmy the early return upwards. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-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 2c4c341d5243..864363881682 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -150,6 +150,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: @@ -160,10 +164,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 Mon Nov 17 09:46:57 2025 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=1603748938; cv=none; d=zohomail.com; s=zohoarc; b=jlLUAGHKkJUpfSZWqGMbw21OsmhPCx5o47RFGDM9CHZ7H+6Ynm6I22+SDHyMU57STR75b2zKhCpFHnRaTQuZwLEAXYpe7+ErxiY12RptOsQig1qf6ViykZ5MvRTx7ksk1KUKn6CNKWwHqJCOeB39E+B298G94QndRb1auvOGuIc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603748938; 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=cbUKR6b9mvrjVlK20WDv1InAUJLku0Kl9L49zrV3Jeo=; b=W8NjCn7WsXCB3Yrdk0eMimwTgnfJ+jLDTSYrU5maw+/lUw45J3M9gnPelfrgizAWmFbTmfcolXXYqMF93/oMuhEe9c8QLlAicnWg2WGzCKUzKQxLsp5YGhEj6uTm019QdNNd7wRs/z4xZ/EbFT1zlhxD+DQkomVEQrDs7Qxdmtg= 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 160374893831967.40927411975724; Mon, 26 Oct 2020 14:48:58 -0700 (PDT) Received: from localhost ([::1]:32964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAML-0000ZT-0v for importer@patchew.org; Mon, 26 Oct 2020 17:48:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAc-00043U-9t for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAa-0001VO-Kd for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:49 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-iWW5IeSMO3aOI8CUizTXAQ-1; Mon, 26 Oct 2020 17:36:45 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DAB306408A for ; Mon, 26 Oct 2020 21:36:44 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A80619728; Mon, 26 Oct 2020 21:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748207; 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=cbUKR6b9mvrjVlK20WDv1InAUJLku0Kl9L49zrV3Jeo=; b=Q6BpIDvhPXysF73Pa8rANvYOfdenp7H0n/cx0rAIqd/3dRve+b250nMRYRlKurREjkFIQF UEUqfYbyBwRHPtSWrhfPLScRvjzF/LBIXzKtvucC0V95SFWiEy9k+redSd8ZLATcXhtoZA i7jtKqxUFYTVWWsmikrk4olZzmhfbRM= X-MC-Unique: iWW5IeSMO3aOI8CUizTXAQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 06/16] qapi/expr.py: Check type of 'data' member Date: Mon, 26 Oct 2020 17:36:27 -0400 Message-Id: <20201026213637.47087-7-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/25 21:03:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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: <20201026194251.11075-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 864363881682..2654a72e8333 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -254,6 +254,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) @@ -267,6 +270,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 Mon Nov 17 09:46:57 2025 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=1603748692; cv=none; d=zohomail.com; s=zohoarc; b=BisWq8DnSIefvnco5w2Ez/D2mhmPraCREChNZLTGvEngkXmccLQKKRz+5JNw37nvPuav1WT8NFFR4rLdHYKOYGP4XuSMvh5ySZFjs/BHZ5V2YKxx67VOsBBFm3Xh5F4MMxI2lG+X6Q92Z/+Y3UWRr2f7ehuDV1lyFYk2LXuIR8I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603748692; 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=PADkYIFfY8n6yj7AmPITNyc+ufsFjfb5RIBcX2AxO2k=; b=YW1RNWS6WJG7eCPkuxVP608ZW72jX8u+2cOs57BDl/hWVGr1/2xY1e7Q8+b71mQ1/iGxIwTGPDKEe8HhyzHn+QiGTe6pER4Vr9SCJnyOGBKA7v1Y8p4UG1xoQeugbXuV3YH4eNspG9whlWz6o3WTh1mvaNH9fBvgZovhCYzuEa4= 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 1603748692613223.80396345061422; Mon, 26 Oct 2020 14:44:52 -0700 (PDT) Received: from localhost ([::1]:50582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAIM-0004Ui-Mp for importer@patchew.org; Mon, 26 Oct 2020 17:44:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAi-00045G-WD for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAc-0001Vl-0l for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:56 -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-11-4AGkohr0OaS7w8fZUBJOxw-1; Mon, 26 Oct 2020 17:36:46 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 98F23809DCA for ; Mon, 26 Oct 2020 21:36:45 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0800219728; Mon, 26 Oct 2020 21:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748209; 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=PADkYIFfY8n6yj7AmPITNyc+ufsFjfb5RIBcX2AxO2k=; b=SzFUpD5mv+bv2tW196YfKoTejZLk8hvNrORUMIkE9sDWhfrwSPtXp7rpQ/eGzrkXWUA9nI i/owPtaQWf6MxuyWViixllCj17HLvQ01hpR/NvYbtUzsGi37ey1o4uSeewdpH8O8rmWHLf qes/CqsqB66Og07zvfV5gRBGsYkj9lM= X-MC-Unique: 4AGkohr0OaS7w8fZUBJOxw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 07/16] qapi/expr.py: Add casts in a few select cases Date: Mon, 26 Oct 2020 17:36:28 -0400 Message-Id: <20201026213637.47087-8-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/26 02:39:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Casts are instructions to the type checker only, they aren't "safe" and should probably be avoided in general. In this case, when we perform type checking on a nested structure, the type of each field does not "stick". 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: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-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 2654a72e8333..b8720b723377 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -15,7 +15,7 @@ # See the COPYING file in the top-level directory. =20 import re -from typing import MutableMapping, Optional +from typing import MutableMapping, Optional, cast =20 from .common import c_name from .error import QAPISemError @@ -232,7 +232,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) @@ -240,7 +240,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'] @@ -337,7 +337,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 Mon Nov 17 09:46:57 2025 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=1603748536; cv=none; d=zohomail.com; s=zohoarc; b=RHhYBGb5YKswOyf3gOriJggLsfs3Tea+P6cEVE6uWgzvIOON5G9Iurk5fCXb+LkqSWv87i7yVWc+QXnhGJsIRIK02MLDORFqJMlhyHLX3sTZhdxIaT0k6aZIStPGv4gZF9UkQ8qkf1VIpP1UQfvcaF8/GRBc6oTxfJxcff2KisE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603748536; 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=oI0Dul6XNmcol0mIDhBZFd6jmLpiRD7wGUA9gFDJELA=; b=m7B6fEYztez8zBQnvZF96sks/Jd4KEHGOjsE1INNsGRnTU9lsKU6sfMhqZfSiLRxe4AzbRLJMNfBLHNTtLvqNw2lGdo/t90rgEuo25L49laVW7qI+LMZUNXuvzrH39l4KpWqojEEP3S8EQFOr1dB+8VGF+L/eLuK+2rxQKDn3bM= 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 1603748536292454.5353771250575; Mon, 26 Oct 2020 14:42:16 -0700 (PDT) Received: from localhost ([::1]:42078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAFr-0000xC-0o for importer@patchew.org; Mon, 26 Oct 2020 17:42:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAk-00047R-V4 for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60624) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAc-0001Vi-3L for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:58 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-232-Ph6iB08mMwG1KWOQWZPLhA-1; Mon, 26 Oct 2020 17:36:47 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 60E851008307 for ; Mon, 26 Oct 2020 21:36:46 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC80619728; Mon, 26 Oct 2020 21:36:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748209; 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=oI0Dul6XNmcol0mIDhBZFd6jmLpiRD7wGUA9gFDJELA=; b=EENq6L4AN5cDzrdcMHIKFVDZQCPVaIcrWIrzUX6LaC2lOaNuOJka/rK1mqX7nhbfnDfEU2 Z+qz0WqAY+KMEYClGHq8xSNS6MTU8iFzmmxZ5xFkMgninQQoW85urtSWeMyMePZXUATxaa VJJ3b7+vBM2I7ZHDkqejTa3yZDfUKRk= X-MC-Unique: Ph6iB08mMwG1KWOQWZPLhA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 08/16] qapi/expr.py: add type hint annotations Date: Mon, 26 Oct 2020 17:36:29 -0400 Message-Id: <20201026213637.47087-9-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/25 21:03:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 71 ++++++++++++++++++++++++++++--------------- scripts/qapi/mypy.ini | 5 --- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index b8720b723377..b393ccd30e92 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -15,7 +15,14 @@ # See the COPYING file in the top-level directory. =20 import re -from typing import MutableMapping, Optional, cast +from typing import ( + Iterable, + List, + MutableMapping, + Optional, + Union, + cast, +) =20 from .common import c_name from .error import QAPISemError @@ -23,9 +30,10 @@ 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] +# Expressions in their raw form are (just) JSON-like objects. +Expression =3D _JSObject =20 =20 # Names must be letters, numbers, -, and _. They must start with letter, @@ -35,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('*'): @@ -62,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) @@ -91,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( @@ -109,9 +126,9 @@ def check_flags(expr, info): "are incompatible") =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, @@ -137,7 +154,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): @@ -145,8 +162,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 @@ -190,7 +210,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): @@ -207,7 +228,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') @@ -231,7 +252,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 @@ -239,7 +260,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') @@ -265,7 +286,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: @@ -282,7 +303,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) @@ -293,7 +314,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 @@ -302,7 +323,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 c0f2a58306de..df9b05e4ab36 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -9,11 +9,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 Mon Nov 17 09:46:57 2025 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=1603748860; cv=none; d=zohomail.com; s=zohoarc; b=UAZNb+M31dZixcBk+G9zWo5YpPpe2in7SR+05JTh9Pk2d0cpLAKjIqzlOuZzh0Tb+MD9dRzFEYwKHERlhK9vkh+B+BRhJdI8Xmuu9T8BiiiTtb+eltUYVdHwsdaeqhYcCcK0+m3/ILT43LYqMl4kn0XaANlHL2Zs2C/kLslomEY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603748860; 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=TaeIISdvKHLxN9nER0GC5PZOgVkEsw2xJcGmhNEMuAM=; b=A70ZRu2I3hWMwoc7TvH44mPzbW38mbvjAhE5CBtnoexfZai+IC5dH5NvsLscZdMOwJ6Wryzb2S5VcxwhsEpnLItLxAoLTbzY6S00nPx7K5DnuGS1XRK1E/OZKZjs0Ia2Il4vmWAJcndUdSX8MLpSjy4FlbgavmZgTQUeyk35NqQ= 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 1603748860501308.72223877003387; Mon, 26 Oct 2020 14:47:40 -0700 (PDT) Received: from localhost ([::1]:59220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAL5-0008Av-C6 for importer@patchew.org; Mon, 26 Oct 2020 17:47:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAk-00046j-7h for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54112) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAd-0001W3-1H for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:36:57 -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-60-bKdD4lK1PsmTVCEfe_B4MA-1; Mon, 26 Oct 2020 17:36:48 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3BF9818C89D5 for ; Mon, 26 Oct 2020 21:36:47 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 872401972B; Mon, 26 Oct 2020 21:36:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748210; 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=TaeIISdvKHLxN9nER0GC5PZOgVkEsw2xJcGmhNEMuAM=; b=cHkjf7WENJMmuHWsjYeTkwZJehIim6OI1AsOd/7a4TMZerHYjT0cT2Owj6ecE+PL9yjq/v sEI78StOxTtMRF5rJy44DEJm9Zl5c5SPocf9uqmmDwKV10kiAH2dp8NGEyqoJiLvyYQzu9 dngDp5ejyAVUXNrPRilMCSATpyBGwfI= X-MC-Unique: bKdD4lK1PsmTVCEfe_B4MA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 09/16] qapi/expr.py: rewrite check_if Date: Mon, 26 Oct 2020 17:36:30 -0400 Message-Id: <20201026213637.47087-10-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/25 21:03:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is a 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: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa based-on: <20201026194251.11075-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 b393ccd30e92..4d4ee3daa002 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -143,15 +143,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 Mon Nov 17 09:46:57 2025 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=1603749194; cv=none; d=zohomail.com; s=zohoarc; b=lKJ37i91RkKWtLbM1/v/jdx/E9OEXzk4bzvU2KYv1QTcpdKC1Xhz/EsjScuUQz3toh9ObxFeSyLFWiICe0cSpHPA+zgSlXx6tCPVoa728BIAfP4CAhemjDnlnlN6x20GByxe/elD7iRP4SCdDcjJ9RoPr6dMN08nMWE94OlhwSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603749194; 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=kQFpYUlfuuEMOo22umOn7LMFTEt2gX8PWZrAk866k+0=; b=IP81kdTkxLqIVM/yTDPJr7NpoOZoDLMVu4O47VGDpzSpIFl3y0bKEF7L1riseIK5BmANUbLaFQaFqEwW1Aft5qPsb4d4xmgYw1Ze238B4Dd3mXT+ufW3KGwriFbV/FRBnmPAscO4Dv9tKY/FYqapBzEBOoiuKgKdDBtOSChL1us= 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 16037491949011.4904729990593069; Mon, 26 Oct 2020 14:53:14 -0700 (PDT) Received: from localhost ([::1]:42722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAQT-0004nw-Sm for importer@patchew.org; Mon, 26 Oct 2020 17:53:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAo-0004A3-LZ for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45231) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAi-0001W6-Ki for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:02 -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-181-UXiP9CaWPY6F0yKQM46mXg-1; Mon, 26 Oct 2020 17:36:48 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F37AA101EBE6 for ; Mon, 26 Oct 2020 21:36:47 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E5F619728; Mon, 26 Oct 2020 21:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748210; 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=kQFpYUlfuuEMOo22umOn7LMFTEt2gX8PWZrAk866k+0=; b=g8o95OucDRIorFQ7tRC9HcGshancshCFzursb8zC+1UjQF8ZBsHbKOz4OKGRLHLM4K4gb1 jGT4apBTbSlbmScETj1vo4s9VciyQZ+58p4oSA041k7FR64QghNNbQbG6xVSjrR5qLTe75 WQG9n+t/EUkGMILSEfgo+Tp88XOB8HY= X-MC-Unique: UXiP9CaWPY6F0yKQM46mXg-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 10/16] qapi/expr.py: Remove single-letter variable Date: Mon, 26 Oct 2020 17:36:31 -0400 Message-Id: <20201026213637.47087-11-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/26 02:39:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-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 4d4ee3daa002..99c5c2ff99b0 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -218,14 +218,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 Mon Nov 17 09:46:57 2025 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=1603748693; cv=none; d=zohomail.com; s=zohoarc; b=SD5oMdhLrRyLPw7tGiwVwbfYOP3Zq6VWWXh/Y/xiatPqD9PvxBKKCJsEO0JW/wRDhbv2Gb+WBKZkZ2Ja9YWEIN3uwnrMdnWAUR1OaWWVIPUqXJOgMWo1/aqrUnw2UCuo3Jl7DLGzTNjqWJer4wRxqH2R0ub1PbpXLRHd0/Bxl0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603748693; 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=xsC1XwWe2xZB6jZsPUnPvk/vZ/eXiMvO0aLF5vyHpbM=; b=atNUMiHMsREigpyzQiexXdCFT49cgszDDFayj55wOeuWVn8gh5bkDeTa7mEGU+VTCYF/Kj2jdWY3JfYipIX4y7wPK7n/5MNJJ3oTflm93KXkJ1BcOFqzRCuYhpeMFSSb6KibyROYQq8I5d8kNu7em4hS3OUJ2V3Fe9a5vdvHjOg= 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 16037486933381020.5586887251205; Mon, 26 Oct 2020 14:44:53 -0700 (PDT) Received: from localhost ([::1]:50720 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAIN-0004Y9-QX for importer@patchew.org; Mon, 26 Oct 2020 17:44:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60630) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAq-0004AL-F5 for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31979) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAi-0001Wd-NR for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:04 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-577-OfVrLQb0PdCR_NwviTRFag-1; Mon, 26 Oct 2020 17:36:49 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DEBBA64089 for ; Mon, 26 Oct 2020 21:36:48 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 475C11992F; Mon, 26 Oct 2020 21:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748215; 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=xsC1XwWe2xZB6jZsPUnPvk/vZ/eXiMvO0aLF5vyHpbM=; b=HvZW4bCHRXjkhOhuQRLnMFPTVeJ+FDTN1ehNxrfm/2/nqETeObJZpVcn5CIcQE2RHTCia5 WSE4TLtBW9G4JgNZhrKnB/GVKYnzOW15vNN1YB6p1t+PozvEeXGj/xrLQp+tW6I8R31jNw qCHJTvhO671PIimAKEqZr+EnWsjBHf0= X-MC-Unique: OfVrLQb0PdCR_NwviTRFag-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 11/16] qapi/expr.py: enable pylint checks Date: Mon, 26 Oct 2020 17:36:32 -0400 Message-Id: <20201026213637.47087-12-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/26 02:39:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Tested-by: Eduardo Habkost Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa Tested-by: Cleber Rosa based-on: <20201026194251.11075-1-jsnow@redhat.com> --- scripts/qapi/pylintrc | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index b9e077a1642d..fb0386d529ac 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -3,7 +3,6 @@ # Add files or directories matching the regex patterns to the ignore list. # The regex matches against base names, not paths. ignore-patterns=3Derror.py, - expr.py, parser.py, schema.py, =20 --=20 2.26.2 From nobody Mon Nov 17 09:46:57 2025 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=1603749151; cv=none; d=zohomail.com; s=zohoarc; b=exguo+hMTL8u38efoI+zPDNZ0nJ3t8lhq03hm2GuXAMxIRyrhih4bGb96iImfCkxngfAd8XZ0PacZT7jNuCRlO6qu55KEE0Ey0O+V8S2BIWTc+fLt7+t71og8uPIf83obNnftdOtp+T0TZFS4+iB7Nd/MRt9bBKCwLF8HT2gjTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603749151; 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=pJIGUTUx3HszdODAMxMubRf0iN87atBmxtqfAT/Ws6A=; b=BirQgxpwwNROjkSrQY/NJPdnKVUIHUiL2EScr7laFWahvyybJtITHQzeQz9pLoZe0ZbtyWL867OB0vcsvPopedKO74eKjQf7+JqTPhed2wAWTl4+gHuWbJqYvojJ6+ctisjEgAHoCPtHinU8UX0evRqhPfpVFl+i8//HFvhyvww= 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 160374915100973.45179997385014; Mon, 26 Oct 2020 14:52:31 -0700 (PDT) Received: from localhost ([::1]:41566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAPl-0004Im-MC for importer@patchew.org; Mon, 26 Oct 2020 17:52:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAu-0004Bf-VK for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51917) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAi-0001WJ-O3 for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:08 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-329-QMWwBojwPA2T-i4Npah5RQ-1; Mon, 26 Oct 2020 17:36:50 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A76F6101EBE3 for ; Mon, 26 Oct 2020 21:36:49 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FDC919728; Mon, 26 Oct 2020 21:36:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748212; 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=pJIGUTUx3HszdODAMxMubRf0iN87atBmxtqfAT/Ws6A=; b=G34NvJCLs6yR5qwzVJpKOzAw+5K2PLWaoearnveh7xafgB4BjRMDxKNetdAhajq5MT5UHI BNely764TRizXM0dUwzTZt7SxGCZbvdtykaQymfgpRQ23z5fdd4tq6lSMQFAWbB8UZsc63 nz4isauWmw5bFQF0suEYiNZq5P0lwMk= X-MC-Unique: QMWwBojwPA2T-i4Npah5RQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 12/16] qapi/expr.py: Add docstrings Date: Mon, 26 Oct 2020 17:36:33 -0400 Message-Id: <20201026213637.47087-13-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/26 02:39:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 167 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index 99c5c2ff99b0..8ad82ca98864 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- # -# Check (context-free) QAPI schema expression structure -# # Copyright IBM, Corp. 2011 # Copyright (c) 2013-2019 Red Hat Inc. # @@ -14,6 +12,25 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 +""" +Normalize and validate (context-free) QAPI schema expression structures. + +After QAPI expressions are parsed from disk, they are stored in +recursively nested Python data structures using Dict, List, str, bool, +and int. This module ensures that those nested structures have the +correct type(s) and key(s) where appropriate for the QAPI context-free +grammar. + +The QAPI schema expression language allows for syntactic sugar; this +module also handles the normalization process of these nested +structures. + +See `check_exprs` for the main entry point. + +See `schema.QAPISchema` for processing into native Python data +structures and contextual semantic validation. +""" + import re from typing import ( Iterable, @@ -32,7 +49,7 @@ =20 # Arbitrary form for a JSON-like object. _JSObject =3D MutableMapping[str, object] -# Expressions in their raw form are (just) JSON-like objects. +#: Expressions in their unvalidated form are JSON-like objects. Expression =3D _JSObject =20 =20 @@ -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,25 @@ 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 +113,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 +135,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 +166,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( @@ -127,6 +190,19 @@ 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]``. + + :param expr: A ``dict``; the ``if`` field, if present, will be validat= ed. + :param info: QAPI source file information. + + :forms: + :sugared: ``Union[str, List[str]]`` + :canonical: ``List[str]`` + """ =20 def check_if_str(ifcond: object) -> None: if not isinstance(ifcond, str): @@ -155,6 +231,17 @@ 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}``. + + :forms: + :sugared: ``Dict[str, Union[str, TypeRef]]`` + :canonical: ``Dict[str, TypeRef]`` + """ if isinstance(members, dict): for key, arg in members.items(): if isinstance(arg, dict): @@ -167,6 +254,21 @@ 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. + When given a string, check if that name is allowed= to + have keys that use uppercase letters, and modify + validation accordingly. + """ if value is None: return =20 @@ -212,6 +314,16 @@ 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}``. + + :forms: + :sugared: ``List[Union[str, Feature]]`` + :canonical: ``List[Feature]`` + """ if features is None: return if not isinstance(features, list): @@ -229,6 +341,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') @@ -253,6 +371,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 @@ -261,6 +385,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') @@ -287,6 +417,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: @@ -304,6 +440,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) @@ -315,6 +457,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]`` (see: `check_if`) + :features: ``Optional[Features]`` (see: `check_features`) + """ args =3D expr.get('data') boxed =3D expr.get('boxed', False) =20 @@ -324,6 +476,15 @@ 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. + :return: The same list of expressions (now modified). + """ for expr_elem in exprs: # Expression assert isinstance(expr_elem['expr'], dict) --=20 2.26.2 From nobody Mon Nov 17 09:46:57 2025 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=1603749333; cv=none; d=zohomail.com; s=zohoarc; b=Jbfhb0jT6zSsV5ToA5Za19DGBAvGh1u7Grp3y2mVfJUdalJ0TEof0MIFhuba4d7q4KWPLCcjRjeedh8yG0O5R2I14/4lXzfvZfxOHn5rUpzqjPl2naR2jyUhcCb5rM0mLzCFqJV3rWCGbaOKVp4lQ5CEMT0n4zd8Il9usLeB2aU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603749333; 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=gGFAJIbWrsePAIhsW7EqR0u/1Qreg8w5S8GElOz37dI=; b=e8qP/spHsF8eNFgi1v8uHgUjtU9H+2HoPnVlADpIWboF3GagSrVPd5lcePAys0G0eZcPebCfOHi45KArWlONVdSEprpW1pgntUCnU9VAvaC9WbeXQewOdZRq7Kcsu7Pjbs3NgIj0DV6PjCwEL7WQ1d5S4efuvlXJrJMMnitudMI= 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 1603749333310952.9732683370651; Mon, 26 Oct 2020 14:55:33 -0700 (PDT) Received: from localhost ([::1]:45816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXASi-0006B8-0p for importer@patchew.org; Mon, 26 Oct 2020 17:55:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAv-0004Ea-V9 for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48324) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAi-0001WO-O0 for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:09 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-400-c67zQgCKOACKkR5HuOn70A-1; Mon, 26 Oct 2020 17:36:51 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6BE4E8030B2 for ; Mon, 26 Oct 2020 21:36:50 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id C956E19D6C; Mon, 26 Oct 2020 21:36:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748213; 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=gGFAJIbWrsePAIhsW7EqR0u/1Qreg8w5S8GElOz37dI=; b=NhJbSqpxIp9u7GOchtLLR6EGg0DbnztI6kROPUMsd/GNAh3VXJG5HvXK8qEZY0oDAPc+Kw f3M2vSm3+iSVH89WKVXTQOkwwOnqtjukMCUPfXHz6abMITc905rRDgS2QUZBWjRP2j9z5w B/AdMoKwU/VrPcnHjpJ+ZM9M2bCqB0c= X-MC-Unique: c67zQgCKOACKkR5HuOn70A-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 13/16] qapi/expr.py: Modify check_keys to accept any Iterable Date: Mon, 26 Oct 2020 17:36:34 -0400 Message-Id: <20201026213637.47087-14-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/25 21:03:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is a 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: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-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 8ad82ca98864..883aa1781599 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -133,8 +133,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 @@ -155,7 +155,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 Mon Nov 17 09:46:57 2025 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=1603749074; cv=none; d=zohomail.com; s=zohoarc; b=B7HPk9Gkr4s4OlCDZrv/jdNWDc83w4WhFJ33xj76ihxj0+j7xnh5fM/lRdZ7OQSdNg6/RrB3ecBRExRMXrsgue4Gegnun8xaxDcSIsvTTq5BCoxEVhn6tAkXDijNJZ/07C5OhI9XQ7NMKtsvGHE3Qlx24sXDFZx8HjZLAoawKpE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603749074; 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=m+EZJX0eQxg+80kMWX3ibga94kOWka1lb3G7YdUIwjs=; b=E4XP5AsZYZ+RpqmUPLflKIcTGAknZLUs6N4cIkI+a2pEGnTNBStFtxD7M0lvDvsKWlYOUk4YVmBSTQwrNhuQEmds/y9olrm0H60hP1ESzXtooaY/2Guhr00gSg191H0cjHnDXdh3pFb+BlhKTLvHiYYfA8SKIdtpvM9EeSuoM40= 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 160374907442965.71556840968537; Mon, 26 Oct 2020 14:51:14 -0700 (PDT) Received: from localhost ([::1]:38576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXAOX-0002xq-A2 for importer@patchew.org; Mon, 26 Oct 2020 17:51:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAn-000493-SS for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:46697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAi-0001WS-Kt for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:01 -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-478-JLAwioocMW-D33uKLlDKnA-1; Mon, 26 Oct 2020 17:36:52 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 340D41868431 for ; Mon, 26 Oct 2020 21:36:51 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E03819728; Mon, 26 Oct 2020 21:36:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748214; 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=m+EZJX0eQxg+80kMWX3ibga94kOWka1lb3G7YdUIwjs=; b=hD+WQ7LwkHrYIw82PYYc6CPAtBg5F6xk1GFKSDLxJZC2+XGV1CbBSnBWMrEnrjYLYauN9m dxtT0Cpma6kJS9NcaGiI+JGmibBXhaGXervdE0KWLAMfxm47P4twEgNRmlpH4zI7Al+Dfo BbxqENtSP6d7LIea4B5h1llBERwBTcY= X-MC-Unique: JLAwioocMW-D33uKLlDKnA-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 14/16] qapi/expr.py: Use tuples instead of lists for static data Date: Mon, 26 Oct 2020 17:36:35 -0400 Message-Id: <20201026213637.47087-15-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/25 21:03:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It is -- maybe -- possibly -- three nanoseconds faster. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-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 883aa1781599..9253560cd9ce 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -172,11 +172,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', 'coroutine']: + for key in ('boxed', 'allow-oob', 'allow-preconfig', 'coroutine'): if key in expr and expr[key] is not True: raise QAPISemError( info, "flag '%s' may only use true value" % key) --=20 2.26.2 From nobody Mon Nov 17 09:46:57 2025 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=1603749020; cv=none; d=zohomail.com; s=zohoarc; b=hgW8zE8Z/Votx1RCEtrRbgQBGyMbGw48SV/Tg82Gnhzl//E37/J0Fuxyxk0MtjQCY8fugW+VHqTGlc55X9BWkgQ45F4zaFkOUcyjdDcxJu+tHXe8Oc7Cz6sHlx81Ne/Bx3qQrp99Yg0EI9K+v0XTp7qHEsASFrwPsb8j9yllLRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603749020; 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=BzR1jpkyEvGckWPaDmHWHkzzpNd44v+7R6OfTtEDH+4=; b=SHVM2W1oIgKL5nxScud8N+xuuQZr3uYX3KFVfY9Kg6VrgXlWRZDLdRsEAAGcFVqBmSNzkctujH4hmZWoBzKGRFcdWVeQ4GVgAhSS4y34gmJWi6JBQuFkHBVfT6xIcs4dXH8JxOXKYtX6Ao2fcpO2rT6PkJHvhTSKT2YHqoiv+rw= 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 1603749020490739.0253264933858; Mon, 26 Oct 2020 14:50:20 -0700 (PDT) Received: from localhost ([::1]:37276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXANe-0002OP-Vv for importer@patchew.org; Mon, 26 Oct 2020 17:50:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60610) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAo-00049P-3M for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22833) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAi-0001WY-MX for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:01 -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-155-Tbxvh5SfNJ24Eyvs5WQ9zw-1; Mon, 26 Oct 2020 17:36:52 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F3745809DD5 for ; Mon, 26 Oct 2020 21:36:51 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B90519728; Mon, 26 Oct 2020 21:36:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748214; 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=BzR1jpkyEvGckWPaDmHWHkzzpNd44v+7R6OfTtEDH+4=; b=ai7vVRuYeWb67kw6uWumS827eIlfWTPuXo5olEEVmI0lFXPcLdg/5A7okIyVryIMRNfqSp Wxum5cFjkn90HhgXYTY3s9xvT7hGVK/byxDdEjMWOmaCYVOfFqBwNbaJQEaziFMkp9VtIs ZcG/E3dfJbZwDb8js0OUHWkFekyvlfk= X-MC-Unique: Tbxvh5SfNJ24Eyvs5WQ9zw-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 15/16] qapi/expr.py: move related checks inside check_xxx functions Date: Mon, 26 Oct 2020 17:36:36 -0400 Message-Id: <20201026213637.47087-16-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/26 02:39:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There's not a big obvious difference between the types of checks that happen in the main function versus the kind that happen in the functions. Now they're in one place for each of the main types. As part of the move, spell out the required and optional keywords so they're obvious at a glance. Signed-off-by: John Snow Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-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 9253560cd9ce..3b62e801a42c 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -347,6 +347,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') @@ -377,6 +381,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 @@ -391,6 +400,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') @@ -423,6 +439,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: @@ -446,6 +467,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', 'coroutine')) + normalize_members(expr.get('data')) + args =3D expr.get('data') rets =3D expr.get('returns') boxed =3D expr.get('boxed', False) @@ -467,6 +495,11 @@ def check_event(expr: Expression, info: QAPISourceInfo= ) -> None: :if: ``Optional[Ifcond]`` (see: `check_if`) :features: ``Optional[Features]`` (see: `check_features`) """ + check_keys(expr, info, 'event', + required=3D['event'], + optional=3D('data', 'boxed', 'if', 'features')) + normalize_members(expr.get('data')) + args =3D expr.get('data') boxed =3D expr.get('boxed', False) =20 @@ -534,38 +567,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', 'coroutine']) - normalize_members(expr.get('data')) check_command(expr, info) elif meta =3D=3D 'event': - check_keys(expr, info, meta, - ['event'], ['data', 'boxed', 'if', 'features']) - normalize_members(expr.get('data')) check_event(expr, info) else: assert False, 'unexpected meta type' --=20 2.26.2 From nobody Mon Nov 17 09:46:57 2025 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=1603749373; cv=none; d=zohomail.com; s=zohoarc; b=V+SVZI/hp2hJXtZtqEDEDELCEx2KmUI5eBy5m4Kk992GFynEnu86TJXGiGw/IH5+eqwegJHVqny0ZsNNrA4WquYEDMXFFf7a+jdkOBjXdRp/he5V01a+TTVA1u6SzcPq/a4XXZSpb//o24XHVJb5jg6f7+3G0nzF/pOBYuj+qmc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1603749373; 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=ML+qe2yQqzou6+7JqLkJ3Tzy6XHzJrxKeTvXUwHkH2c=; b=U+haoYgelDNd2bF+Dz0JitQm9mEJAl5lJnrDctQgG6iHwEXS7DivQSiQ5uOvUYnqDVxk5XyE8PftNY3g+LR1/WRxo2dJjSwz0JM8bfxs5i2PGzRCgDx5HO7zVv17CTvaRFrGoVEhEwoRzAbCAS4N95OlLxP/+MHSTrXEcOzAFfY= 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 1603749373779866.8608734814266; Mon, 26 Oct 2020 14:56:13 -0700 (PDT) Received: from localhost ([::1]:47314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXATM-0006rz-PB for importer@patchew.org; Mon, 26 Oct 2020 17:56:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXAAu-0004AX-Eb for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:55955) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kXAAi-0001Wk-MX for qemu-devel@nongnu.org; Mon, 26 Oct 2020 17:37:08 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-62-W-WP03WjMZKtyIfsxGxIdQ-1; Mon, 26 Oct 2020 17:36:53 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CC7B58030B2 for ; Mon, 26 Oct 2020 21:36:52 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-238.rdu2.redhat.com [10.10.118.238]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2026319728; Mon, 26 Oct 2020 21:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603748215; 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=ML+qe2yQqzou6+7JqLkJ3Tzy6XHzJrxKeTvXUwHkH2c=; b=Z8EG5Nct/jXYIKb0sfedGYGvYjENs66PXd95lSe9rnuRoHdQsB7hnE4tSq+8t7TyB0oHcZ dkoiizrBMzba4yNY0ur2jNZ+70E3JE/NaviyOIBdeuRpoD1o6dFVQJl51r4lmuy90iLMqQ KIeWM4fBELYIHiTXQ+u02Vtmf16kjE4= X-MC-Unique: W-WP03WjMZKtyIfsxGxIdQ-1 From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v2 16/16] qapi/expr.py: Use an expression checker dispatch table Date: Mon, 26 Oct 2020 17:36:37 -0400 Message-Id: <20201026213637.47087-17-jsnow@redhat.com> In-Reply-To: <20201026213637.47087-1-jsnow@redhat.com> References: <20201026213637.47087-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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/10/25 21:03:19 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_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: John Snow , Eduardo Habkost , Cleber Rosa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This enforces a type signature against all of the top-level expression check routines without necessarily needing to create some overcomplicated class hierarchy for them. Signed-off-by: John Snow Reviewed-by: Eduardo Habkost Reviewed-by: Cleber Rosa based-on: <20201026194251.11075-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 3b62e801a42c..3b0a589652c9 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, @@ -508,6 +511,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] @@ -534,28 +557,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: @@ -566,22 +581,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