From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814407; cv=none; d=zohomail.com; s=zohoarc; b=DEEFwQNNEQcopW/wazlQ1lNmTtFdrjpaS2gn+Km9W5kqf1shzV1WJnA9sQkh5ywl3G5v6a03gsuAy3x0n3W85ee8Q/40wotZiDNnrLrFDLOsFPMrYJkjRW3fNHXnmu9pDLq7GTHfR10JyFeKRg6B62pfGOmM8uM2t6Zt86Hibcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814407; 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=ZMY/wzTC1WX5rSMzZEfkvQygIqZldMtlPzP4tLxY3L4=; b=GtKOWV8hz6kvg1YWADlFCnxeGjDg3BnoUmgM/YjquohvTvQ418Bc41D8g6UWeSwCmx/hJb2xbOssgik5cqJQzViwrZj4MVsrSHv/3eNaGp+rA/cjCrYTqXZMqLpsM5pMKyrUnOulZ1wSzR3SNLaL8965V2/CG+X3Ba7vuUKHW+Y= 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 1600814407332279.5854785708136; Tue, 22 Sep 2020 15:40:07 -0700 (PDT) Received: from localhost ([::1]:53418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqxB-0002fi-Vv for importer@patchew.org; Tue, 22 Sep 2020 18:40:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57994) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqsr-00048M-5U for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22325) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqso-0007bI-FI for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:36 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-490-VLWWGsa4N92iU4kRc2aWCw-1; Tue, 22 Sep 2020 18:35:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9B2731074641; Tue, 22 Sep 2020 22:35:28 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8445460C05; Tue, 22 Sep 2020 22:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814133; 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=ZMY/wzTC1WX5rSMzZEfkvQygIqZldMtlPzP4tLxY3L4=; b=SrCP1h2kq2utpzdO5t0HcRe4cQqyiTShXuOvXoruHakpT+TSGNp8AjwLANZ2GDt4GfTGv+ EBoe65L8baW4aWUgDgcNSnWDF962E1HLPI/V4xCm3qi+DFoLbUjLsXpqb4mVLRUZajrdxh /DuqcBgRbFTP0N99a1IEGk3DdT0sNwE= X-MC-Unique: VLWWGsa4N92iU4kRc2aWCw-1 From: John Snow To: Markus Armbruster Subject: [PATCH 01/26] qapi/parser.py: refactor parsing routine into method Date: Tue, 22 Sep 2020 18:35:00 -0400 Message-Id: <20200922223525.4085762-2-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For the sake of keeping __init__ easier to reason about, with fewer variables in play. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 8be4570c31..55117f5754 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -46,28 +46,34 @@ class QAPIDocError(QAPIError): class QAPISchemaParser: =20 def __init__(self, fname, previously_included=3DNone, incl_info=3DNone= ): - previously_included =3D previously_included or set() - previously_included.add(os.path.abspath(fname)) + self._fname =3D fname + self._included =3D previously_included or set() + self._included.add(os.path.abspath(self._fname)) + + self.cursor =3D 0 + self.info =3D QAPISourceInfo(self._fname, 1, incl_info) + self.line_pos =3D 0 + self.exprs =3D [] + self.docs =3D [] =20 try: - fp =3D open(fname, 'r', encoding=3D'utf-8') + fp =3D open(self._fname, 'r', encoding=3D'utf-8') self.src =3D fp.read() except IOError as e: raise QAPISemError(incl_info or QAPISourceInfo(None, None, Non= e), "can't read %s file '%s': %s" % ("include" if incl_info else "schema", - fname, + self._fname, e.strerror)) + self._parse() =20 + def _parse(self): + cur_doc =3D None + + # Prime the lexer: if self.src =3D=3D '' or self.src[-1] !=3D '\n': self.src +=3D '\n' - self.cursor =3D 0 - self.info =3D QAPISourceInfo(fname, 1, incl_info) - self.line_pos =3D 0 - self.exprs =3D [] - self.docs =3D [] self.accept() - cur_doc =3D None =20 while self.tok is not None: info =3D self.info @@ -86,12 +92,12 @@ def __init__(self, fname, previously_included=3DNone, i= ncl_info=3DNone): if not isinstance(include, str): raise QAPISemError(info, "value of 'include' must be a strin= g") - incl_fname =3D os.path.join(os.path.dirname(fname), + incl_fname =3D os.path.join(os.path.dirname(self._fname), include) self.exprs.append({'expr': {'include': incl_fname}, 'info': info}) exprs_include =3D self._include(include, info, incl_fname, - previously_included) + self._included) if exprs_include: self.exprs.extend(exprs_include.exprs) self.docs.extend(exprs_include.docs) --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814199; cv=none; d=zohomail.com; s=zohoarc; b=JGfaOGS0/m9eRF+WIcHbRT/8vVqMgs2w5zmKlYyeijK23be+wKhQ0awpkXq4qI2NEIUfJ75vrWp/xkJ9a2+h0sm7IVGmyNzB43eYc5lBCKqWH2+Z35lM2uH7n6lnSNWfidlR+9mpeRvzEoIBtCECwxojow9GEvaMFY5UDs+uUOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814199; 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=91Nfs25MUnlz2lbX63MuZ0javddZdJuS/LqgOXEy65A=; b=ihIhhSdWGmFRiI3PowgJQj2YVKByXAmhYUUZl30wih1qrX2iJ2Ct4TGWnLblPknuAjnodCHiVLL8iMIu/XFY/x2F2GFrdSnrlKHyYi5+6ccNg+L9SAhe+AYhZRAwpk4Eaa9pbFqgWm/gyqWYi4pnJLKZdN12xuJdoMmcvRUve28= 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 16008141998533.304916061024528; Tue, 22 Sep 2020 15:36:39 -0700 (PDT) Received: from localhost ([::1]:40818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqtq-0005vm-F1 for importer@patchew.org; Tue, 22 Sep 2020 18:36:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqsr-00049K-KP for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58481) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqso-0007bR-TS for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-542-q6WJou7sNkSlvYzPqhNYeQ-1; Tue, 22 Sep 2020 18:35:30 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B15A5801AEB; Tue, 22 Sep 2020 22:35:29 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id E1AA160BF4; Tue, 22 Sep 2020 22:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814134; 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=91Nfs25MUnlz2lbX63MuZ0javddZdJuS/LqgOXEy65A=; b=iST5jX3z/ByDb3C14+/vUIqCb5I520cB/fC2DXRi8n0cbzSlFckV/hZIzAi9dOTf5Xsbsw jl20QfgTf2Pd3xJ/3tfhHOhfX0pLjFR8WLcm38xKlYP80AfI8lopfw4r8QMj4Tp3N9qITu +bnETMVStMtQ+DvhAMcVAvFrMk6Br2A= X-MC-Unique: q6WJou7sNkSlvYzPqhNYeQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 02/26] qapi/parser.py: group variable declarations in __init__ Date: Tue, 22 Sep 2020 18:35:01 -0400 Message-Id: <20200922223525.4085762-3-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add missing declarations and group them by function so they're easier to understand at a distance. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 55117f5754..b2984c8ff0 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -50,12 +50,19 @@ def __init__(self, fname, previously_included=3DNone, i= ncl_info=3DNone): self._included =3D previously_included or set() self._included.add(os.path.abspath(self._fname)) =20 + # Lexer state (see `accept` for details): + self.tok =3D None + self.pos =3D 0 self.cursor =3D 0 + self.val =3D None self.info =3D QAPISourceInfo(self._fname, 1, incl_info) self.line_pos =3D 0 + + # Parser output: self.exprs =3D [] self.docs =3D [] =20 + # Showtime! try: fp =3D open(self._fname, 'r', encoding=3D'utf-8') self.src =3D fp.read() --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814272; cv=none; d=zohomail.com; s=zohoarc; b=jiQwx8+IDJNqhS2r6/zsp4BVdRFggsg1aUk3Un8ETuOJHnuS9gaguqF8uhYOGnUCUerRhd40nHLC8z1s9SJt2EvKrI8o1CT5l+PNvCckPTrn2Mb0Ah3uGoOtvoVB+n5R8VaW9KByXfr1suszG7uJlwq28TIg3QAoDBwF/9YcFe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814272; 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=snMperRcJ+yh2ihxI2qqgjRXS3cpwHmHoHiVVHkmroA=; b=OIOULR8r1xywmOo0LzNHSu6Nd81P/xlQBd7Pi9vZfnMnjACMjnrOSF/XiRpgMn2YBt3XiPl9qhPUfP44EU6/Hj00W3VNwotx/k5EcabuVk7uHsev1Urf09By0k3LjxAyIrqt5LbmzGDbVPWU7Dx2bLz2vhZObe4H6J52YNQfEHQ= 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 16008142729671012.6582857200866; Tue, 22 Sep 2020 15:37:52 -0700 (PDT) Received: from localhost ([::1]:44754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqv1-0007XO-Kb for importer@patchew.org; Tue, 22 Sep 2020 18:37:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqsq-00046k-2B for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:36 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:52837 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqso-0007bL-EQ for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:35 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-281-KBVqvTtjMQqY_sgBX2amTQ-1; Tue, 22 Sep 2020 18:35:31 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id ACA0D81CAFB; Tue, 22 Sep 2020 22:35:30 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id DCA8060BF4; Tue, 22 Sep 2020 22:35:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814133; 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=snMperRcJ+yh2ihxI2qqgjRXS3cpwHmHoHiVVHkmroA=; b=OaNAoAsoHhcL4hXeXlfpWZK9SzVKAa35ecMjk87VKTVzYo62asDwXum4dj2NrRp1nUlRhf tQIX0kZttT/28mY39M5W1TQd5OUdq87YqBZGvW9z43hkcQAqVMc6bmQDKzqES6XAWkVhQw 51DtzGqMMQQh4ZVcVqvwWkV9NHNaD2U= X-MC-Unique: KBVqvTtjMQqY_sgBX2amTQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 03/26] qapi/parser.py: use 'with' statement for opening files Date: Tue, 22 Sep 2020 18:35:02 -0400 Message-Id: <20200922223525.4085762-4-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 17:01:35 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Minor, this prevents file descriptor leaks on error pathways. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index b2984c8ff0..d0f35fe03e 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -64,8 +64,8 @@ def __init__(self, fname, previously_included=3DNone, inc= l_info=3DNone): =20 # Showtime! try: - fp =3D open(self._fname, 'r', encoding=3D'utf-8') - self.src =3D fp.read() + with open(self._fname, 'r', encoding=3D'utf-8') as fp: + self.src =3D fp.read() except IOError as e: raise QAPISemError(incl_info or QAPISourceInfo(None, None, Non= e), "can't read %s file '%s': %s" --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814201; cv=none; d=zohomail.com; s=zohoarc; b=YxLDCmp3D8xvyq+GaUajbE14a5iEmmHQC7fsASKeZPsjLCkut89I46z0pusr/0VlODuo98mLjHV8TeHKAYnkIkI6NfncFIThqi2LzjA48Mr47qZ0aKu/Cn2VuOYWRZZo9qY05Pc3K8GvyF2D1Tp4S3DlewntxJZB61YvTLA97Z4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814201; 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=nyuvQY54G53HH6uqI9lGJUDHNNFkR+Pw2q847xGGx5c=; b=CE5xWEBvgxs0F0R8P5cfxsxjqUJk9WUTerdx97CNFpYxcSoTNWmom9XvjFx4k7vHBUKzU5s9iKDmzYxDLa/Z/MeRYTPjJ9H/2GVrIYPC3Fneh2AlQzq19FAIM++lvEoRmE1OYlWMHLT9VuLyI66B2P0gjYbo2tFNTN4/QFqpja0= 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 1600814201754879.8755940340645; Tue, 22 Sep 2020 15:36:41 -0700 (PDT) Received: from localhost ([::1]:41060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqts-00061k-Co for importer@patchew.org; Tue, 22 Sep 2020 18:36:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58042) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqst-0004CR-6t for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:59417) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqsr-0007cQ-Bt for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:38 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-325-cKbZRuhAOtesMk6PVosQXQ-1; Tue, 22 Sep 2020 18:35:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9FEC425E0; Tue, 22 Sep 2020 22:35:31 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id D6E4160BF4; Tue, 22 Sep 2020 22:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814136; 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=nyuvQY54G53HH6uqI9lGJUDHNNFkR+Pw2q847xGGx5c=; b=X1/PZ2Bi64jY1OPWIqDTJyPUu/xAjuTjxo1nlpe09TpBtK7J1yneYiaBWSC5nmbZpTGCZ4 5upf/j3iGwIZTzmzSoZZKQQ7DCfrv7mE47EN7N+zbTI3nFm3ED58f2MwSmowhvP9nfO1iI lOmDo4myw1/GJ7hSb6DcPCzCRClCheM= X-MC-Unique: cKbZRuhAOtesMk6PVosQXQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 04/26] qapi/source.py: Add default arguments to QAPISourceInfo Date: Tue, 22 Sep 2020 18:35:03 -0400 Message-Id: <20200922223525.4085762-5-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The parser tries to create an object as QAPISourceInfo(None, None, None). Add some defaults to QAPISourceInfo such that we don't need to pass explicit as many explicit nothings. Having the defaults nearby the code in source.py also helps remind us that they might be unset. Using a numerical 0 to mean "no line" is nicer to type than using None for the same. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 2 +- scripts/qapi/source.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index d0f35fe03e..db4e9ae872 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -67,7 +67,7 @@ def __init__(self, fname, previously_included=3DNone, inc= l_info=3DNone): with open(self._fname, 'r', encoding=3D'utf-8') as fp: self.src =3D fp.read() except IOError as e: - raise QAPISemError(incl_info or QAPISourceInfo(None, None, Non= e), + raise QAPISemError(incl_info or QAPISourceInfo(None), "can't read %s file '%s': %s" % ("include" if incl_info else "schema", self._fname, diff --git a/scripts/qapi/source.py b/scripts/qapi/source.py index ba991d798f..d1de9e36b1 100644 --- a/scripts/qapi/source.py +++ b/scripts/qapi/source.py @@ -30,7 +30,10 @@ def __init__(self) -> None: class QAPISourceInfo: T =3D TypeVar('T', bound=3D'QAPISourceInfo') =20 - def __init__(self: T, fname: str, line: int, parent: Optional[T]): + def __init__(self: T, + fname: str, + line: int =3D 0, + parent: Optional[T] =3D None): self.fname =3D fname self.line =3D line self.parent =3D parent @@ -53,7 +56,7 @@ def loc(self) -> str: if self.fname is None: return sys.argv[0] ret =3D self.fname - if self.line is not None: + if self.line: ret +=3D ':%d' % self.line return ret =20 --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814353; cv=none; d=zohomail.com; s=zohoarc; b=VvUy4FQg0OTFCfkIXOGLViL27Bco8c2euVqW5bd36z61eDdj/26JpgEjwCbhi6JoyJ+EdEm8b6HX4BFHVAK53xGqAONDMXe6UggPpv8CPNRI0RcMLz+XLfg+yb6bcXICHnOQZerBI8cgqDcl3QYi0ZvbZHePMYApbSLDwsta7PY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814353; 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=78Pk7z0SL79eqX9LpB/A0ZFDcXbAXaC/dqYUGtV0ckg=; b=f7hdVyAtnTacVpswVESe0KauKwRRv5XrqallxQqYEkbk7pv9ChTBStbvWa+PaF/m1rp4BbCkz+4NQrWrZdI4jK+A0c2gY8I4QxxqXqc3SaTKpxvrHYmWOFHMKySKXxSlJvmhdBo9DIvKjcBA5/SP4uT+rRX8yWN42YesilB1Rsg= 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 1600814353354172.38478771222321; Tue, 22 Sep 2020 15:39:13 -0700 (PDT) Received: from localhost ([::1]:49170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqwJ-0000wL-TC for importer@patchew.org; Tue, 22 Sep 2020 18:39:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58014) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqss-0004A5-4y for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47681) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqsq-0007c7-GG for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:37 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-43-9Z2S4PshODySUI640UdPWQ-1; Tue, 22 Sep 2020 18:35:33 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A92FB186DD28; Tue, 22 Sep 2020 22:35:32 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id D69F360CCC; Tue, 22 Sep 2020 22:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814135; 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=78Pk7z0SL79eqX9LpB/A0ZFDcXbAXaC/dqYUGtV0ckg=; b=RFaA7pt8XvhNAZQ6fQJy1CejLou5d+nFlTPvRwmDFsYsKNvJA6yEcKXSG3nlvWYugogKl7 JfPTKjI9U/8tSlLmoosfS79bvJf0fYR/PQ9MheHTtVXHy9kVrK8YqhvXKfilmR8wfHVNYM bpUc15+9KFQ0l9tHL2yxr/mTHFpoDTY= X-MC-Unique: 9Z2S4PshODySUI640UdPWQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 05/26] qapi/parser.py: start source info at line 0 Date: Tue, 22 Sep 2020 18:35:04 -0400 Message-Id: <20200922223525.4085762-6-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Before we have any actual line context, we still have a file context. We can use this to report errors without mentioning a specific line. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index db4e9ae872..fc0b1516cc 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -55,7 +55,7 @@ def __init__(self, fname, previously_included=3DNone, inc= l_info=3DNone): self.pos =3D 0 self.cursor =3D 0 self.val =3D None - self.info =3D QAPISourceInfo(self._fname, 1, incl_info) + self.info =3D QAPISourceInfo(self._fname, parent=3Dincl_info) self.line_pos =3D 0 =20 # Parser output: @@ -78,6 +78,7 @@ def _parse(self): cur_doc =3D None =20 # Prime the lexer: + self.info.line +=3D 1 if self.src =3D=3D '' or self.src[-1] !=3D '\n': self.src +=3D '\n' self.accept() --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814508; cv=none; d=zohomail.com; s=zohoarc; b=TwNeX/pFIlqRVAeLt+Nc9e1sQEFgECGn51jcMRZ4RduMUvt4XBh8wFyeIUpvP2CJ10Fy3HuiPJCmERm1d6XY1jl6O5CXv1EoIKkv7c8tnIOh0w5iseekdMeixG6TVRTna4FtTqN53Pv+8hVBAslrrX1V1AFecNPCbgWGmJ9Mv7M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814508; 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=K7ZGPCpFeOKGAGDsqGCIaOZb4bSdwvi6S6v977znT0s=; b=GCQxhsE9FT4TN7StyO3bhA5thB9i/r//6gzSVhr5eau5SGJCYZqzYaqif14KTmNopbK3CDG8n5MUlYDhfNzzFnTr2agbmiR/4wRmK0s6gnfLEdzm8e3TnyEdhE4enW6WPzw1WdtW0NnI+T2o5cqCHGw3OT1vb4PXWXl+znYClQ4= 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 160081450808590.3573711794703; Tue, 22 Sep 2020 15:41:48 -0700 (PDT) Received: from localhost ([::1]:57866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqyo-0004V1-RT for importer@patchew.org; Tue, 22 Sep 2020 18:41:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqsv-0004IU-Sd for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqsu-0007dJ-68 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-143-MDtuzdY0M9yGt3HD_r54Cg-1; Tue, 22 Sep 2020 18:35:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BD5061005E74; Tue, 22 Sep 2020 22:35:33 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3B0860E1C; Tue, 22 Sep 2020 22:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814139; 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=K7ZGPCpFeOKGAGDsqGCIaOZb4bSdwvi6S6v977znT0s=; b=LdWy2D4EKK4jcuyxKS0XNxAk9eRc+9toFrCvw113e05ebq3xjQ/FELj1xhDZM50mX3Plki lfVy9gGHvu86PXZokYm9Yko3HuWyAJMNFc3Bl1PHH3jRKYpP//bY1B8Tyca23qfPOO1Kyg fRCEiDd56Wbo8+7FMN/ifEAbKKP26X4= X-MC-Unique: MDtuzdY0M9yGt3HD_r54Cg-1 From: John Snow To: Markus Armbruster Subject: [PATCH 06/26] qapi/parser.py: raise QAPIParseError during file opening Date: Tue, 22 Sep 2020 18:35:05 -0400 Message-Id: <20200922223525.4085762-7-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Now that we can have exception contexts that don't specify a specific line, we can use that context to raise errors when opening the file. If we don't have a parent context, we can simply use our own. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index fc0b1516cc..5a7233bc76 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -67,11 +67,13 @@ def __init__(self, fname, previously_included=3DNone, i= ncl_info=3DNone): with open(self._fname, 'r', encoding=3D'utf-8') as fp: self.src =3D fp.read() except IOError as e: - raise QAPISemError(incl_info or QAPISourceInfo(None), - "can't read %s file '%s': %s" - % ("include" if incl_info else "schema", - self._fname, - e.strerror)) + msg =3D "can't read {kind:s} file '{fname:s}': {errmsg:s}".for= mat( + kind=3D'include' if incl_info else 'schema', + fname=3Dself._fname, + errmsg=3De.strerror + ) + context =3D incl_info or self.info + raise QAPIParseError(context, msg) from e self._parse() =20 def _parse(self): --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814355; cv=none; d=zohomail.com; s=zohoarc; b=l4Sn0He58zDK7aqqVd7HGwEtAspw7GQs7F6dmuze5NKaum1vR8m8B8QA2MoZ7rNBYqIydRmLO/igipVHX7Bg3Z2V8+gbprVMs+9p1nyDjDHCL1fUIe/lUzdosR2zuktunPZvQPudY6WkxSBgzjARkHu8KkHVyhWAm/gexqRVXTw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814355; 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=HY4iHPLX+Mtqs4MtwyCFbQw0nV6/SF3Tme+QPV8lnWE=; b=W2gkT6fAFCOMn37TnyEFlXmI56zKpalICLvn7XpAyjzrGZShMOF1PQPASAY4bGPqp1Koql5ozZzsANNJnfSw+vgVfm9mLiKWMeqwJzfalvRFH9xsWrqFWHVVCQLJBk1357TV+EL7rGX5jTTso++7782gE8+Ht92q+GuB4wb8Qws= 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 1600814355891774.6580718550038; Tue, 22 Sep 2020 15:39:15 -0700 (PDT) Received: from localhost ([::1]:49422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqwM-00013F-HS for importer@patchew.org; Tue, 22 Sep 2020 18:39:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqsu-0004EE-1Y for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:49102) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqss-0007cj-Cp for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:39 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-54-wAUacH1bOYyLil5r-ogUwg-1; Tue, 22 Sep 2020 18:35:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C2AEB186DD27; Tue, 22 Sep 2020 22:35:34 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA1A760BF4; Tue, 22 Sep 2020 22:35:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814137; 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=HY4iHPLX+Mtqs4MtwyCFbQw0nV6/SF3Tme+QPV8lnWE=; b=UtG/i6b55LRmpw6+VIHwyXurFRim34/lZgmCivFaejuKY23ahFSvIB8Byz0mc9f5p9vOvm iswsy4O439K6d3PCCYiqJRS82LCly7i6TKwUBxy46hA2OMP8irXqUExnJxDBIzmjDL0xAY TjLP9gKwdPRUkjW/79VPiKsqGsXWRjk= X-MC-Unique: wAUacH1bOYyLil5r-ogUwg-1 From: John Snow To: Markus Armbruster Subject: [PATCH 07/26] qapi/parser.py: fully remove 'null' constant Date: Tue, 22 Sep 2020 18:35:06 -0400 Message-Id: <20200922223525.4085762-8-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Based on the docs, we don't support the null constant, and the code agrees. There's a few remnants where callers check .tok for 'n', and these can be removed. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 8 ++++---- tests/qapi-schema/leading-comma-list.err | 2 +- tests/qapi-schema/trailing-comma-list.err | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 5a7233bc76..78355ca93f 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -274,9 +274,9 @@ def get_values(self): if self.tok =3D=3D ']': self.accept() return expr - if self.tok not in "{['tfn": + if self.tok not in "{['tf": raise self._parse_error( - "expected '{', '[', ']', string, boolean or 'null'") + "expected '{', '[', ']', string, or boolean") while True: expr.append(self.get_expr(True)) if self.tok =3D=3D ']': @@ -295,12 +295,12 @@ def get_expr(self, nested): elif self.tok =3D=3D '[': self.accept() expr =3D self.get_values() - elif self.tok in "'tfn": + elif self.tok in "'tf": expr =3D self.val self.accept() else: raise self._parse_error( - "expected '{', '[', string, boolean or 'null'") + "expected '{', '[', string, or boolean") return expr =20 def _get_doc(self, info): diff --git a/tests/qapi-schema/leading-comma-list.err b/tests/qapi-schema/l= eading-comma-list.err index 76eed2b5b3..0725d6529f 100644 --- a/tests/qapi-schema/leading-comma-list.err +++ b/tests/qapi-schema/leading-comma-list.err @@ -1 +1 @@ -leading-comma-list.json:2:13: expected '{', '[', ']', string, boolean or '= null' +leading-comma-list.json:2:13: expected '{', '[', ']', string, or boolean diff --git a/tests/qapi-schema/trailing-comma-list.err b/tests/qapi-schema/= trailing-comma-list.err index ad2f2d7c97..bb5f8c3c90 100644 --- a/tests/qapi-schema/trailing-comma-list.err +++ b/tests/qapi-schema/trailing-comma-list.err @@ -1 +1 @@ -trailing-comma-list.json:2:36: expected '{', '[', string, boolean or 'null' +trailing-comma-list.json:2:36: expected '{', '[', string, or boolean --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814506; cv=none; d=zohomail.com; s=zohoarc; b=YgarW14zYo8CCWtzd6FGeNVEgjAkd5dDzWXEdxPvJcbH9ncwLWGBdd0AZceLqC7PDT4gmZp90BexSDiPBALbWL/HrYn/b5fzxF473FfuYh/CsW+K7kpxJigmU8m6H237whRVQ/MHrtX6i7SoEuEIKI7Xa+k5OszzlCtLouS/SjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814506; 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=EFGub7ZhjjnhzVH7ElCNIqLLQL5ff0E2HEr5DzbLLds=; b=QiKbkpNaCWEmMuKw/XKTUJ06WymO/anB/ft4OzZQokgfyC5anIhRBWejjSmn1ocE+mekiZQ9fplLiGTcklR/os+vwvVnWlpD9jheKgb9KF5OBxAOgGxHI4wng3a35TYMgDLUWrtQsH/SoNe1T9J/RwgQG4ziok9rZG6usDybfhk= 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 1600814506641905.6361849452009; Tue, 22 Sep 2020 15:41:46 -0700 (PDT) Received: from localhost ([::1]:57602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqyn-0004N1-8s for importer@patchew.org; Tue, 22 Sep 2020 18:41:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58080) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqsv-0004Hv-Kh for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:35844) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqst-0007d7-Uf for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:41 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-138-giPYim8bNeCw0kcI1VU16A-1; Tue, 22 Sep 2020 18:35:36 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01BBF1005E64; Tue, 22 Sep 2020 22:35:36 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE026610AF; Tue, 22 Sep 2020 22:35:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814138; 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=EFGub7ZhjjnhzVH7ElCNIqLLQL5ff0E2HEr5DzbLLds=; b=H8zxzwBo3LUM/hZG9ihb1Lfc+nCRZg4vdJy8MkORRNqcorj+qsM1J0nqt7tnf5ytN2fMzT M2IzP+0W3CatmUkT0EMRP0lAbTPWKe7B91zQdkNG/ATxOyZSXcKp6wI3zPI9XB70xIvuoP Az9bFitNwml8suUYenoC5bVC2MSLS0s= X-MC-Unique: giPYim8bNeCw0kcI1VU16A-1 From: John Snow To: Markus Armbruster Subject: [PATCH 08/26] qapi/parser.py: Assert lexer value is a string Date: Tue, 22 Sep 2020 18:35:07 -0400 Message-Id: <20200922223525.4085762-9-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The type checker can't constrain the token value to string in this case, because it's only loosely correlated with the return token, which is "stringly typed". Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 78355ca93f..6774b6c736 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -312,6 +312,7 @@ def _get_doc(self, info): cur_doc =3D QAPIDoc(info) self.accept(False) while self.tok =3D=3D '#': + assert isinstance(self.val, str), "Expected str value" if self.val.startswith('##'): # End of doc comment if self.val !=3D '##': --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814625; cv=none; d=zohomail.com; s=zohoarc; b=A0P0KeBJVdMMCeCKzWjR+EmSCkKCFE1l4fmH9uqGq5dZ1F0KChJCS+2mXDHKsEj9eUMU1QuLKTOBBWkelBwVwCHRUbYFfNXgM09LiP7/ViLUxzQz0+b3laIAETKPWMU1XV8ZfprY9oTys3tpiVJLP+xEXtLy7oD2fkIXvPJahtg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814625; 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=ZPjT7h9M9onq+vvAMMLwRyCmMJMrAK5tD5k2QAXXKR0=; b=bymygpLeHeu7ye5pZWNHkoQ/y4bV2AFH4V/iIqkFVqdU1NazVVEnZIuyJufMIlrvR1/FwiVpHHdousPn7RkmA+KZ/eMChfxLyIqEE956ecNIOZfV5TEyR6iPD2pFyxtSuIG84Xlmcfj5E7Fv5n1rJNVlW7sH7s++DqvugHUpgM0= 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 1600814625587667.5104173392585; Tue, 22 Sep 2020 15:43:45 -0700 (PDT) Received: from localhost ([::1]:37956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr0i-0007vx-9V for importer@patchew.org; Tue, 22 Sep 2020 18:43:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqsx-0004Lo-13 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:24129) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqsu-0007dU-TZ for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:42 -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-154-46tfiXMHPva8GzhuiwT6zA-1; Tue, 22 Sep 2020 18:35:38 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 42B28186DD27; Tue, 22 Sep 2020 22:35:37 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4561D60BF4; Tue, 22 Sep 2020 22:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814140; 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=ZPjT7h9M9onq+vvAMMLwRyCmMJMrAK5tD5k2QAXXKR0=; b=VSJ0P5x9aGPHtOSRwSelpnNVPQTQUvtEQVtLz+B2vvnfx3AmdJVPtKtWKw9PKG7GfK2gFV SEQQnjZ9eWumVSnESJTQK1rsA0tPK+XRy2JpQxPz8VA9ZZ5dHw5UGtmsfqVJeJZA/Xaf5F oeqBWo5HkmZagTADgSEBP2hVleAWN5Q= X-MC-Unique: 46tfiXMHPva8GzhuiwT6zA-1 From: John Snow To: Markus Armbruster Subject: [PATCH 09/26] qapi/parser.py: assert get_expr returns object in outer loop Date: Tue, 22 Sep 2020 18:35:08 -0400 Message-Id: <20200922223525.4085762-10-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" get_expr can return many things, depending on where it is used. In the outer parsing loop, we expect and require it to return an object. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 6774b6c736..1bc33e85ea 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -94,6 +94,9 @@ def _parse(self): continue =20 expr =3D self.get_expr(False) + if not isinstance(expr, dict): + raise QAPISemError(info, "Expecting object statement") + if 'include' in expr: self.reject_expr_doc(cur_doc) if len(expr) !=3D 1: --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814792; cv=none; d=zohomail.com; s=zohoarc; b=dILj/NYiKoJbJmREvp/9KR4apv8RD8AY7LRpViNkhJra5L/CCsrzymYsj8vvzg6EH8bJb7rvXt9Vg+/PWGypTFTY7LS0DvuXqjWgnQpTCkLwWLS8tWjtjU7wmsOyJg1PBGqrxTHYXL5wk67qPNajVZVi2yg2FnFX5fwMYawjeYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814792; 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=UK4zDT6zPhLUZkX4SIut7rDgOTI/aCc0iI8mieLBlpQ=; b=MCiEgldm/r9GWUrvcVileVgKu2PdrdL9l1Gymc1GC2GbcmwfuaQ657C7LBh/dOy9MlycTy3C7ldr8OUelstKdizIDkfZCuW+hdtDgrX9yD4814HXz5qJGo8eWrnSAe9UFiugaUg+xfA/Tc5QMLo4jire7nWcpwaQycewcijULLE= 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 16008147925551006.6063591850764; Tue, 22 Sep 2020 15:46:32 -0700 (PDT) Received: from localhost ([::1]:44794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr3O-0002WP-Ug for importer@patchew.org; Tue, 22 Sep 2020 18:46:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqsx-0004OI-VD for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:48743) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqsv-0007df-VT for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:43 -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-190-_GNqg23MPlWhexVnUdrgSQ-1; Tue, 22 Sep 2020 18:35:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BF57801AE8; Tue, 22 Sep 2020 22:35:38 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 708CC60BF4; Tue, 22 Sep 2020 22:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814141; 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=UK4zDT6zPhLUZkX4SIut7rDgOTI/aCc0iI8mieLBlpQ=; b=H4lO1SUilHLnz/p1TtWNNskBEZDynYk9uBGCnfmXBnudSlZI3C5zEfJO5JW8gd7ZDx55Bk SgYNGW5yI8MSGkQwcdkTOAVaUqPX2VMtjSylk+ZWXRC4UhaC6e6+tgqMg5WdrGyX5dhBWY BTIk6HYiMX5w55GG3Qxqd6ltESSDIIw= X-MC-Unique: _GNqg23MPlWhexVnUdrgSQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 10/26] qapi/parser.py: assert object keys are strings Date: Tue, 22 Sep 2020 18:35:09 -0400 Message-Id: <20200922223525.4085762-11-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Since values can also be other data types, add an assertion to ensure we're dealing with strings. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 1bc33e85ea..756c904257 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -256,6 +256,8 @@ def get_members(self): raise self._parse_error("expected string or '}'") while True: key =3D self.val + assert isinstance(key, str), f"expected str, got {type(key)!s}" + self.accept() if self.tok !=3D ':': raise self._parse_error("expected ':'") --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814923; cv=none; d=zohomail.com; s=zohoarc; b=MkuWNR6naciB42yI84t6kT8D3DXxb26ld73LnTi7tARHr6QqxZ9WbWzZK9gXUjEcxpm9XUpOXtxl4l6zqbSu4bUqiZ2yetB2tE1TzuAHKY8aTO1lsPidgMDM7jLaxuXMAz9AZH5Yk7ShJGCamw2POk6rbfgau5+G0nGZGSzn8x4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814923; 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=4HMxZnigJXfXaR7x/BM++m7Lnpe90f238nIkOFQGWJI=; b=exoA5U403QP/LxOr6PWFImkt0EDzJ5xlh4QWpwFPHsfM3KENYmHGJ4xxJPEK0PyIpN07iJCh3+0JyU+SdY+WJCiFlIKvCegBjeGMfbfICSD99eYX159qlDgKAjiQc8hKkDIuFlz5oVqU0pZQeMG/9k7rtDk4P4KNRAucNhMsxdI= 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 1600814923033964.3040657447282; Tue, 22 Sep 2020 15:48:43 -0700 (PDT) Received: from localhost ([::1]:53170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr5V-00061p-N0 for importer@patchew.org; Tue, 22 Sep 2020 18:48:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqt0-0004W3-EN for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:46 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:26498 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqsy-0007e0-HA for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:46 -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-316-0Tf8tEh_M9mWFIl1M4_rGQ-1; Tue, 22 Sep 2020 18:35:40 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6230E186DD27; Tue, 22 Sep 2020 22:35:39 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 888A960CCC; Tue, 22 Sep 2020 22:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814143; 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=4HMxZnigJXfXaR7x/BM++m7Lnpe90f238nIkOFQGWJI=; b=f5Z0/IWv6cfkn79PmpMcEWt9sdL6ULsqqmc/VSoys3EsEds1geiFiVFMXIrER4Hi3XpeuN hl2iLcDHEC8Ke8yrTRn4dSsqWL6Z44IoXmbwgB1SjqVzc7WBUHY70BGMQJkmjWSprm2rRJ cc6/7H6t8AKl+XaFObUO5rDKSUQ7mUc= X-MC-Unique: 0Tf8tEh_M9mWFIl1M4_rGQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 11/26] qapi/parser.py: Convert several methods to @classmethod Date: Tue, 22 Sep 2020 18:35:10 -0400 Message-Id: <20200922223525.4085762-12-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 17:00:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It's usually nicer to keep static methods as class methods -- this allows them to call other class methods, to be subclassed and extended, etc. Meanwhile, any method that doesn't utilize `self` can be a class method. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 756c904257..75a693a9d7 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -139,15 +139,16 @@ def _parse(self): def _parse_error(self, msg: str) -> QAPIParseError: return QAPIParseError.make(self, msg) =20 - @staticmethod - def reject_expr_doc(doc): + @classmethod + def reject_expr_doc(cls, doc): if doc and doc.symbol: raise QAPISemError( doc.info, "documentation for '%s' is not followed by the definition" % doc.symbol) =20 - def _include(self, include, info, incl_fname, previously_included): + @classmethod + def _include(cls, include, info, incl_fname, previously_included): incl_abs_fname =3D os.path.abspath(incl_fname) # catch inclusion cycle inf =3D info @@ -162,7 +163,8 @@ def _include(self, include, info, incl_fname, previousl= y_included): =20 return QAPISchemaParser(incl_fname, previously_included, info) =20 - def _pragma(self, name, value, info): + @classmethod + def _pragma(cls, name, value, info): if name =3D=3D 'doc-required': if not isinstance(value, bool): raise QAPISemError(info, --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814623; cv=none; d=zohomail.com; s=zohoarc; b=fCnwmTUuUEB9OtrhJQcesMIooSwodAbkSDGDpLlbkJlMKqlw8sNDBMZDHZ88aPRPeNJpqwgUZw/ow/clW3UkdNOHlG7fOLyAlGNLyjVSl3ys0mZ9RE3XtlcYUdRZkeZ42ikDD+ESdzE2kuDvfz8nWUcSYxcMN11B2+sOSMtcTGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814623; 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=MRADnjcvuYBbKImJ2ASizBGrKG22BEIAUr5NiDqqnjo=; b=ZgBM/wUILJZS1qaa2kOjESMCgLB3byxu4moCNDbzGjMDIJwNHB4mIrGPBQV6lzCkFgD6Dt2gFmOwl6W9hxGSqlhPtgy4yoGN9k65ulIx9GNvUT91HUsNTbSKGliG7PMHLaip6gdnIaLd9UTFH46GQhRSuQrh6AzElk55zjP0rvA= 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 1600814623437826.3075079352154; Tue, 22 Sep 2020 15:43:43 -0700 (PDT) Received: from localhost ([::1]:37740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr0g-0007qh-7d for importer@patchew.org; Tue, 22 Sep 2020 18:43:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58140) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqt0-0004Un-1U for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:46 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:46918 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqsy-0007e1-9m for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:45 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-339-M6TWuIsJOveOnkxQ2NpgkA-1; Tue, 22 Sep 2020 18:35:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 68AF9801AE8; Tue, 22 Sep 2020 22:35:40 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C83D60BF4; Tue, 22 Sep 2020 22:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814143; 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=MRADnjcvuYBbKImJ2ASizBGrKG22BEIAUr5NiDqqnjo=; b=JNuM219IC43QWEaLLSvDUFrcpqoXZCD8T03vgrtL55/N4gSAUHabyaklkppGHW/cqcMUhR nkTzrqueXAlnHTrVf8PRzu2K14AUikwhDyBSTICBPK6PTaARGw2LaaKytbzcBXVvL5Z6gE TBTSwrwNt1hfC6EXHZouZ7mSVRG6/eo= X-MC-Unique: M6TWuIsJOveOnkxQ2NpgkA-1 From: John Snow To: Markus Armbruster Subject: [PATCH 12/26] qapi/parser.py: add casts to pragma checks Date: Tue, 22 Sep 2020 18:35:11 -0400 Message-Id: <20200922223525.4085762-13-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.81; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 17:01:22 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This kind of type checking at runtime is not something mypy can introspect, so add a do-nothing cast to help mypy out. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 75a693a9d7..9a1007f779 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -17,7 +17,7 @@ import os import re from collections import OrderedDict -from typing import Type, TypeVar +from typing import List, Type, TypeVar, cast =20 from .error import QAPIError, QAPISourceError, QAPISemError from .source import QAPISourceInfo @@ -176,14 +176,14 @@ def _pragma(cls, name, value, info): raise QAPISemError( info, "pragma returns-whitelist must be a list of strings") - info.pragma.returns_whitelist =3D value + info.pragma.returns_whitelist =3D cast(List[str], value) elif name =3D=3D 'name-case-whitelist': if (not isinstance(value, list) or any([not isinstance(elt, str) for elt in value])): raise QAPISemError( info, "pragma name-case-whitelist must be a list of strings") - info.pragma.name_case_whitelist =3D value + info.pragma.name_case_whitelist =3D cast(List[str], value) else: raise QAPISemError(info, "unknown pragma '%s'" % name) =20 --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814583; cv=none; d=zohomail.com; s=zohoarc; b=KMCsyiyxfOg/mhkewS10PgXMOF0p9qPVIHY103RvhaheeF3UTxGOnQCHqdhTFpvPznrqeImf8hGkUs9FClrYal65tpl1V9/faNp7mpiNzDx1xrmC/m9DiDcv2If1PcGW1QOTkvnbc132Q3VOp+mts0AZX8GlspzzqCqhjWG5ZCI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814583; 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=k1e9wsLbffSunTe91GgJ+qycPBufyfpYi6x1TgpznJg=; b=jkFRds3ZB1ZK8wsBetk8GCRsfLttj5dFiIaP7VE2sexeSqlqNVkMLgURXeQRS6Or25/MqtzIETjwPs+9snDXrFpAa2ouD9zBZTV7wRIXX1BDcB6CbkZwa7cdRSebxNBoxB7Ywd9CZ7xnTTcRfrl3Rx0QvCYb/coYv+B6KCshUUo= 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 160081458371033.95660121036542; Tue, 22 Sep 2020 15:43:03 -0700 (PDT) Received: from localhost ([::1]:33556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr02-0006A5-FG for importer@patchew.org; Tue, 22 Sep 2020 18:43:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqt1-0004Xt-5Z for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:35018) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqsy-0007eD-SU for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:46 -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-425-Gbu67MJLOgiG1-ovuTSCOw-1; Tue, 22 Sep 2020 18:35:42 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 609CB1005E64; Tue, 22 Sep 2020 22:35:41 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94B6F60BF4; Tue, 22 Sep 2020 22:35:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814144; 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=k1e9wsLbffSunTe91GgJ+qycPBufyfpYi6x1TgpznJg=; b=HFpqFgk0QHGHLflaxRpIX8h7n2DPIwonsT7PgxuirJ84SN+RfZGSSTLInLL0HvNH+kIGxj g1JJUU4mQeynHfHCXGwWy6RoCBA7m6apZ3LYZ+nrXhmljKmrxc2T7JbN67c35lE1mU6cN5 /CeyCO8p16qy+Qdb1WF1lBmlTEG/c+U= X-MC-Unique: Gbu67MJLOgiG1-ovuTSCOw-1 From: John Snow To: Markus Armbruster Subject: [PATCH 13/26] qapi/parser.py: add type hint annotations Date: Tue, 22 Sep 2020 18:35:12 -0400 Message-Id: <20200922223525.4085762-14-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Annotations for QAPIDoc are in a later commit. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 69 ++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 9a1007f779..d9aae4ddb7 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -14,18 +14,35 @@ # 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 os import re -from collections import OrderedDict -from typing import List, Type, TypeVar, cast +from typing import ( + Any, + Dict, + List, + Optional, + Set, + Type, + TypeVar, + Union, + cast, +) =20 from .error import QAPIError, QAPISourceError, QAPISemError from .source import QAPISourceInfo =20 =20 +Expression =3D Dict[str, Any] +_Value =3D Union[List[object], 'OrderedDict[str, object]', str, bool] +# Necessary imprecision: mypy does not (yet?) support recursive types; +# so we must stub out that recursion with 'object'. +# Note, we do not support numerics or null in this parser. + + class QAPIParseError(QAPISourceError): """Error class for all QAPI schema parsing errors.""" - T =3D TypeVar('T', bound=3D'QAPIParseError') =20 @classmethod @@ -45,22 +62,25 @@ class QAPIDocError(QAPIError): =20 class QAPISchemaParser: =20 - def __init__(self, fname, previously_included=3DNone, incl_info=3DNone= ): + def __init__(self, + fname: str, + previously_included: Optional[Set[str]] =3D None, + incl_info: Optional[QAPISourceInfo] =3D None): self._fname =3D fname self._included =3D previously_included or set() self._included.add(os.path.abspath(self._fname)) =20 # Lexer state (see `accept` for details): - self.tok =3D None + self.tok: Optional[str] =3D None self.pos =3D 0 self.cursor =3D 0 - self.val =3D None + self.val: Optional[Union[bool, str]] =3D None self.info =3D QAPISourceInfo(self._fname, parent=3Dincl_info) self.line_pos =3D 0 =20 # Parser output: - self.exprs =3D [] - self.docs =3D [] + self.exprs: List[Expression] =3D [] + self.docs: List[QAPIDoc] =3D [] =20 # Showtime! try: @@ -76,7 +96,7 @@ def __init__(self, fname, previously_included=3DNone, inc= l_info=3DNone): raise QAPIParseError(context, msg) from e self._parse() =20 - def _parse(self): + def _parse(self) -> None: cur_doc =3D None =20 # Prime the lexer: @@ -140,7 +160,7 @@ def _parse_error(self, msg: str) -> QAPIParseError: return QAPIParseError.make(self, msg) =20 @classmethod - def reject_expr_doc(cls, doc): + def reject_expr_doc(cls, doc: Optional['QAPIDoc']) -> None: if doc and doc.symbol: raise QAPISemError( doc.info, @@ -148,7 +168,12 @@ def reject_expr_doc(cls, doc): % doc.symbol) =20 @classmethod - def _include(cls, include, info, incl_fname, previously_included): + def _include(cls, + include: str, + info: QAPISourceInfo, + incl_fname: str, + previously_included: Set[str] + ) -> Optional['QAPISchemaParser']: incl_abs_fname =3D os.path.abspath(incl_fname) # catch inclusion cycle inf =3D info @@ -164,7 +189,10 @@ def _include(cls, include, info, incl_fname, previousl= y_included): return QAPISchemaParser(incl_fname, previously_included, info) =20 @classmethod - def _pragma(cls, name, value, info): + def _pragma(cls, + name: str, + value: object, + info: QAPISourceInfo) -> None: if name =3D=3D 'doc-required': if not isinstance(value, bool): raise QAPISemError(info, @@ -187,7 +215,7 @@ def _pragma(cls, name, value, info): else: raise QAPISemError(info, "unknown pragma '%s'" % name) =20 - def accept(self, skip_comment=3DTrue): + def accept(self, skip_comment: bool =3D True) -> None: while True: self.tok =3D self.src[self.cursor] self.pos =3D self.cursor @@ -249,8 +277,8 @@ def accept(self, skip_comment=3DTrue): self.src[self.cursor-1:]) raise self._parse_error("stray '%s'" % match.group(0)) =20 - def get_members(self): - expr =3D OrderedDict() + def get_members(self) -> 'OrderedDict[str, object]': + expr: 'OrderedDict[str, object]' =3D OrderedDict() if self.tok =3D=3D '}': self.accept() return expr @@ -276,8 +304,8 @@ def get_members(self): if self.tok !=3D "'": raise self._parse_error("expected string") =20 - def get_values(self): - expr =3D [] + def get_values(self) -> List[object]: + expr: List[object] =3D [] if self.tok =3D=3D ']': self.accept() return expr @@ -293,7 +321,8 @@ def get_values(self): raise self._parse_error("expected ',' or ']'") self.accept() =20 - def get_expr(self, nested): + def get_expr(self, nested: bool =3D False) -> _Value: + expr: _Value if self.tok !=3D '{' and not nested: raise self._parse_error("expected '{'") if self.tok =3D=3D '{': @@ -310,7 +339,7 @@ def get_expr(self, nested): "expected '{', '[', string, or boolean") return expr =20 - def _get_doc(self, info): + def _get_doc(self, info: QAPISourceInfo) -> List['QAPIDoc']: if self.val !=3D '##': raise self._parse_error( "junk after '##' at start of documentation comment") @@ -342,7 +371,7 @@ def _get_doc(self, info): =20 raise self._parse_error("documentation comment must end with '##'") =20 - def get_doc(self, info): + def get_doc(self, info: QAPISourceInfo) -> List['QAPIDoc']: try: return self._get_doc(info) except QAPIDocError as err: --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600815069; cv=none; d=zohomail.com; s=zohoarc; b=fEzKymuV7N08IQmS0JMZBZYrmlfW1cJUU67Bp3AmwjjK8v01BvXvr36Gy6BB0QrxOnO53SiE8P2h86x7rlOz/3eViPelL83+tEBwwekek/l/tKfjzXCUi4FDV5qgoRQDc4Z+Y2KXFSfzaR9XLKQWKHw0vWDWHY6Fad2j6bhfw9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600815069; 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=ZaO4qj/yTu41gKQZ04f3gMKYh6PkBbR6GMOvXDRhB7k=; b=nV/4TbMfYAc+ivwMI3xP8FIpDyfW2aSf48ijI/bZotm0X/sDM//KKHjpdH9jR1R4U1nIJ9phiknoRuAnnt+cp8ATEeig4wWP/gsNBXDksJwd7NLFA82To9AuMDAVEFgGsYLAXqfAnbzwN2hs1GvKNoxgVHxX3MYK4fzktByTqGg= 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 1600815069250208.9479194065358; Tue, 22 Sep 2020 15:51:09 -0700 (PDT) Received: from localhost ([::1]:33406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr7r-00017a-UV for importer@patchew.org; Tue, 22 Sep 2020 18:51:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqt1-0004Zo-T0 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:22280) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqt0-0007fS-0L for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35: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-406-WSV9awEwPGCz8mjvddRMmQ-1; Tue, 22 Sep 2020 18:35:43 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70D92107465D; Tue, 22 Sep 2020 22:35:42 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CC2860CCC; Tue, 22 Sep 2020 22:35:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814145; 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=ZaO4qj/yTu41gKQZ04f3gMKYh6PkBbR6GMOvXDRhB7k=; b=FhstZodiiuaxDmIX2N/N10ITdhj5f3QUa0yBS14GeH5uZbLcE3a/vKFxwM4L81rUa+M7L7 QqUBJyEF7YsHXohcIfo2n84toRRCAG5MUFqrCRCE9mZgWipr+Yl5840uCoX03rPoCndR+7 BfAXNTZIQ469gqAO/3dh427ZjJw3vq8= X-MC-Unique: WSV9awEwPGCz8mjvddRMmQ-1 From: John Snow To: Markus Armbruster Subject: [PATCH 14/26] qapi/parser.py: add docstrings Date: Tue, 22 Sep 2020 18:35:13 -0400 Message-Id: <20200922223525.4085762-15-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index d9aae4ddb7..490436b48a 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -61,7 +61,15 @@ class QAPIDocError(QAPIError): =20 =20 class QAPISchemaParser: + """ + Performs parsing of a QAPI schema source file. =20 + :param fname: Path to the source file + :param previously_included: Set of absolute paths of previously includ= ed + source files; these will not be parsed aga= in. + :param incl_info: QAPISourceInfo for the parent document; + Can be None for the parent document. + """ def __init__(self, fname: str, previously_included: Optional[Set[str]] =3D None, @@ -97,6 +105,10 @@ def __init__(self, self._parse() =20 def _parse(self) -> None: + """ + Parse the QAPI Schema Document. + Build self.exprs, self.docs + """ cur_doc =3D None =20 # Prime the lexer: @@ -216,6 +228,32 @@ def _pragma(cls, raise QAPISemError(info, "unknown pragma '%s'" % name) =20 def accept(self, skip_comment: bool =3D True) -> None: + """ + Read the next lexeme. + + - `tok` is the current lexeme/token type. + It will always be a single char in `"[]{},:'tf#"`. + - `pos` is the position of the first character in the lexeme. + - `cursor` is the position of the next character. + - `val` is the value of the lexeme. + + Single-char lexemes: + LBRACE, RBRACE, COLON, COMMA, LSQB, RSQB: + `tok` holds the single-char value of the lexeme. + + Multi-char lexemes: + COMMENT - `tok` is `'#'`. + `val` is a string including all chars until end-of-lin= e. + (The '#' is excluded.) + STRING - `tok` is `"'"`. + `val` is the string, excluding the quotes. + TRUE - `tok` is `"t"`. `val` is `True`. + FALSE - `tok` is `"f"`. `val` is `False`. + + NEWLINE and SPACE lexemes are consumed by the lexer directly. + `line_pos` and `info` are advanced when NEWLINE is encountered. + `tok` is set to `None` upon reaching EOF. + """ while True: self.tok =3D self.src[self.cursor] self.pos =3D self.cursor --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814919; cv=none; d=zohomail.com; s=zohoarc; b=IXOaVVTBNzlwpnbKIwGN8DEADuqRCHe4WXjIt6nGg5eksvn7Mqu8MH+3baSRvpjIA05+30DtP4yWX6vqFqFSf36DLqD1cX3BEmf3LxwawbRNoevgDcwl4K1LAM2OGGZb67vTvqEvyLX855wd8y+cd8wlqYSaPJ5v4MtKRSYE7nw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814919; 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=UtEbxEEmIN+hGEWS4thp55WZFeorkKDSjE+eFLo91xc=; b=lYjBia7xfipltj2f/fH5D4oZRsJgblGxC/rZXgXr6eERzpyfx3BFPb4w4K33O9miQX+iKnDHhVIkSOa2AIdo17EPl5F1/Yh5sHs+6wN4tM7l2KBAxL+W26jg8R0q53xMBWlnPHOktZ1kzbaN92YGQTS2Bjh2l6bEGM1dqeNVlBM= 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 160081491968565.86113136279607; Tue, 22 Sep 2020 15:48:39 -0700 (PDT) Received: from localhost ([::1]:52834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr5S-0005tC-7R for importer@patchew.org; Tue, 22 Sep 2020 18:48:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58212) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqt5-0004jN-Im for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:43630) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqt2-0007fs-St for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:51 -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-292-ZwgtsrW-PTKl5bdz19JcUA-1; Tue, 22 Sep 2020 18:35:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7EB491005E64; Tue, 22 Sep 2020 22:35:43 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E6DD60BF4; Tue, 22 Sep 2020 22:35:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814148; 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=UtEbxEEmIN+hGEWS4thp55WZFeorkKDSjE+eFLo91xc=; b=hZfqKNqN+JhmF0+y3y+RqdoO3LW+9aHIoOE5HBBwqOtd/KPww/rHZ/3aWj9Ihlojazug1w Inf0R2JqExPPqA+HtY5M2SjEt+0z50/CQVA3C6mppnh65/U79g9a9MRXsL+R5z6hUiCowH 63qDMq7AwD7bPVwdN2r/Q7VKnsAuy7Q= X-MC-Unique: ZwgtsrW-PTKl5bdz19JcUA-1 From: John Snow To: Markus Armbruster Subject: [PATCH 15/26] qapi/parser.py: add ParsedExpression type Date: Tue, 22 Sep 2020 18:35:14 -0400 Message-Id: <20200922223525.4085762-16-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This is an immutable, named, typed tuple; it's nicer than arbitrary dicts for passing data around when using strict typing. Turn parser.exprs into a list of ParsedExpressions instead, and adjust expr.py to match. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/expr.py | 56 +++++++++++++++--------------------------- scripts/qapi/parser.py | 32 +++++++++++++----------- scripts/qapi/schema.py | 6 ++--- 3 files changed, 41 insertions(+), 53 deletions(-) diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py index cfd342aa04..f2059c505c 100644 --- a/scripts/qapi/expr.py +++ b/scripts/qapi/expr.py @@ -46,7 +46,7 @@ =20 from .common import c_name from .error import QAPISemError -from .parser import QAPIDoc +from .parser import ParsedExpression from .source import QAPISourceInfo =20 =20 @@ -517,7 +517,7 @@ class ExpressionType(str, Enum): } =20 =20 -def check_exprs(exprs: List[_JSObject]) -> List[_JSObject]: +def check_exprs(exprs: List[ParsedExpression]) -> List[ParsedExpression]: """ Validate and normalize a list of parsed QAPI schema expressions. [RW] =20 @@ -526,49 +526,33 @@ def check_exprs(exprs: List[_JSObject]) -> List[_JSOb= ject]: =20 :param exprs: The list of expressions to normalize/validate. """ - for expr_elem in exprs: - # 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 - + for expr in exprs: for kind in ExpressionType: - if kind in expr: + if kind in expr.expr: meta =3D kind break else: - raise QAPISemError(info, "expression is missing metatype") + raise QAPISemError(expr.info, "expression is missing metatype") =20 if meta =3D=3D ExpressionType.INCLUDE: continue =20 - name =3D cast(str, expr[meta]) # asserted right below: - check_name_is_str(name, info, "'%s'" % meta.value) - info.set_defn(meta.value, name) - check_defn_name_str(name, info, meta.value) + name =3D cast(str, expr.expr[meta]) # asserted right below: + check_name_is_str(name, expr.info, "'%s'" % meta.value) + expr.info.set_defn(meta.value, name) + check_defn_name_str(name, expr.info, meta.value) =20 - if doc: - if doc.symbol !=3D name: - raise QAPISemError( - info, "documentation comment is for '%s'" % doc.symbol) - doc.check_expr(expr) - elif info.pragma.doc_required: - raise QAPISemError(info, - "documentation comment required") + if expr.doc: + if expr.doc.symbol !=3D name: + msg =3D f"documentation comment is for '{expr.doc.symbol}'" + raise QAPISemError(expr.info, msg) + expr.doc.check_expr(expr.expr) + elif expr.info.pragma.doc_required: + raise QAPISemError(expr.info, "documentation comment required") =20 - _CHECK_FN[meta](expr, info) - check_if(expr, info, meta.value) - check_features(expr.get('features'), info) - check_flags(expr, info) + _CHECK_FN[meta](expr.expr, expr.info) + check_if(expr.expr, expr.info, meta.value) + check_features(expr.expr.get('features'), expr.info) + check_flags(expr.expr, expr.info) =20 return exprs diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 490436b48a..f65afa4eb2 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -19,9 +19,8 @@ import os import re from typing import ( - Any, - Dict, List, + NamedTuple, Optional, Set, Type, @@ -34,13 +33,18 @@ from .source import QAPISourceInfo =20 =20 -Expression =3D Dict[str, Any] _Value =3D Union[List[object], 'OrderedDict[str, object]', str, bool] # Necessary imprecision: mypy does not (yet?) support recursive types; # so we must stub out that recursion with 'object'. # Note, we do not support numerics or null in this parser. =20 =20 +class ParsedExpression(NamedTuple): + expr: 'OrderedDict[str, object]' + info: QAPISourceInfo + doc: Optional['QAPIDoc'] + + class QAPIParseError(QAPISourceError): """Error class for all QAPI schema parsing errors.""" T =3D TypeVar('T', bound=3D'QAPIParseError') @@ -87,7 +91,7 @@ def __init__(self, self.line_pos =3D 0 =20 # Parser output: - self.exprs: List[Expression] =3D [] + self.exprs: List[ParsedExpression] =3D [] self.docs: List[QAPIDoc] =3D [] =20 # Showtime! @@ -139,8 +143,7 @@ def _parse(self) -> None: "value of 'include' must be a strin= g") incl_fname =3D os.path.join(os.path.dirname(self._fname), include) - self.exprs.append({'expr': {'include': incl_fname}, - 'info': info}) + self._add_expr(OrderedDict({'include': incl_fname}), info) exprs_include =3D self._include(include, info, incl_fname, self._included) if exprs_include: @@ -157,20 +160,21 @@ def _parse(self) -> None: for name, value in pragma.items(): self._pragma(name, value, info) else: - expr_elem =3D {'expr': expr, - 'info': info} - if cur_doc: - if not cur_doc.symbol: - raise QAPISemError( - cur_doc.info, "definition documentation requir= ed") - expr_elem['doc'] =3D cur_doc - self.exprs.append(expr_elem) + if cur_doc and not cur_doc.symbol: + raise QAPISemError( + cur_doc.info, "definition documentation required") + self._add_expr(expr, info, cur_doc) cur_doc =3D None self.reject_expr_doc(cur_doc) =20 def _parse_error(self, msg: str) -> QAPIParseError: return QAPIParseError.make(self, msg) =20 + def _add_expr(self, expr: 'OrderedDict[str, object]', + info: QAPISourceInfo, + doc: Optional['QAPIDoc'] =3D None) -> None: + self.exprs.append(ParsedExpression(expr, info, doc)) + @classmethod def reject_expr_doc(cls, doc: Optional['QAPIDoc']) -> None: if doc and doc.symbol: diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 121d8488d2..51af0449f5 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -1106,9 +1106,9 @@ def _def_event(self, expr, info, doc): =20 def _def_exprs(self, exprs): for expr_elem in exprs: - expr =3D expr_elem['expr'] - info =3D expr_elem['info'] - doc =3D expr_elem.get('doc') + expr =3D expr_elem.expr + info =3D expr_elem.info + doc =3D expr_elem.doc if 'enum' in expr: self._def_enum_type(expr, info, doc) elif 'struct' in expr: --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814788; cv=none; d=zohomail.com; s=zohoarc; b=RRJCiqa574tDY1Ia228NCDadNtsXyrHPCrxwtjZ8JshOnwX4eNCl8OK/N2PgtxJdL/z5Ahny1sleXquC2xt2INi/E4wc8kMo//r8RKSq2IUir/CtYqac+z8kB+2Xe4IM08n9i6kRU3P0CA+DXc4UhlhGjk13E/CvhZD4Ewwm4Jo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814788; 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=zf3U7GT859YgMsfNxOYBu76mnA//cyA3+FAGAPVPv3I=; b=jca0gwWLo5cRCJZNUBo4PO5bhWsdDnczfqFygonox7Vy6DMoOlOBJFD0pWL1Yjlq/MRdLb4fqUY1cFTPeXu7FN4b754/Fb5m9fBDy5uKnyNIIBv0z1gckxvRuOsR19JCvOC9pnnY2Jk6+HvWhVWox7y457Wfmoe6Jimhi1IklqE= 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 1600814788883994.6934197410869; Tue, 22 Sep 2020 15:46:28 -0700 (PDT) Received: from localhost ([::1]:44476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr3L-0002NF-3H for importer@patchew.org; Tue, 22 Sep 2020 18:46:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58186) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqt3-0004eP-Ld for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20171) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqt1-0007fj-Rk for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35: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-193-qoncvMnvPzWAb5OZd-7p_A-1; Tue, 22 Sep 2020 18:35:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 80CD41074641; Tue, 22 Sep 2020 22:35:44 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABAA560BF4; Tue, 22 Sep 2020 22:35:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814147; 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=zf3U7GT859YgMsfNxOYBu76mnA//cyA3+FAGAPVPv3I=; b=AjQjGqgHcHXGl29WH8uf58vIRECV74wxpzaF327im3SrJQ6ClHcdEQml7WIP+mhMl0HMxw /49zxgelDhhoDwSw3Wda4PPLB9CCDRJyYG0wSqlz8spTWQ9Xwm3WA+xS/8hNbRF+fgrzYR fk03afFzSoQYzy3JssVT/oM2QR7gC00= X-MC-Unique: qoncvMnvPzWAb5OZd-7p_A-1 From: John Snow To: Markus Armbruster Subject: [PATCH 16/26] qapi/pragma.py: Move QAPISchemaPragma into its own module Date: Tue, 22 Sep 2020 18:35:15 -0400 Message-Id: <20200922223525.4085762-17-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/pragma.py | 25 +++++++++++++++++++++++++ scripts/qapi/source.py | 15 ++------------- 2 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 scripts/qapi/pragma.py diff --git a/scripts/qapi/pragma.py b/scripts/qapi/pragma.py new file mode 100644 index 0000000000..7f3db9ab87 --- /dev/null +++ b/scripts/qapi/pragma.py @@ -0,0 +1,25 @@ +# +# QAPI pragma information +# +# Copyright (c) 2020 John Snow, for Red Hat Inc. +# +# Authors: +# John Snow +# +# This work is licensed under the terms of the GNU GPL, version 2. +# See the COPYING file in the top-level directory. + +from typing import List + + +class QAPISchemaPragma: + # Replace with @dataclass in Python 3.7+ + # pylint: disable=3Dtoo-few-public-methods + + def __init__(self) -> None: + # Are documentation comments required? + self.doc_required =3D False + # Whitelist of commands allowed to return a non-dictionary + self.returns_whitelist: List[str] =3D [] + # Whitelist of entities allowed to violate case conventions + self.name_case_whitelist: List[str] =3D [] diff --git a/scripts/qapi/source.py b/scripts/qapi/source.py index d1de9e36b1..fe1424be03 100644 --- a/scripts/qapi/source.py +++ b/scripts/qapi/source.py @@ -11,20 +11,9 @@ =20 import copy import sys -from typing import List, Optional, TypeVar +from typing import Optional, TypeVar =20 - -class QAPISchemaPragma: - # Replace with @dataclass in Python 3.7+ - # pylint: disable=3Dtoo-few-public-methods - - def __init__(self) -> None: - # Are documentation comments required? - self.doc_required =3D False - # Whitelist of commands allowed to return a non-dictionary - self.returns_whitelist: List[str] =3D [] - # Whitelist of entities allowed to violate case conventions - self.name_case_whitelist: List[str] =3D [] +from .pragma import QAPISchemaPragma =20 =20 class QAPISourceInfo: --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814514; cv=none; d=zohomail.com; s=zohoarc; b=Hn6xK7VUP5DFeDYaQm2YmHHyR5AT0n2tkKojEVau45vANSYnHIjttmXopIBN27p14MID69bxuzheZTc50C/8N51ass9TC1xXGMNYvZHvO6eGf7meq3Mo6GL+j/uwceq8s131WQSSXQAqxIEFz2q3twigExVuxNw+IY4nYKQQIsA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814514; 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=A3czMzA7jYvQ1EYINs1q1A8p7rMTBFDZJx5iX7pQP+o=; b=EX1JjVLHbHrSekG7Ev5lEVmu3G8T1k9pMG1EQZowyFnTa8GuIBRHvwQgqWx1Jjo/zBHZuvZ6tA9OX1YAbo3OkLmo0CSgp+CPO8Ql7gNP3PoW2eMN7aVYa6W0Gj6gsvDLjOLLcqbFESDDKlJFEnada0PKu7gL0N6q1+dg6Deu5lM= 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 1600814514366524.6167912964976; Tue, 22 Sep 2020 15:41:54 -0700 (PDT) Received: from localhost ([::1]:58060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqyt-0004aw-Dv for importer@patchew.org; Tue, 22 Sep 2020 18:41:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqt8-0004qA-4L for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:54 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:29265) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqt4-0007g6-E8 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:53 -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-472-Fnyoah9MMr6hkkOa34iVPg-1; Tue, 22 Sep 2020 18:35:46 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8733A1074669; Tue, 22 Sep 2020 22:35:45 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABFA560BF4; Tue, 22 Sep 2020 22:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814149; 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=A3czMzA7jYvQ1EYINs1q1A8p7rMTBFDZJx5iX7pQP+o=; b=daCcEvv4ULad8fw2bwUkM84QQ9eR6PkIYwbmgwPz1rA8FnHe6b4WsH1No/dakontKIgoer X0cLoafGH262iJ93hMdDKuEr5arRFAy6LmeXBKouYw/rzBXv1L/1ZvbNSKwBat0uFhoDne oqTxQe1twDOt3tntxSLYlmcn2WWS+xs= X-MC-Unique: Fnyoah9MMr6hkkOa34iVPg-1 From: John Snow To: Markus Armbruster Subject: [PATCH 17/26] qapi/pragma.py: Move pragma parsing out of parser.py Date: Tue, 22 Sep 2020 18:35:16 -0400 Message-Id: <20200922223525.4085762-18-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" parser.py is a JSON parser at heart and shouldn't necessarily understand what it is parsing on a semantic level. Move pragma parsing to pragma.py, and leave the parser a little more happily ignorant. Note: the type annotation in error.py now creates a cyclic import, because error -> source -> pragma -> error. Use the magical mypy constant TYPE_CHEC= KING to avoid this cycle at runtime. pylint dislikes this cycle still, but it can be safely ignored. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/error.py | 8 +++--- scripts/qapi/parser.py | 41 ++++--------------------------- scripts/qapi/pragma.py | 55 +++++++++++++++++++++++++++++++++++++----- 3 files changed, 59 insertions(+), 45 deletions(-) diff --git a/scripts/qapi/error.py b/scripts/qapi/error.py index ab6a0f6271..be5fd24218 100644 --- a/scripts/qapi/error.py +++ b/scripts/qapi/error.py @@ -11,9 +11,11 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 -from typing import Optional +from typing import Optional, TYPE_CHECKING =20 -from .source import QAPISourceInfo +if TYPE_CHECKING: + # pylint: disable=3Dcyclic-import + from .source import QAPISourceInfo =20 =20 class QAPIError(Exception): @@ -23,7 +25,7 @@ class QAPIError(Exception): class QAPISourceError(QAPIError): """Error class for all exceptions identifying a source location.""" def __init__(self, - info: QAPISourceInfo, + info: 'QAPISourceInfo', msg: str, col: Optional[int] =3D None): super().__init__() diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index f65afa4eb2..5b3a9b5da8 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -26,10 +26,10 @@ Type, TypeVar, Union, - cast, ) =20 from .error import QAPIError, QAPISourceError, QAPISemError +from .pragma import PragmaError from .source import QAPISourceInfo =20 =20 @@ -151,14 +151,10 @@ def _parse(self) -> None: self.docs.extend(exprs_include.docs) elif "pragma" in expr: self.reject_expr_doc(cur_doc) - if len(expr) !=3D 1: - raise QAPISemError(info, "invalid 'pragma' directive") - pragma =3D expr['pragma'] - if not isinstance(pragma, dict): - raise QAPISemError( - info, "value of 'pragma' must be an object") - for name, value in pragma.items(): - self._pragma(name, value, info) + try: + info.pragma.parse(expr) + except PragmaError as err: + raise QAPISemError(info, str(err)) from err else: if cur_doc and not cur_doc.symbol: raise QAPISemError( @@ -204,33 +200,6 @@ def _include(cls, =20 return QAPISchemaParser(incl_fname, previously_included, info) =20 - @classmethod - def _pragma(cls, - name: str, - value: object, - info: QAPISourceInfo) -> None: - if name =3D=3D 'doc-required': - if not isinstance(value, bool): - raise QAPISemError(info, - "pragma 'doc-required' must be boolean") - info.pragma.doc_required =3D value - elif name =3D=3D 'returns-whitelist': - if (not isinstance(value, list) - or any([not isinstance(elt, str) for elt in value])): - raise QAPISemError( - info, - "pragma returns-whitelist must be a list of strings") - info.pragma.returns_whitelist =3D cast(List[str], value) - elif name =3D=3D 'name-case-whitelist': - if (not isinstance(value, list) - or any([not isinstance(elt, str) for elt in value])): - raise QAPISemError( - info, - "pragma name-case-whitelist must be a list of strings") - info.pragma.name_case_whitelist =3D cast(List[str], value) - else: - raise QAPISemError(info, "unknown pragma '%s'" % name) - def accept(self, skip_comment: bool =3D True) -> None: """ Read the next lexeme. diff --git a/scripts/qapi/pragma.py b/scripts/qapi/pragma.py index 7f3db9ab87..03ba3cac90 100644 --- a/scripts/qapi/pragma.py +++ b/scripts/qapi/pragma.py @@ -9,17 +9,60 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. =20 -from typing import List +from typing import Mapping, Sequence + +from .error import QAPIError + + +class PragmaError(QAPIError): + """For errors relating to Pragma validation.""" =20 =20 class QAPISchemaPragma: - # Replace with @dataclass in Python 3.7+ - # pylint: disable=3Dtoo-few-public-methods - def __init__(self) -> None: # Are documentation comments required? self.doc_required =3D False # Whitelist of commands allowed to return a non-dictionary - self.returns_whitelist: List[str] =3D [] + self.returns_whitelist: Sequence[str] =3D tuple() # Whitelist of entities allowed to violate case conventions - self.name_case_whitelist: List[str] =3D [] + self.name_case_whitelist: Sequence[str] =3D tuple() + + def _add_doc_required(self, value: object) -> None: + if not isinstance(value, bool): + raise PragmaError("pragma 'doc-required' must be boolean") + self.doc_required =3D value + + def _add_returns_whitelist(self, value: object) -> None: + if (not isinstance(value, list) + or any([not isinstance(elt, str) for elt in value])): + raise PragmaError( + "pragma returns-whitelist must be a list of strings") + self.returns_whitelist =3D tuple(value) + + def _add_name_case_whitelist(self, value: object) -> None: + if (not isinstance(value, list) + or any([not isinstance(elt, str) for elt in value])): + raise PragmaError( + "pragma name-case-whitelist must be a list of strings") + self.name_case_whitelist =3D tuple(value) + + def add(self, name: str, value: object) -> None: + if name =3D=3D 'doc-required': + self._add_doc_required(value) + elif name =3D=3D 'returns-whitelist': + self._add_returns_whitelist(value) + elif name =3D=3D 'name-case-whitelist': + self._add_name_case_whitelist(value) + else: + raise PragmaError(f"unknown pragma '{name}'") + + def parse(self, expression: Mapping[str, object]) -> None: + if expression.keys() !=3D {'pragma'}: + raise PragmaError("invalid 'pragma' directive") + + body =3D expression['pragma'] + if not isinstance(body, dict): + raise PragmaError("value of 'pragma' must be an object") + + for name, value in body.items(): + self.add(name, value) --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814357; cv=none; d=zohomail.com; s=zohoarc; b=HYBUin6ahQMLulJkUNq3ZTgLRbRqtvsYFKlUFdiaXAIINEAnhyBfMRUpAhp9xfHDdHM9qXoz/4YafBV5oNgMGIlRr2exCkgfFVOy5Y36j0j0yg9PL1BXe0vj6XtKWbggcsc+e+dklV+rL3hATUeoB5A0JoteFosGPOfPbfC4PMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814357; 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=Jx/RLJEheVGU74xhwDSBCExsWp4oxNEyMTUGMehjDwU=; b=dO+WFh5OtxqJ26l6ty4+CYKR9TNXR6qlPFe9jUDV8TyX8vMoxVp/VFeVKJmfox5wh4bRnrZ+LPsvOuQooWOGn3p6G8vo69qYwMHS3nIdnXZtxwdpeXSVdtqMRJEsUsQdXrSlAkFNykgf3J8Sq66F9arllfYkfZjAtw3Abat3nTo= 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 1600814357411540.7195310905944; Tue, 22 Sep 2020 15:39:17 -0700 (PDT) Received: from localhost ([::1]:49616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqwO-00017x-4K for importer@patchew.org; Tue, 22 Sep 2020 18:39:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58222) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqt6-0004lu-HJ for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:52 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:57951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqt4-0007g9-HX for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:52 -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-241-tVCcdv-ONGuryEcPGvS1Bg-1; Tue, 22 Sep 2020 18:35:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A785681CBE9; Tue, 22 Sep 2020 22:35:46 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2E9860BF4; Tue, 22 Sep 2020 22:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814149; 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=Jx/RLJEheVGU74xhwDSBCExsWp4oxNEyMTUGMehjDwU=; b=DvQo5PIVqriNoVVXHBImWXeB3CkEPFiAP0E24JGjCDONhAYgtMFZk89KbOWMcfPBfLFhMo JM08d2jkGiOOmXy1gYKHlF1DfsRHpO59lv581um1kULcPfTmolZhxAQzx9xc3V/fA+dLLB NWWK1ss7nGYA1Yalk1H7EqcCDRqn0+Y= X-MC-Unique: tVCcdv-ONGuryEcPGvS1Bg-1 From: John Snow To: Markus Armbruster Subject: [PATCH 18/26] qapi/parser.py: Modify _include() to use parser state Date: Tue, 22 Sep 2020 18:35:17 -0400 Message-Id: <20200922223525.4085762-19-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" It doesn't need to take quite so many arguments. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 5b3a9b5da8..77067b2f5d 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -144,8 +144,7 @@ def _parse(self) -> None: incl_fname =3D os.path.join(os.path.dirname(self._fname), include) self._add_expr(OrderedDict({'include': incl_fname}), info) - exprs_include =3D self._include(include, info, incl_fname, - self._included) + exprs_include =3D self._include(include, incl_fname) if exprs_include: self.exprs.extend(exprs_include.exprs) self.docs.extend(exprs_include.docs) @@ -179,26 +178,22 @@ def reject_expr_doc(cls, doc: Optional['QAPIDoc']) ->= None: "documentation for '%s' is not followed by the definition" % doc.symbol) =20 - @classmethod - def _include(cls, - include: str, - info: QAPISourceInfo, - incl_fname: str, - previously_included: Set[str] - ) -> Optional['QAPISchemaParser']: + def _include(self, include: str, + incl_fname: str) -> Optional['QAPISchemaParser']: incl_abs_fname =3D os.path.abspath(incl_fname) + # catch inclusion cycle - inf =3D info + inf =3D self.info while inf: if incl_abs_fname =3D=3D os.path.abspath(inf.fname): - raise QAPISemError(info, "inclusion loop for %s" % include) + raise QAPISemError(self.info, f"inclusion loop for {includ= e}") inf =3D inf.parent =20 # skip multiple include of the same file - if incl_abs_fname in previously_included: + if incl_abs_fname in self._included: return None =20 - return QAPISchemaParser(incl_fname, previously_included, info) + return QAPISchemaParser(incl_fname, self._included, self.info) =20 def accept(self, skip_comment: bool =3D True) -> None: """ --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814628; cv=none; d=zohomail.com; s=zohoarc; b=XIUxX0N/eLg92ydPajPzjDa8AcYlnLZ7YkLUHKHys4CBV+o48amHlzzBX5t4ujEFEhf8SSVvaGvsmCtFN/JvSBvHvBusKRfB88Yuf9pKlyyotiUCHjMEllMI82X/x1EzYurHHBW332gDJuiKodbLZVcMNettELSnX7TCRQYw4uY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814628; 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=4dgNQxVwXkzMulCoNr1J2aB5uELtE4y8VKAcE/Muug4=; b=DmBIQMlu2f5wue2hRQaIAAitsVPA2FwTHiv2BjbfhD+Dv+vZMQkJhbozxFfJ2VGC+E2E3Ud0jboEmI52+JZWCMQhzDXKyAnAIeHdJZdQ5Mx2OKKNKRGR+x+TbV7K/Dd2wf5xTAK79V5Z2WBOGsTxmbG818MsnNItl5hOfkhc+2A= 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 1600814628253312.0383908667361; Tue, 22 Sep 2020 15:43:48 -0700 (PDT) Received: from localhost ([::1]:38224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr0k-00082Z-V3 for importer@patchew.org; Tue, 22 Sep 2020 18:43:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqtA-0004wt-U9 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:56 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:58850 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqt8-0007iN-1M for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35: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-212-bE5mKJEqNAyELENuwlOvsw-1; Tue, 22 Sep 2020 18:35:49 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 248D41005E64; Tue, 22 Sep 2020 22:35:48 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9DF960BF4; Tue, 22 Sep 2020 22:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814153; 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=4dgNQxVwXkzMulCoNr1J2aB5uELtE4y8VKAcE/Muug4=; b=JiVOknDnvaRDeFpfKdC3MUOaPp8reIIzuGhraqe3KCPll1TCP6YYAmHaGHtwnA+qpS5MTk 6NDX2zvVTDqdapYmcmW6oGT2CZFnzTRFBiaQJoStcz7QBLW6DWrzjDA24QiDHlTsJXC7Sk xmKSKDknD/WtitUHQtjk+deEQIWtjY0= X-MC-Unique: bE5mKJEqNAyELENuwlOvsw-1 From: John Snow To: Markus Armbruster Subject: [PATCH 19/26] qapi/parser.py: add parent argument Date: Tue, 22 Sep 2020 18:35:18 -0400 Message-Id: <20200922223525.4085762-20-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 17:00:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Instead of passing previously_included and info separately, we can pass the parent parser itself. This cuts down on the number of parameters to pass when creating a parser; and makes it easier to add new shared data members between parent and child. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 77067b2f5d..fa0ddad922 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -68,26 +68,23 @@ class QAPISchemaParser: """ Performs parsing of a QAPI schema source file. =20 - :param fname: Path to the source file - :param previously_included: Set of absolute paths of previously includ= ed - source files; these will not be parsed aga= in. - :param incl_info: QAPISourceInfo for the parent document; - Can be None for the parent document. + :param fname: Path to the source file + :param parent: Parent parser, if this is an included file. """ - def __init__(self, - fname: str, - previously_included: Optional[Set[str]] =3D None, - incl_info: Optional[QAPISourceInfo] =3D None): + def __init__(self, fname: str, + parent: Optional['QAPISchemaParser'] =3D None): self._fname =3D fname - self._included =3D previously_included or set() + self._included: Set[str] =3D parent._included if parent else set() self._included.add(os.path.abspath(self._fname)) + parent_info =3D parent.info if parent else None =20 # Lexer state (see `accept` for details): self.tok: Optional[str] =3D None self.pos =3D 0 self.cursor =3D 0 self.val: Optional[Union[bool, str]] =3D None - self.info =3D QAPISourceInfo(self._fname, parent=3Dincl_info) + self.info: QAPISourceInfo =3D QAPISourceInfo(self._fname, + parent=3Dparent_info) self.line_pos =3D 0 =20 # Parser output: @@ -100,11 +97,11 @@ def __init__(self, self.src =3D fp.read() except IOError as e: msg =3D "can't read {kind:s} file '{fname:s}': {errmsg:s}".for= mat( - kind=3D'include' if incl_info else 'schema', + kind=3D'include' if parent else 'schema', fname=3Dself._fname, errmsg=3De.strerror ) - context =3D incl_info or self.info + context =3D parent_info if parent_info else self.info raise QAPIParseError(context, msg) from e self._parse() =20 @@ -193,7 +190,7 @@ def _include(self, include: str, if incl_abs_fname in self._included: return None =20 - return QAPISchemaParser(incl_fname, self._included, self.info) + return QAPISchemaParser(incl_fname, self) =20 def accept(self, skip_comment: bool =3D True) -> None: """ --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600815202; cv=none; d=zohomail.com; s=zohoarc; b=lBrKwKiiTQ8dVde3qyN31/sauCEiIiw/WgBFkwHJsYcalTNiTOditI3frxbVKzPX0DrvSLYwpZf7fuf3IS5vSLYi9XwCoGTN/KdmRT9vfw6xOLe/h4fBRbzEsKn3SDKiZr662UPonTv69RVNfpxZX3vcUZ1SjtnQwF2LFrc9tcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600815202; 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=DqqTzaUnIDbKj5VfEuq8tE1FVI4iOp0G5PJp7jr73nk=; b=Ew9dHDqV9hbJBAygoU0CAW5XNBEPhb31ZCXCydbNLbcGbOpggXQb01ROOVtRKrd34vmRCERnmUxpxTfRs5yhvjXycqm+4kteQfKnIQAt0SgDTS4IADrlxGqiCLE+KbxL+BNWRsV2UNJsV2qIXbGShJBMRMkAIkHzeFMrg9ZjOk0= 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 1600815202160837.3199471921414; Tue, 22 Sep 2020 15:53:22 -0700 (PDT) Received: from localhost ([::1]:41772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKrA0-0004fj-RL for importer@patchew.org; Tue, 22 Sep 2020 18:53:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqtA-0004uX-0Q for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:56 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:59523 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqt7-0007iA-Uy for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:55 -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-230-t_6_dx9LNHeMdm01u6WcNg-1; Tue, 22 Sep 2020 18:35:50 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8B56F186DD27; Tue, 22 Sep 2020 22:35:49 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6892260BF4; Tue, 22 Sep 2020 22:35:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814152; 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=DqqTzaUnIDbKj5VfEuq8tE1FVI4iOp0G5PJp7jr73nk=; b=Gn9YRUNfU0o+Hl/x1Q/3dahpLfhetOnblgIk8FcHaM9/JBtqtd6FwgceKGkX4IAaUTifi4 ZvqqkBH0ZLB4s/eFh/VRcOZIodcPq4przFPfsgdEpV0h+wCQW42VPCyCpXdkYjcyGLi7ju F6VGUNIJ/D/al7bLJfk8q/A/j94wuOg= X-MC-Unique: t_6_dx9LNHeMdm01u6WcNg-1 From: John Snow To: Markus Armbruster Subject: [PATCH 20/26] qapi/parser.py: remove unused check_args_section arguments Date: Tue, 22 Sep 2020 18:35:19 -0400 Message-Id: <20200922223525.4085762-21-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=jsnow@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 13:33:09 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index fa0ddad922..a3403d4017 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -650,7 +650,7 @@ def check_expr(self, expr): =20 def check(self): =20 - def check_args_section(args, info, what): + def check_args_section(args): bogus =3D [name for name, section in args.items() if not section.member] if bogus: @@ -661,5 +661,5 @@ def check_args_section(args, info, what): "', '".join(bogus), "do" if len(bogus) > 1 else "does")) =20 - check_args_section(self.args, self.info, 'members') - check_args_section(self.features, self.info, 'features') + check_args_section(self.args) + check_args_section(self.features) --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600815059; cv=none; d=zohomail.com; s=zohoarc; b=ikIVmVN4az53DThJjl91JHT3RrNZIDI2YNA65esia5+eZyVNk9/VPsdNRAo1ljlkr/xnhozog0RX+jJuk7ZZNX2GfoaNANIhQSKvyCwiLu7+noz0BdVDcy4+6k64tkTsXSyfcqcZwJZ+VRjf6RoiYx352qzEhzh0t/Tx4nCdniI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600815059; 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=pHZFxl07TIYdNw8EF7I1vXj2EQzeoY8jGiAfQv30QKI=; b=MnjWXSdqs9LecDB34uPVTp6EZt1mxTg0d3o+5y7gkhCBPQNTOJE2jWBs6rhMWBpn9cwZk4FHYppJn5yPl8buyo7iQdWXAqMp502MH78BRf6TrQujaxTCtfNM+9TuT/G2bCshDmu8cysh0Q2d4QKPFBB/+yUwZXGAFy2naUMFx/U= 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 1600815059674656.6517064453515; Tue, 22 Sep 2020 15:50:59 -0700 (PDT) Received: from localhost ([::1]:32932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr7h-0000vS-7Z for importer@patchew.org; Tue, 22 Sep 2020 18:50:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqtA-0004vB-9j for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44118) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqt8-0007iZ-Gc for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:55 -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-175-nRuRPSIPNPe_oQlPSRhQtw-1; Tue, 22 Sep 2020 18:35:51 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A6026801AE8; Tue, 22 Sep 2020 22:35:50 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id B7F5060CCC; Tue, 22 Sep 2020 22:35:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814153; 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=pHZFxl07TIYdNw8EF7I1vXj2EQzeoY8jGiAfQv30QKI=; b=B/utQhLW7zPxVKwhDsqb1zj5TM5JipZyyVJHWazv8WRsmaQhlrA1PJfKm80ME0qqntT2tY Xmvm65CsEWAdLr7v8ohCk1yJZygGcMW7K+ekCg/5SIdildl7MwcMJ5khHxzXYfaR/wh3ju sqCaNVfsbSGCRhiMzbCyWCFSH9cva6Y= X-MC-Unique: nRuRPSIPNPe_oQlPSRhQtw-1 From: John Snow To: Markus Armbruster Subject: [PATCH 21/26] qapi/parser.py: QAPIDoc: convert @staticmethod to @classmethod Date: Tue, 22 Sep 2020 18:35:20 -0400 Message-Id: <20200922223525.4085762-22-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" For consistency: replace @staticmethod with @classmethod. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index a3403d4017..f5f40ffa16 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -465,8 +465,8 @@ def append(self, line): def end_comment(self): self._end_section() =20 - @staticmethod - def _is_section_tag(name): + @classmethod + def _is_section_tag(cls, name): return name in ('Returns:', 'Since:', # those are often singular or plural 'Note:', 'Notes:', --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600815443; cv=none; d=zohomail.com; s=zohoarc; b=JZA4iUAQMtio+h0K9iuda1ftfSeLQimoCiqo+gPzT+nkqadL5keZso3AXxDarvR3dGhGee2QxU+I7ehBZ2T4v0XUYBiqx0NNbLaqTRWNYuh2REeEOIqn1QZiH5Bi88uxS/aEUhJd8nzQyfMKb3+XTiS8CtZwWdOG7ItH75zURJ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600815443; 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=zYOmOo9imBbda8qkO2IraSrwFKE1gwRI/d1nAeUgSyw=; b=GdcnE7TaQ6sVxDEBaLzGxoh18Fmwq4aCc6LCQD5g6NKEDK1ll44bmrVbOUYiVKhTsRsaJ2RPnMjDjYCtb8JY/Vvx73YggmbI+HBL7xM55lcnyi4yyOM4pgPY/AQ4Sr9W3jB8s3KU+JbiAvGysrbdS/Y1xfFbzIab819ZQfc/zGo= 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 1600815443946956.0334427247831; Tue, 22 Sep 2020 15:57:23 -0700 (PDT) Received: from localhost ([::1]:58080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKrDu-0003AA-9r for importer@patchew.org; Tue, 22 Sep 2020 18:57:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqti-0006JE-3k for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:36:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:40265) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqtd-0007ot-Ll for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:36:29 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-572-m6u-WVRzOamqY5d7gc5sxA-1; Tue, 22 Sep 2020 18:35:52 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A5816186DD27; Tue, 22 Sep 2020 22:35:51 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id D255760BF4; Tue, 22 Sep 2020 22:35:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814184; 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=zYOmOo9imBbda8qkO2IraSrwFKE1gwRI/d1nAeUgSyw=; b=HGyAxBzkMFJ3YnupS5axc4ykTAH3osBlEigzjmUQT3afmgtPc0P+x2g9clvavQhokR8ZSR cmR23LJpNptYJu02dd5WjNktsiqcad7190Qhxd2av3FCoaaF472bRupoBLLlGYFkZXGnFN yBRzrDNlCWl0wCb/nU05OvBNVeys/Tw= X-MC-Unique: m6u-WVRzOamqY5d7gc5sxA-1 From: John Snow To: Markus Armbruster Subject: [PATCH 22/26] qapi/parser.py: add type hint annotations (QAPIDoc) Date: Tue, 22 Sep 2020 18:35:21 -0400 Message-Id: <20200922223525.4085762-23-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 02:07:04 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 68 +++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index f5f40ffa16..cdb64ffc22 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -23,6 +23,7 @@ NamedTuple, Optional, Set, + TYPE_CHECKING, Type, TypeVar, Union, @@ -32,6 +33,10 @@ from .pragma import PragmaError from .source import QAPISourceInfo =20 +if TYPE_CHECKING: + # pylint: disable=3Dcyclic-import + from .schema import QAPISchemaMember, QAPISchemaFeature + =20 _Value =3D Union[List[object], 'OrderedDict[str, object]', str, bool] # Necessary imprecision: mypy does not (yet?) support recursive types; @@ -405,43 +410,43 @@ class QAPIDoc: """ =20 class Section: - def __init__(self, name=3DNone): + def __init__(self, name: Optional[str] =3D None): # optional section name (argument/member or section name) self.name =3D name self.text =3D '' =20 - def append(self, line): + def append(self, line: str) -> None: self.text +=3D line.rstrip() + '\n' =20 class ArgSection(Section): - def __init__(self, name): + def __init__(self, name: Optional[str] =3D None): super().__init__(name) - self.member =3D None + self.member: Optional['QAPISchemaMember'] =3D None =20 - def connect(self, member): + def connect(self, member: 'QAPISchemaMember') -> None: self.member =3D member =20 - def __init__(self, info): + def __init__(self, info: QAPISourceInfo): self.info =3D info - self.symbol =3D None + self.symbol: Optional[str] =3D None self.body =3D QAPIDoc.Section() # dict mapping parameter name to ArgSection - self.args =3D OrderedDict() - self.features =3D OrderedDict() + self.args: 'OrderedDict[str, QAPIDoc.ArgSection]' =3D OrderedDict() + self.features: 'OrderedDict[str, QAPIDoc.ArgSection]' =3D OrderedD= ict() # a list of Section - self.sections =3D [] + self.sections: List[QAPIDoc.Section] =3D [] # the current section self._section =3D self.body self._append_line =3D self._append_body_line =20 - def has_section(self, name): + def has_section(self, name: str) -> bool: """Return True if we have a section with this name.""" for i in self.sections: if i.name =3D=3D name: return True return False =20 - def append(self, line): + def append(self, line: str) -> None: """ Parse a comment line and add it to the documentation. =20 @@ -462,18 +467,18 @@ def append(self, line): line =3D line[1:] self._append_line(line) =20 - def end_comment(self): + def end_comment(self) -> None: self._end_section() =20 @classmethod - def _is_section_tag(cls, name): + def _is_section_tag(cls, name: str) -> bool: return name in ('Returns:', 'Since:', # those are often singular or plural 'Note:', 'Notes:', 'Example:', 'Examples:', 'TODO:') =20 - def _append_body_line(self, line): + def _append_body_line(self, line: str) -> None: """ Process a line of documentation text in the body section. =20 @@ -513,7 +518,7 @@ def _append_body_line(self, line): # This is a free-form documentation block self._append_freeform(line.strip()) =20 - def _append_args_line(self, line): + def _append_args_line(self, line: str) -> None: """ Process a line of documentation text in an argument section. =20 @@ -546,7 +551,7 @@ def _append_args_line(self, line): =20 self._append_freeform(line.strip()) =20 - def _append_features_line(self, line): + def _append_features_line(self, line: str) -> None: name =3D line.split(' ', 1)[0] =20 if name.startswith('@') and name.endswith(':'): @@ -565,7 +570,7 @@ def _append_features_line(self, line): =20 self._append_freeform(line.strip()) =20 - def _append_various_line(self, line): + def _append_various_line(self, line: str) -> None: """ Process a line of documentation text in an additional section. =20 @@ -591,7 +596,10 @@ def _append_various_line(self, line): =20 self._append_freeform(line) =20 - def _start_symbol_section(self, symbols_dict, name): + def _start_symbol_section( + self, + symbols_dict: 'OrderedDict[str, QAPIDoc.ArgSection]', + name: str) -> None: # FIXME invalid names other than the empty string aren't flagged if not name: raise QAPIDocError("invalid parameter name") @@ -602,20 +610,20 @@ def _start_symbol_section(self, symbols_dict, name): self._section =3D QAPIDoc.ArgSection(name) symbols_dict[name] =3D self._section =20 - def _start_args_section(self, name): + def _start_args_section(self, name: str) -> None: self._start_symbol_section(self.args, name) =20 - def _start_features_section(self, name): + def _start_features_section(self, name: str) -> None: self._start_symbol_section(self.features, name) =20 - def _start_section(self, name=3DNone): + def _start_section(self, name: Optional[str] =3D None) -> None: if name in ('Returns', 'Since') and self.has_section(name): raise QAPIDocError("duplicated '%s' section" % name) self._end_section() self._section =3D QAPIDoc.Section(name) self.sections.append(self._section) =20 - def _end_section(self): + def _end_section(self) -> None: if self._section: text =3D self._section.text =3D self._section.text.strip() if self._section.name and (not text or text.isspace()): @@ -623,34 +631,34 @@ def _end_section(self): "empty doc section '%s'" % self._section.name) self._section =3D None =20 - def _append_freeform(self, line): + def _append_freeform(self, line: str) -> None: match =3D re.match(r'(@\S+:)', line) if match: raise QAPIDocError("'%s' not allowed in free-form documentatio= n" % match.group(1)) self._section.append(line) =20 - def connect_member(self, member): + def connect_member(self, member: 'QAPISchemaMember') -> None: if member.name not in self.args: # Undocumented TODO outlaw self.args[member.name] =3D QAPIDoc.ArgSection(member.name) self.args[member.name].connect(member) =20 - def connect_feature(self, feature): + def connect_feature(self, feature: 'QAPISchemaFeature') -> None: if feature.name not in self.features: raise QAPISemError(feature.info, "feature '%s' lacks documentation" % feature.name) self.features[feature.name].connect(feature) =20 - def check_expr(self, expr): + def check_expr(self, expr: 'OrderedDict[str, object]') -> None: if self.has_section('Returns') and 'command' not in expr: raise QAPISemError(self.info, "'Returns:' is only valid for commands") =20 - def check(self): - - def check_args_section(args): + def check(self) -> None: + def check_args_section( + args: 'OrderedDict[str, QAPIDoc.ArgSection]') -> None: bogus =3D [name for name, section in args.items() if not section.member] if bogus: --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814794; cv=none; d=zohomail.com; s=zohoarc; b=eIvZi/UOf5v6Fs6RVGA+xMASPEpVgy8C9fPMFf55NJVdhxuvWatHScUjOwlQPtjxGctpGNTUYNp+Zjm3LaWMezqpM3BrQFEjAN0XvpXvYAqdVIhzSs1kyKQYnIk/cAp+7GqkUOe7XQWTlzN9zy+K+S+FChxycKYw/rOJOE9WwlY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814794; 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=5dDPP0KFvn7o6PYfniM7VGeH7Pm+p2luU/Vg6xwyPq8=; b=LaI+Fb7y716i1uDbhzEjDl8lfr+KnpXkqnxhBWnaYSSsS6VpWe82cGN5nTkWSC2N0FmjOAYRacVj+ch6rqNmNNqQGgjMHCRJ/C500cIDweyiOfpwbpaumEM2MqzEdhzgkLdDt2Ia2TMdwb1HZto6H7tgDXmo8J9cPLtzoQJ4f2c= 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 1600814794228140.44109148764278; Tue, 22 Sep 2020 15:46:34 -0700 (PDT) Received: from localhost ([::1]:44990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr3Q-0002c2-J9 for importer@patchew.org; Tue, 22 Sep 2020 18:46:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58288) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqtC-0004zv-1M for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35:58 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:23112 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqtA-0007jx-DF for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:35: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-418-MqNzN1qPNFy4sqVOKYK4Ig-1; Tue, 22 Sep 2020 18:35:53 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DA66F1005CA7; Tue, 22 Sep 2020 22:35:52 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id D237A60BF4; Tue, 22 Sep 2020 22:35:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814155; 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=5dDPP0KFvn7o6PYfniM7VGeH7Pm+p2luU/Vg6xwyPq8=; b=Pk0h6liSTts+rAh94lFG2qtYkW1o/3TalNZt9qkh7rQYNy2Go6PP3LVX9fh1kVMlz/11lu BsBPB+UYnvUHwo4+Fq8lWwDwkzj7gz5SIaTcjwCi9gohaZOgQcc0/SoWg++BrInKOLyfij rDCQZjcixIKCg7FVdVrFZtQEuaBjrHw= X-MC-Unique: MqNzN1qPNFy4sqVOKYK4Ig-1 From: John Snow To: Markus Armbruster Subject: [PATCH 23/26] qapi/parser.py: enable mypy checks Date: Tue, 22 Sep 2020 18:35:22 -0400 Message-Id: <20200922223525.4085762-24-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 17:00:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/mypy.ini | 5 ----- 1 file changed, 5 deletions(-) diff --git a/scripts/qapi/mypy.ini b/scripts/qapi/mypy.ini index 4d341c6b2d..20ab509946 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -4,11 +4,6 @@ strict_optional =3D False disallow_untyped_calls =3D False python_version =3D 3.6 =20 -[mypy-qapi.parser] -disallow_untyped_defs =3D False -disallow_incomplete_defs =3D False -check_untyped_defs =3D False - [mypy-qapi.schema] disallow_untyped_defs =3D False disallow_incomplete_defs =3D False --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600815190; cv=none; d=zohomail.com; s=zohoarc; b=T3F4WKMuoJ/8s3N6jCXbWVA0xgtQ5eb8wXbQV/qSEnqdQt2pMGFvkMk7EO3uMGYkru8eRZUkhyjToBY2mtZKB2UBHb3b9mUK3Ks/xPoduDxyOBRxUUjoMs0kln1K36OxIuZYzpOtPQNI99C8Y1ZqyPUMmkFKVOqezmCUBHEGBUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600815190; 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=J58kk9KonAS7Kge2Gue/KficmECzeBFNtMpPf9StRKk=; b=NxTHhokpT/tB3dp7odwbVYly7MoSAUoJ0UfmfW5I4/l2BwS43XZJldSP1wr/lJN/vjT8sg9CN4QI6NCDl4z1Y8DBIgPaApj2g3y71cJnqPDsZspL/63+ZPFkaAEq/AOSibJdU5ubB6QODqIbGBUapEPdEeZ5uOAV/MJlLfXFF/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 1600815190455394.91469109743423; Tue, 22 Sep 2020 15:53:10 -0700 (PDT) Received: from localhost ([::1]:41338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr9n-0004VF-5N for importer@patchew.org; Tue, 22 Sep 2020 18:53:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqtE-00056o-OY for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:36:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqtC-0007lX-Pb for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:36:00 -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-377-F9Ea86SHNA-hTURJuKKVDg-1; Tue, 22 Sep 2020 18:35:55 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 46FD581CAFB; Tue, 22 Sep 2020 22:35:54 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21B9160BF4; Tue, 22 Sep 2020 22:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814158; 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=J58kk9KonAS7Kge2Gue/KficmECzeBFNtMpPf9StRKk=; b=NYTx7AtLUSCtr6VCUWnM0Flo4hmiJtIY7oeXHdtkToJezBjai94dsVHW7+ZRVQiwI5BWbg mZIbwoDk4L9RRmksuLVsVz/qf3rN6Lu0qsdEb1YvRMBJIeRCuwQrjxo4Ewrvy00xX8lKnE M9ZkwWjqp7VqSkXetAUAUQrfaju3oNk= X-MC-Unique: F9Ea86SHNA-hTURJuKKVDg-1 From: John Snow To: Markus Armbruster Subject: [PATCH 24/26] qapi/parser.py: remove one and two-letter variables Date: Tue, 22 Sep 2020 18:35:23 -0400 Message-Id: <20200922223525.4085762-25-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Standard pylint complaint: use more descriptibe variable names. OK, fine. Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index cdb64ffc22..818f8bc580 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -57,8 +57,8 @@ class QAPIParseError(QAPISourceError): @classmethod def make(cls: Type[T], parser: 'QAPISchemaParser', msg: str) -> T: col =3D 1 - for ch in parser.src[parser.line_pos:parser.pos]: - if ch =3D=3D '\t': + for char in parser.src[parser.line_pos:parser.pos]: + if char =3D=3D '\t': col =3D (col + 7) % 8 + 1 else: col +=3D 1 @@ -100,14 +100,16 @@ def __init__(self, fname: str, try: with open(self._fname, 'r', encoding=3D'utf-8') as fp: self.src =3D fp.read() - except IOError as e: + except IOError as err: msg =3D "can't read {kind:s} file '{fname:s}': {errmsg:s}".for= mat( kind=3D'include' if parent else 'schema', fname=3Dself._fname, - errmsg=3De.strerror + errmsg=3Derr.strerror ) context =3D parent_info if parent_info else self.info - raise QAPIParseError(context, msg) from e + raise QAPIParseError(context, msg) from err + + # Showtime! self._parse() =20 def _parse(self) -> None: @@ -245,25 +247,25 @@ def accept(self, skip_comment: bool =3D True) -> None: string =3D '' esc =3D False while True: - ch =3D self.src[self.cursor] + char =3D self.src[self.cursor] self.cursor +=3D 1 - if ch =3D=3D '\n': + if char =3D=3D '\n': raise self._parse_error("missing terminating \"'\"= ") if esc: # Note: we recognize only \\ because we have # no use for funny characters in strings - if ch !=3D '\\': - raise self._parse_error(f"unknown escape \\{ch= }") + if char !=3D '\\': + raise self._parse_error(f"unknown escape \\{ch= ar}") esc =3D False - elif ch =3D=3D '\\': + elif char =3D=3D '\\': esc =3D True continue - elif ch =3D=3D "'": + elif char =3D=3D "'": self.val =3D string return - if ord(ch) < 32 or ord(ch) >=3D 127: + if ord(char) < 32 or ord(char) >=3D 127: raise self._parse_error("funny character in string= ") - string +=3D ch + string +=3D char elif self.src.startswith('true', self.pos): self.val =3D True self.cursor +=3D 3 --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600814923; cv=none; d=zohomail.com; s=zohoarc; b=SKEbWT7GB+6eyPRKogJo4r+347DkU8L+T93ci29oCiwDPHTZd/qLuE3+vAruBgwnan2027pyJdzPyFHT4QSl5dzGn3XykVJg0Jf8+xIAwjluK/rSVdRSFtAuVQ03qSLAKqFnYnuYlaaYMbcTX/u1Ka0P/PYxffsAEd4wYSZjQ2Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600814923; 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=lH56PFrv2xupag+D/VVl2XGyz6Fs7ITLTTSckxtpENY=; b=bHM6SmB2eztKpC5Sk7tynJafbcymfMv9Li8s2CE78iHOJd/8XE6ytNzYZ0sUjbdP0Xn0IUQW959QTSHMbwwc2RPOtGe3a6AV61XPUHjleNsawKXkUmCTRM96WaMgNM7QIkwPusqnBGu3jVcwOkkK1Rdu6G/tw32A57q65KNolas= 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 1600814923819367.59741071996666; Tue, 22 Sep 2020 15:48:43 -0700 (PDT) Received: from localhost ([::1]:53318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr5W-00065v-Fq for importer@patchew.org; Tue, 22 Sep 2020 18:48:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqtG-0005Ag-5j for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:36:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:46289) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqtE-0007mK-D3 for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:36: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-527-cEP2jUunMc2u1MOPE76Caw-1; Tue, 22 Sep 2020 18:35:56 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4438F801AE8; Tue, 22 Sep 2020 22:35:55 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 744CA60BF4; Tue, 22 Sep 2020 22:35:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814159; 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=lH56PFrv2xupag+D/VVl2XGyz6Fs7ITLTTSckxtpENY=; b=NGpiFrkkIZXBmUrEAg8kjMo74IVHU0OSv+P3u7Q5EEYEQ8pCqOeVl6IYtxL7MDwSD5SuKO 8F8hH7dox4RUSVDRVGGP4natHaCnOKRG0V4j6LAs9jcpNusCqBDJCJLU2oylGPZ2tj1Ol9 OjUOy4BzgbSwcWjGEaoTH7g4PgTzijQ= X-MC-Unique: cEP2jUunMc2u1MOPE76Caw-1 From: John Snow To: Markus Armbruster Subject: [PATCH 25/26] qapi/parser.py: Silence too-few-public-methods warning Date: Tue, 22 Sep 2020 18:35:24 -0400 Message-Id: <20200922223525.4085762-26-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/parser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 818f8bc580..e3481b02f2 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -412,6 +412,8 @@ class QAPIDoc: """ =20 class Section: + # pylint: disable=3Dtoo-few-public-methods + def __init__(self, name: Optional[str] =3D None): # optional section name (argument/member or section name) self.name =3D name --=20 2.26.2 From nobody Sun May 5 18:14:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600815306; cv=none; d=zohomail.com; s=zohoarc; b=OCyYl+/ZHQ5SQ4WbrVzvokFs9Hbet/24qAr2GCDcjWxmrLwH9B0guCbus0wouXqYQZ2kb5CAPslqJP9lFZ3LKwKrddYBwwEqu4a5ega3hI0rBeGIXigWOrSTcShHD4UtiElPKFQOojaYrhXVNcdkq2v4tLaJz3onpeYYCMJN8R8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600815306; 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=WIXC9m+eUFElyWRXz3PZkTgl23wI6PWbMikj9v1K5pg=; b=bcdB99o75pWEo4Wyx0DQy0NslnT1xcXNLJxzMd4nxIgIr2AfIecS9NqpO9QlGw14i+iK3ymYbp7W7+Kr2CPFyYTBbWHrFztMMdgl+snyOnT2ib+tRGoPbfX6gP3u/AxQPUnwaZWE2f77iq13oE99szwM+PXlbR30e0tHRSCc1i0= 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 1600815306586613.5447700690149; Tue, 22 Sep 2020 15:55:06 -0700 (PDT) Received: from localhost ([::1]:49626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKrBh-0007xn-6b for importer@patchew.org; Tue, 22 Sep 2020 18:55:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kKqtH-0005E6-Jk for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:36:03 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:34090) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kKqtF-0007n7-PT for qemu-devel@nongnu.org; Tue, 22 Sep 2020 18:36:03 -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-451-pdXStFfbP4i-uxXZyf8AeA-1; Tue, 22 Sep 2020 18:35:57 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3AA19801AE9; Tue, 22 Sep 2020 22:35:56 +0000 (UTC) Received: from scv.redhat.com (ovpn-119-140.rdu2.redhat.com [10.10.119.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F21160CCC; Tue, 22 Sep 2020 22:35:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600814161; 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=WIXC9m+eUFElyWRXz3PZkTgl23wI6PWbMikj9v1K5pg=; b=QbZVeWksYCqo7nqf+qrYf2ke0oIg423XrazkTZoeeS7CAbtd5bIvWne4XGMCC6Q009Khw6 vwTlJJ2RJYEioJnG4PBXXrJAu7BnLDYH34WDcp+cKPE0cju2qcsfSpQEDuypdXLonSVbu4 rAXmIT8hLzwgFn53C1NsP9Vxk9wfIEA= X-MC-Unique: pdXStFfbP4i-uxXZyf8AeA-1 From: John Snow To: Markus Armbruster Subject: [PATCH 26/26] qapi/parser.py: enable pylint checks Date: Tue, 22 Sep 2020 18:35:25 -0400 Message-Id: <20200922223525.4085762-27-jsnow@redhat.com> In-Reply-To: <20200922223525.4085762-1-jsnow@redhat.com> References: <20200922223525.4085762-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/22 15:47:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.455, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cleber Rosa , John Snow , qemu-devel@nongnu.org, Eduardo Habkost , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: John Snow based-on: <20200922210101.4081073-1-jsnow@redhat.com> based-on: <20200922212115.4084301-1-jsnow@redhat.com> --- scripts/qapi/pylintrc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/qapi/pylintrc b/scripts/qapi/pylintrc index 88efbf71cb..5091a08f12 100644 --- a/scripts/qapi/pylintrc +++ b/scripts/qapi/pylintrc @@ -2,8 +2,7 @@ =20 # Add files or directories matching the regex patterns to the ignore list. # The regex matches against base names, not paths. -ignore-patterns=3Dparser.py, - schema.py, +ignore-patterns=3Dschema.py, =20 =20 [MESSAGES CONTROL] --=20 2.26.2