From patchwork Tue Sep 22 22:35:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304688 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84DFCC4727D for ; Tue, 22 Sep 2020 22:40:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C1E820936 for ; Tue, 22 Sep 2020 22:40:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SrCP1h2k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C1E820936 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqx7-0002fi-6m for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:40:01 -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 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= 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 X-MC-Unique: VLWWGsa4N92iU4kRc2aWCw-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" For the sake of keeping __init__ easier to reason about, with fewer variables in play. Signed-off-by: John Snow --- 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: def __init__(self, fname, previously_included=None, incl_info=None): - previously_included = previously_included or set() - previously_included.add(os.path.abspath(fname)) + self._fname = fname + self._included = previously_included or set() + self._included.add(os.path.abspath(self._fname)) + + self.cursor = 0 + self.info = QAPISourceInfo(self._fname, 1, incl_info) + self.line_pos = 0 + self.exprs = [] + self.docs = [] try: - fp = open(fname, 'r', encoding='utf-8') + fp = open(self._fname, 'r', encoding='utf-8') self.src = fp.read() except IOError as e: raise QAPISemError(incl_info or QAPISourceInfo(None, None, None), "can't read %s file '%s': %s" % ("include" if incl_info else "schema", - fname, + self._fname, e.strerror)) + self._parse() + def _parse(self): + cur_doc = None + + # Prime the lexer: if self.src == '' or self.src[-1] != '\n': self.src += '\n' - self.cursor = 0 - self.info = QAPISourceInfo(fname, 1, incl_info) - self.line_pos = 0 - self.exprs = [] - self.docs = [] self.accept() - cur_doc = None while self.tok is not None: info = self.info @@ -86,12 +92,12 @@ def __init__(self, fname, previously_included=None, incl_info=None): if not isinstance(include, str): raise QAPISemError(info, "value of 'include' must be a string") - incl_fname = os.path.join(os.path.dirname(fname), + incl_fname = os.path.join(os.path.dirname(self._fname), include) self.exprs.append({'expr': {'include': incl_fname}, 'info': info}) exprs_include = 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) From patchwork Tue Sep 22 22:35:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C461C4727D for ; Tue, 22 Sep 2020 22:36:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B94FC20715 for ; Tue, 22 Sep 2020 22:36:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iST5jX3z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B94FC20715 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqtm-0005vm-C3 for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:36:34 -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 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= 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 X-MC-Unique: q6WJou7sNkSlvYzPqhNYeQ-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Add missing declarations and group them by function so they're easier to understand at a distance. Signed-off-by: John Snow --- 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=None, incl_info=None): self._included = previously_included or set() self._included.add(os.path.abspath(self._fname)) + # Lexer state (see `accept` for details): + self.tok = None + self.pos = 0 self.cursor = 0 + self.val = None self.info = QAPISourceInfo(self._fname, 1, incl_info) self.line_pos = 0 + + # Parser output: self.exprs = [] self.docs = [] + # Showtime! try: fp = open(self._fname, 'r', encoding='utf-8') self.src = fp.read() From patchwork Tue Sep 22 22:35:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304690 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EF2CC2D0E2 for ; Tue, 22 Sep 2020 22:37:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9E7C420715 for ; Tue, 22 Sep 2020 22:37:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="OaNAoAso" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E7C420715 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44754 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKquo-0007XO-K2 for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:37:38 -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 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= 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 X-MC-Unique: KBVqvTtjMQqY_sgBX2amTQ-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Minor, this prevents file descriptor leaks on error pathways. Signed-off-by: John Snow --- 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=None, incl_info=None): # Showtime! try: - fp = open(self._fname, 'r', encoding='utf-8') - self.src = fp.read() + with open(self._fname, 'r', encoding='utf-8') as fp: + self.src = fp.read() except IOError as e: raise QAPISemError(incl_info or QAPISourceInfo(None, None, None), "can't read %s file '%s': %s" From patchwork Tue Sep 22 22:35:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB1CCC4741F for ; Tue, 22 Sep 2020 22:36:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 62CE120715 for ; Tue, 22 Sep 2020 22:36:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="X1/PZ2Bi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62CE120715 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqto-00061k-Bl for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:36:36 -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 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= 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 X-MC-Unique: cKbZRuhAOtesMk6PVosQXQ-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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=None, incl_info=None): with open(self._fname, 'r', encoding='utf-8') as fp: self.src = fp.read() except IOError as e: - raise QAPISemError(incl_info or QAPISourceInfo(None, None, None), + 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 = TypeVar('T', bound='QAPISourceInfo') - def __init__(self: T, fname: str, line: int, parent: Optional[T]): + def __init__(self: T, + fname: str, + line: int = 0, + parent: Optional[T] = None): self.fname = fname self.line = line self.parent = parent @@ -53,7 +56,7 @@ def loc(self) -> str: if self.fname is None: return sys.argv[0] ret = self.fname - if self.line is not None: + if self.line: ret += ':%d' % self.line return ret From patchwork Tue Sep 22 22:35:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 921B6C2D0E2 for ; Tue, 22 Sep 2020 22:39:09 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1ABF820715 for ; Tue, 22 Sep 2020 22:39:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RFaA7pt8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1ABF820715 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqwG-0000wL-5S for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:39:08 -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 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= 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 X-MC-Unique: 9Z2S4PshODySUI640UdPWQ-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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=None, incl_info=None): self.pos = 0 self.cursor = 0 self.val = None - self.info = QAPISourceInfo(self._fname, 1, incl_info) + self.info = QAPISourceInfo(self._fname, parent=incl_info) self.line_pos = 0 # Parser output: @@ -78,6 +78,7 @@ def _parse(self): cur_doc = None # Prime the lexer: + self.info.line += 1 if self.src == '' or self.src[-1] != '\n': self.src += '\n' self.accept() From patchwork Tue Sep 22 22:35:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C7BFC4727E for ; Tue, 22 Sep 2020 22:41:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DA70E2076E for ; Tue, 22 Sep 2020 22:41:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LdWy2D4E" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DA70E2076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqyk-0004V1-Sh for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:41:42 -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 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= 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 X-MC-Unique: MDtuzdY0M9yGt3HD_r54Cg-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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=None, incl_info=None): with open(self._fname, 'r', encoding='utf-8') as fp: self.src = 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 = "can't read {kind:s} file '{fname:s}': {errmsg:s}".format( + kind='include' if incl_info else 'schema', + fname=self._fname, + errmsg=e.strerror + ) + context = incl_info or self.info + raise QAPIParseError(context, msg) from e self._parse() def _parse(self): From patchwork Tue Sep 22 22:35:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AAADC2D0E2 for ; Tue, 22 Sep 2020 22:39:12 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DFF3A20715 for ; Tue, 22 Sep 2020 22:39:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UtG/i6b5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DFF3A20715 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqwJ-00013F-1k for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:39:11 -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 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= 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 X-MC-Unique: wAUacH1bOYyLil5r-ogUwg-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 == ']': 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 == ']': @@ -295,12 +295,12 @@ def get_expr(self, nested): elif self.tok == '[': self.accept() expr = self.get_values() - elif self.tok in "'tfn": + elif self.tok in "'tf": expr = self.val self.accept() else: raise self._parse_error( - "expected '{', '[', string, boolean or 'null'") + "expected '{', '[', string, or boolean") return expr def _get_doc(self, info): diff --git a/tests/qapi-schema/leading-comma-list.err b/tests/qapi-schema/leading-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 From patchwork Tue Sep 22 22:35:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18BBBC4727D for ; Tue, 22 Sep 2020 22:41:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E33C221EB for ; Tue, 22 Sep 2020 22:41:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H8zxzwBo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E33C221EB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:57602 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqyj-0004N1-M7 for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:41:41 -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 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= 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 X-MC-Unique: giPYim8bNeCw0kcI1VU16A-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 = QAPIDoc(info) self.accept(False) while self.tok == '#': + assert isinstance(self.val, str), "Expected str value" if self.val.startswith('##'): # End of doc comment if self.val != '##': From patchwork Tue Sep 22 22:35:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06438C4727D for ; Tue, 22 Sep 2020 22:43:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F02B2076E for ; Tue, 22 Sep 2020 22:43:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="VSJ0P5x9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F02B2076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr0e-0007vx-Kb for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:43:40 -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 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= 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 X-MC-Unique: 46tfiXMHPva8GzhuiwT6zA-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 expr = 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) != 1: From patchwork Tue Sep 22 22:35:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 166D2C2D0E2 for ; Tue, 22 Sep 2020 22:46:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 69B1E20757 for ; Tue, 22 Sep 2020 22:46:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H4lO1SUi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 69B1E20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr3K-0002WP-5U for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:46:26 -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 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= 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 X-MC-Unique: _GNqg23MPlWhexVnUdrgSQ-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Since values can also be other data types, add an assertion to ensure we're dealing with strings. Signed-off-by: John Snow --- 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 = self.val + assert isinstance(key, str), f"expected str, got {type(key)!s}" + self.accept() if self.tok != ':': raise self._parse_error("expected ':'") From patchwork Tue Sep 22 22:35:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E3F9C2D0E2 for ; Tue, 22 Sep 2020 22:48:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AD4332076E for ; Tue, 22 Sep 2020 22:48:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="f5Z0/IWv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD4332076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53170 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr5R-00061p-OZ for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:48:37 -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 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= 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 X-MC-Unique: 0Tf8tEh_M9mWFIl1M4_rGQ-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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) - @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) - def _include(self, include, info, incl_fname, previously_included): + @classmethod + def _include(cls, include, info, incl_fname, previously_included): incl_abs_fname = os.path.abspath(incl_fname) # catch inclusion cycle inf = info @@ -162,7 +163,8 @@ def _include(self, include, info, incl_fname, previously_included): return QAPISchemaParser(incl_fname, previously_included, info) - def _pragma(self, name, value, info): + @classmethod + def _pragma(cls, name, value, info): if name == 'doc-required': if not isinstance(value, bool): raise QAPISemError(info, From patchwork Tue Sep 22 22:35:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5762C2D0E2 for ; Tue, 22 Sep 2020 22:43:39 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 50B692076E for ; Tue, 22 Sep 2020 22:43:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JNuM219I" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50B692076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr0c-0007qh-G3 for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:43:38 -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 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= 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 X-MC-Unique: M6TWuIsJOveOnkxQ2NpgkA-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 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 = value + info.pragma.returns_whitelist = cast(List[str], value) elif name == '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 = value + info.pragma.name_case_whitelist = cast(List[str], value) else: raise QAPISemError(info, "unknown pragma '%s'" % name) From patchwork Tue Sep 22 22:35:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1F7BC2D0E2 for ; Tue, 22 Sep 2020 22:42:59 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79AD42076E for ; Tue, 22 Sep 2020 22:42:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HFpqFgk0" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 79AD42076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqzy-0006A5-JU for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:42:58 -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 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= 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 X-MC-Unique: Gbu67MJLOgiG1-ovuTSCOw-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Annotations do not change runtime behavior. This commit *only* adds annotations. Annotations for QAPIDoc are in a later commit. Signed-off-by: John Snow --- 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. + +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, +) from .error import QAPIError, QAPISourceError, QAPISemError from .source import QAPISourceInfo +Expression = Dict[str, Any] +_Value = 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 = TypeVar('T', bound='QAPIParseError') @classmethod @@ -45,22 +62,25 @@ class QAPIDocError(QAPIError): class QAPISchemaParser: - def __init__(self, fname, previously_included=None, incl_info=None): + def __init__(self, + fname: str, + previously_included: Optional[Set[str]] = None, + incl_info: Optional[QAPISourceInfo] = None): self._fname = fname self._included = previously_included or set() self._included.add(os.path.abspath(self._fname)) # Lexer state (see `accept` for details): - self.tok = None + self.tok: Optional[str] = None self.pos = 0 self.cursor = 0 - self.val = None + self.val: Optional[Union[bool, str]] = None self.info = QAPISourceInfo(self._fname, parent=incl_info) self.line_pos = 0 # Parser output: - self.exprs = [] - self.docs = [] + self.exprs: List[Expression] = [] + self.docs: List[QAPIDoc] = [] # Showtime! try: @@ -76,7 +96,7 @@ def __init__(self, fname, previously_included=None, incl_info=None): raise QAPIParseError(context, msg) from e self._parse() - def _parse(self): + def _parse(self) -> None: cur_doc = None # Prime the lexer: @@ -140,7 +160,7 @@ def _parse_error(self, msg: str) -> QAPIParseError: return QAPIParseError.make(self, msg) @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) @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 = os.path.abspath(incl_fname) # catch inclusion cycle inf = info @@ -164,7 +189,10 @@ def _include(cls, include, info, incl_fname, previously_included): return QAPISchemaParser(incl_fname, previously_included, info) @classmethod - def _pragma(cls, name, value, info): + def _pragma(cls, + name: str, + value: object, + info: QAPISourceInfo) -> None: if name == '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) - def accept(self, skip_comment=True): + def accept(self, skip_comment: bool = True) -> None: while True: self.tok = self.src[self.cursor] self.pos = self.cursor @@ -249,8 +277,8 @@ def accept(self, skip_comment=True): self.src[self.cursor-1:]) raise self._parse_error("stray '%s'" % match.group(0)) - def get_members(self): - expr = OrderedDict() + def get_members(self) -> 'OrderedDict[str, object]': + expr: 'OrderedDict[str, object]' = OrderedDict() if self.tok == '}': self.accept() return expr @@ -276,8 +304,8 @@ def get_members(self): if self.tok != "'": raise self._parse_error("expected string") - def get_values(self): - expr = [] + def get_values(self) -> List[object]: + expr: List[object] = [] if self.tok == ']': self.accept() return expr @@ -293,7 +321,8 @@ def get_values(self): raise self._parse_error("expected ',' or ']'") self.accept() - def get_expr(self, nested): + def get_expr(self, nested: bool = False) -> _Value: + expr: _Value if self.tok != '{' and not nested: raise self._parse_error("expected '{'") if self.tok == '{': @@ -310,7 +339,7 @@ def get_expr(self, nested): "expected '{', '[', string, or boolean") return expr - def _get_doc(self, info): + def _get_doc(self, info: QAPISourceInfo) -> List['QAPIDoc']: if self.val != '##': raise self._parse_error( "junk after '##' at start of documentation comment") @@ -342,7 +371,7 @@ def _get_doc(self, info): raise self._parse_error("documentation comment must end with '##'") - def get_doc(self, info): + def get_doc(self, info: QAPISourceInfo) -> List['QAPIDoc']: try: return self._get_doc(info) except QAPIDocError as err: From patchwork Tue Sep 22 22:35:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0A8BC4727E for ; Tue, 22 Sep 2020 22:51:00 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3D668206A5 for ; Tue, 22 Sep 2020 22:51:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FhstZodi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D668206A5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr7j-00017a-7C for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:50:59 -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 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= 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 X-MC-Unique: WSV9awEwPGCz8mjvddRMmQ-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- 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): class QAPISchemaParser: + """ + Performs parsing of a QAPI schema source file. + :param fname: Path to the source file + :param previously_included: Set of absolute paths of previously included + source files; these will not be parsed again. + :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]] = None, @@ -97,6 +105,10 @@ def __init__(self, self._parse() def _parse(self) -> None: + """ + Parse the QAPI Schema Document. + Build self.exprs, self.docs + """ cur_doc = None # Prime the lexer: @@ -216,6 +228,32 @@ def _pragma(cls, raise QAPISemError(info, "unknown pragma '%s'" % name) def accept(self, skip_comment: bool = 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-line. + (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 = self.src[self.cursor] self.pos = self.cursor From patchwork Tue Sep 22 22:35:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304682 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA873C2D0E2 for ; Tue, 22 Sep 2020 22:48:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 63E662076E for ; Tue, 22 Sep 2020 22:48:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="hZfqKNqN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63E662076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr5O-0005tC-Au for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:48:34 -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 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= 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 X-MC-Unique: ZwgtsrW-PTKl5bdz19JcUA-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 @@ from .common import c_name from .error import QAPISemError -from .parser import QAPIDoc +from .parser import ParsedExpression from .source import QAPISourceInfo @@ -517,7 +517,7 @@ class ExpressionType(str, Enum): } -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] @@ -526,49 +526,33 @@ def check_exprs(exprs: List[_JSObject]) -> List[_JSObject]: :param exprs: The list of expressions to normalize/validate. """ - for expr_elem in exprs: - # Expression - assert isinstance(expr_elem['expr'], dict) - expr: Expression = expr_elem['expr'] - for key in expr.keys(): - assert isinstance(key, str) - - # QAPISourceInfo - assert isinstance(expr_elem['info'], QAPISourceInfo) - info: QAPISourceInfo = expr_elem['info'] - - # Optional[QAPIDoc] - tmp = expr_elem.get('doc') - assert tmp is None or isinstance(tmp, QAPIDoc) - doc: Optional[QAPIDoc] = tmp - + for expr in exprs: for kind in ExpressionType: - if kind in expr: + if kind in expr.expr: meta = kind break else: - raise QAPISemError(info, "expression is missing metatype") + raise QAPISemError(expr.info, "expression is missing metatype") if meta == ExpressionType.INCLUDE: continue - name = 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 = 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) - if doc: - if doc.symbol != 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 != name: + msg = 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") - _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) 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 -Expression = Dict[str, Any] _Value = 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 ParsedExpression(NamedTuple): + expr: 'OrderedDict[str, object]' + info: QAPISourceInfo + doc: Optional['QAPIDoc'] + + class QAPIParseError(QAPISourceError): """Error class for all QAPI schema parsing errors.""" T = TypeVar('T', bound='QAPIParseError') @@ -87,7 +91,7 @@ def __init__(self, self.line_pos = 0 # Parser output: - self.exprs: List[Expression] = [] + self.exprs: List[ParsedExpression] = [] self.docs: List[QAPIDoc] = [] # Showtime! @@ -139,8 +143,7 @@ def _parse(self) -> None: "value of 'include' must be a string") incl_fname = 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 = 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 = {'expr': expr, - 'info': info} - if cur_doc: - if not cur_doc.symbol: - raise QAPISemError( - cur_doc.info, "definition documentation required") - expr_elem['doc'] = 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 = None self.reject_expr_doc(cur_doc) def _parse_error(self, msg: str) -> QAPIParseError: return QAPIParseError.make(self, msg) + def _add_expr(self, expr: 'OrderedDict[str, object]', + info: QAPISourceInfo, + doc: Optional['QAPIDoc'] = 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): def _def_exprs(self, exprs): for expr_elem in exprs: - expr = expr_elem['expr'] - info = expr_elem['info'] - doc = expr_elem.get('doc') + expr = expr_elem.expr + info = expr_elem.info + doc = expr_elem.doc if 'enum' in expr: self._def_enum_type(expr, info, doc) elif 'struct' in expr: From patchwork Tue Sep 22 22:35:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304684 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4DA3C2D0E2 for ; Tue, 22 Sep 2020 22:46:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5418C20757 for ; Tue, 22 Sep 2020 22:46:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="AjQjGqgH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5418C20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr3G-0002NF-Be for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:46:22 -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 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= 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 X-MC-Unique: qoncvMnvPzWAb5OZd-7p_A-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- 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=too-few-public-methods + + def __init__(self) -> None: + # Are documentation comments required? + self.doc_required = False + # Whitelist of commands allowed to return a non-dictionary + self.returns_whitelist: List[str] = [] + # Whitelist of entities allowed to violate case conventions + self.name_case_whitelist: List[str] = [] 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 @@ import copy import sys -from typing import List, Optional, TypeVar +from typing import Optional, TypeVar - -class QAPISchemaPragma: - # Replace with @dataclass in Python 3.7+ - # pylint: disable=too-few-public-methods - - def __init__(self) -> None: - # Are documentation comments required? - self.doc_required = False - # Whitelist of commands allowed to return a non-dictionary - self.returns_whitelist: List[str] = [] - # Whitelist of entities allowed to violate case conventions - self.name_case_whitelist: List[str] = [] +from .pragma import QAPISchemaPragma class QAPISourceInfo: From patchwork Tue Sep 22 22:35:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A34D5C2D0E2 for ; Tue, 22 Sep 2020 22:41:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C73A2076E for ; Tue, 22 Sep 2020 22:41:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="daCcEvv4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C73A2076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqyn-0004aw-ES for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:41:45 -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 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= 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 X-MC-Unique: Fnyoah9MMr6hkkOa34iVPg-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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_CHECKING to avoid this cycle at runtime. pylint dislikes this cycle still, but it can be safely ignored. Signed-off-by: John Snow --- 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. -from typing import Optional +from typing import Optional, TYPE_CHECKING -from .source import QAPISourceInfo +if TYPE_CHECKING: + # pylint: disable=cyclic-import + from .source import QAPISourceInfo 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] = 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, ) from .error import QAPIError, QAPISourceError, QAPISemError +from .pragma import PragmaError from .source import QAPISourceInfo @@ -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) != 1: - raise QAPISemError(info, "invalid 'pragma' directive") - pragma = 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, return QAPISchemaParser(incl_fname, previously_included, info) - @classmethod - def _pragma(cls, - name: str, - value: object, - info: QAPISourceInfo) -> None: - if name == 'doc-required': - if not isinstance(value, bool): - raise QAPISemError(info, - "pragma 'doc-required' must be boolean") - info.pragma.doc_required = value - elif name == '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 = cast(List[str], value) - elif name == '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 = cast(List[str], value) - else: - raise QAPISemError(info, "unknown pragma '%s'" % name) - def accept(self, skip_comment: bool = 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. -from typing import List +from typing import Mapping, Sequence + +from .error import QAPIError + + +class PragmaError(QAPIError): + """For errors relating to Pragma validation.""" class QAPISchemaPragma: - # Replace with @dataclass in Python 3.7+ - # pylint: disable=too-few-public-methods - def __init__(self) -> None: # Are documentation comments required? self.doc_required = False # Whitelist of commands allowed to return a non-dictionary - self.returns_whitelist: List[str] = [] + self.returns_whitelist: Sequence[str] = tuple() # Whitelist of entities allowed to violate case conventions - self.name_case_whitelist: List[str] = [] + self.name_case_whitelist: Sequence[str] = 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 = 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 = 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 = tuple(value) + + def add(self, name: str, value: object) -> None: + if name == 'doc-required': + self._add_doc_required(value) + elif name == 'returns-whitelist': + self._add_returns_whitelist(value) + elif name == '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() != {'pragma'}: + raise PragmaError("invalid 'pragma' directive") + + body = 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) From patchwork Tue Sep 22 22:35:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0126C4727D for ; Tue, 22 Sep 2020 22:39:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 764C020715 for ; Tue, 22 Sep 2020 22:39:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DvQo5PIV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 764C020715 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKqwK-00017x-EV for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:39:12 -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 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= 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 X-MC-Unique: tVCcdv-ONGuryEcPGvS1Bg-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" It doesn't need to take quite so many arguments. Signed-off-by: John Snow --- 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 = os.path.join(os.path.dirname(self._fname), include) self._add_expr(OrderedDict({'include': incl_fname}), info) - exprs_include = self._include(include, info, incl_fname, - self._included) + exprs_include = 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) - @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 = os.path.abspath(incl_fname) + # catch inclusion cycle - inf = info + inf = self.info while inf: if incl_abs_fname == os.path.abspath(inf.fname): - raise QAPISemError(info, "inclusion loop for %s" % include) + raise QAPISemError(self.info, f"inclusion loop for {include}") inf = inf.parent # skip multiple include of the same file - if incl_abs_fname in previously_included: + if incl_abs_fname in self._included: return None - return QAPISchemaParser(incl_fname, previously_included, info) + return QAPISchemaParser(incl_fname, self._included, self.info) def accept(self, skip_comment: bool = True) -> None: """ From patchwork Tue Sep 22 22:35:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3A65C2D0E2 for ; Tue, 22 Sep 2020 22:43:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 57F8B2076E for ; Tue, 22 Sep 2020 22:43:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JiVOknDn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 57F8B2076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:38224 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr0h-00082Z-GG for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:43:43 -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 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= 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 X-MC-Unique: bE5mKJEqNAyELENuwlOvsw-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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. - :param fname: Path to the source file - :param previously_included: Set of absolute paths of previously included - source files; these will not be parsed again. - :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]] = None, - incl_info: Optional[QAPISourceInfo] = None): + def __init__(self, fname: str, + parent: Optional['QAPISchemaParser'] = None): self._fname = fname - self._included = previously_included or set() + self._included: Set[str] = parent._included if parent else set() self._included.add(os.path.abspath(self._fname)) + parent_info = parent.info if parent else None # Lexer state (see `accept` for details): self.tok: Optional[str] = None self.pos = 0 self.cursor = 0 self.val: Optional[Union[bool, str]] = None - self.info = QAPISourceInfo(self._fname, parent=incl_info) + self.info: QAPISourceInfo = QAPISourceInfo(self._fname, + parent=parent_info) self.line_pos = 0 # Parser output: @@ -100,11 +97,11 @@ def __init__(self, self.src = fp.read() except IOError as e: msg = "can't read {kind:s} file '{fname:s}': {errmsg:s}".format( - kind='include' if incl_info else 'schema', + kind='include' if parent else 'schema', fname=self._fname, errmsg=e.strerror ) - context = incl_info or self.info + context = parent_info if parent_info else self.info raise QAPIParseError(context, msg) from e self._parse() @@ -193,7 +190,7 @@ def _include(self, include: str, if incl_abs_fname in self._included: return None - return QAPISchemaParser(incl_fname, self._included, self.info) + return QAPISchemaParser(incl_fname, self) def accept(self, skip_comment: bool = True) -> None: """ From patchwork Tue Sep 22 22:35:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 273001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91D54C4727D for ; Tue, 22 Sep 2020 22:53:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2F9BB221EB for ; Tue, 22 Sep 2020 22:53:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Gn9YRUNf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2F9BB221EB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41772 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr9n-0004fj-9f for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:53:07 -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 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= 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 X-MC-Unique: t_6_dx9LNHeMdm01u6WcNg-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- 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): def check(self): - def check_args_section(args, info, what): + def check_args_section(args): bogus = [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")) - 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) From patchwork Tue Sep 22 22:35:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304680 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 815CBC2D0E2 for ; Tue, 22 Sep 2020 22:50:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 210CC2076E for ; Tue, 22 Sep 2020 22:50:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="B/utQhLW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 210CC2076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:32932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr7D-0000vS-5z for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:50:27 -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 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= 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 X-MC-Unique: nRuRPSIPNPe_oQlPSRhQtw-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" For consistency: replace @staticmethod with @classmethod. Signed-off-by: John Snow --- 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() - @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:', From patchwork Tue Sep 22 22:35:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304675 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C777DC2D0E2 for ; Tue, 22 Sep 2020 22:57:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 62E49221EB for ; Tue, 22 Sep 2020 22:57:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HGyAxBzk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62E49221EB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:58080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKrDq-0003AA-8D for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:57:18 -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 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= 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 X-MC-Unique: m6u-WVRzOamqY5d7gc5sxA-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Annotations do not change runtime behavior. This commit *only* adds annotations. Signed-off-by: John Snow --- 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 +if TYPE_CHECKING: + # pylint: disable=cyclic-import + from .schema import QAPISchemaMember, QAPISchemaFeature + _Value = Union[List[object], 'OrderedDict[str, object]', str, bool] # Necessary imprecision: mypy does not (yet?) support recursive types; @@ -405,43 +410,43 @@ class QAPIDoc: """ class Section: - def __init__(self, name=None): + def __init__(self, name: Optional[str] = None): # optional section name (argument/member or section name) self.name = name self.text = '' - def append(self, line): + def append(self, line: str) -> None: self.text += line.rstrip() + '\n' class ArgSection(Section): - def __init__(self, name): + def __init__(self, name: Optional[str] = None): super().__init__(name) - self.member = None + self.member: Optional['QAPISchemaMember'] = None - def connect(self, member): + def connect(self, member: 'QAPISchemaMember') -> None: self.member = member - def __init__(self, info): + def __init__(self, info: QAPISourceInfo): self.info = info - self.symbol = None + self.symbol: Optional[str] = None self.body = QAPIDoc.Section() # dict mapping parameter name to ArgSection - self.args = OrderedDict() - self.features = OrderedDict() + self.args: 'OrderedDict[str, QAPIDoc.ArgSection]' = OrderedDict() + self.features: 'OrderedDict[str, QAPIDoc.ArgSection]' = OrderedDict() # a list of Section - self.sections = [] + self.sections: List[QAPIDoc.Section] = [] # the current section self._section = self.body self._append_line = self._append_body_line - 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 == name: return True return False - def append(self, line): + def append(self, line: str) -> None: """ Parse a comment line and add it to the documentation. @@ -462,18 +467,18 @@ def append(self, line): line = line[1:] self._append_line(line) - def end_comment(self): + def end_comment(self) -> None: self._end_section() @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:') - def _append_body_line(self, line): + def _append_body_line(self, line: str) -> None: """ Process a line of documentation text in the body section. @@ -513,7 +518,7 @@ def _append_body_line(self, line): # This is a free-form documentation block self._append_freeform(line.strip()) - def _append_args_line(self, line): + def _append_args_line(self, line: str) -> None: """ Process a line of documentation text in an argument section. @@ -546,7 +551,7 @@ def _append_args_line(self, line): self._append_freeform(line.strip()) - def _append_features_line(self, line): + def _append_features_line(self, line: str) -> None: name = line.split(' ', 1)[0] if name.startswith('@') and name.endswith(':'): @@ -565,7 +570,7 @@ def _append_features_line(self, line): self._append_freeform(line.strip()) - def _append_various_line(self, line): + def _append_various_line(self, line: str) -> None: """ Process a line of documentation text in an additional section. @@ -591,7 +596,10 @@ def _append_various_line(self, line): self._append_freeform(line) - 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 = QAPIDoc.ArgSection(name) symbols_dict[name] = self._section - def _start_args_section(self, name): + def _start_args_section(self, name: str) -> None: self._start_symbol_section(self.args, name) - def _start_features_section(self, name): + def _start_features_section(self, name: str) -> None: self._start_symbol_section(self.features, name) - def _start_section(self, name=None): + def _start_section(self, name: Optional[str] = None) -> None: if name in ('Returns', 'Since') and self.has_section(name): raise QAPIDocError("duplicated '%s' section" % name) self._end_section() self._section = QAPIDoc.Section(name) self.sections.append(self._section) - def _end_section(self): + def _end_section(self) -> None: if self._section: text = self._section.text = 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 = None - def _append_freeform(self, line): + def _append_freeform(self, line: str) -> None: match = re.match(r'(@\S+:)', line) if match: raise QAPIDocError("'%s' not allowed in free-form documentation" % match.group(1)) self._section.append(line) - 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] = QAPIDoc.ArgSection(member.name) self.args[member.name].connect(member) - 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) - 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") - def check(self): - - def check_args_section(args): + def check(self) -> None: + def check_args_section( + args: 'OrderedDict[str, QAPIDoc.ArgSection]') -> None: bogus = [name for name, section in args.items() if not section.member] if bogus: From patchwork Tue Sep 22 22:35:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5FD4C4727D for ; Tue, 22 Sep 2020 22:46:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 74D3E20757 for ; Tue, 22 Sep 2020 22:46:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Pk0h6liS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 74D3E20757 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr3M-0002c2-Da for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:46:28 -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 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= 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 X-MC-Unique: MqNzN1qPNFy4sqVOKYK4Ig-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- 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 = False disallow_untyped_calls = False python_version = 3.6 -[mypy-qapi.parser] -disallow_untyped_defs = False -disallow_incomplete_defs = False -check_untyped_defs = False - [mypy-qapi.schema] disallow_untyped_defs = False disallow_incomplete_defs = False From patchwork Tue Sep 22 22:35:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14F74C4727D for ; Tue, 22 Sep 2020 22:52:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9817820BED for ; Tue, 22 Sep 2020 22:52:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NYTx7AtL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9817820BED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr9c-0004VF-NX for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:52:56 -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 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= 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 X-MC-Unique: F9Ea86SHNA-hTURJuKKVDg-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Standard pylint complaint: use more descriptibe variable names. OK, fine. Signed-off-by: John Snow --- 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 = 1 - for ch in parser.src[parser.line_pos:parser.pos]: - if ch == '\t': + for char in parser.src[parser.line_pos:parser.pos]: + if char == '\t': col = (col + 7) % 8 + 1 else: col += 1 @@ -100,14 +100,16 @@ def __init__(self, fname: str, try: with open(self._fname, 'r', encoding='utf-8') as fp: self.src = fp.read() - except IOError as e: + except IOError as err: msg = "can't read {kind:s} file '{fname:s}': {errmsg:s}".format( kind='include' if parent else 'schema', fname=self._fname, - errmsg=e.strerror + errmsg=err.strerror ) context = parent_info if parent_info else self.info - raise QAPIParseError(context, msg) from e + raise QAPIParseError(context, msg) from err + + # Showtime! self._parse() def _parse(self) -> None: @@ -245,25 +247,25 @@ def accept(self, skip_comment: bool = True) -> None: string = '' esc = False while True: - ch = self.src[self.cursor] + char = self.src[self.cursor] self.cursor += 1 - if ch == '\n': + if char == '\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 != '\\': - raise self._parse_error(f"unknown escape \\{ch}") + if char != '\\': + raise self._parse_error(f"unknown escape \\{char}") esc = False - elif ch == '\\': + elif char == '\\': esc = True continue - elif ch == "'": + elif char == "'": self.val = string return - if ord(ch) < 32 or ord(ch) >= 127: + if ord(char) < 32 or ord(char) >= 127: raise self._parse_error("funny character in string") - string += ch + string += char elif self.src.startswith('true', self.pos): self.val = True self.cursor += 3 From patchwork Tue Sep 22 22:35:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B8A6C4727E for ; Tue, 22 Sep 2020 22:48:40 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 825812076E for ; Tue, 22 Sep 2020 22:48:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NGpiFrkk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 825812076E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:53318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKr5S-00065v-Ku for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:48:38 -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 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= 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 X-MC-Unique: cEP2jUunMc2u1MOPE76Caw-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- 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: """ class Section: + # pylint: disable=too-few-public-methods + def __init__(self, name: Optional[str] = None): # optional section name (argument/member or section name) self.name = name From patchwork Tue Sep 22 22:35:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 304677 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4E95C2D0E2 for ; Tue, 22 Sep 2020 22:55:02 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 05E6920BED for ; Tue, 22 Sep 2020 22:55:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="QbZVeWks" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 05E6920BED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:49626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kKrBd-0007xn-0B for qemu-devel@archiver.kernel.org; Tue, 22 Sep 2020 18:55:01 -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 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= 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 X-MC-Unique: pdXStFfbP4i-uxXZyf8AeA-1 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) 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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- 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 @@ # Add files or directories matching the regex patterns to the ignore list. # The regex matches against base names, not paths. -ignore-patterns=parser.py, - schema.py, +ignore-patterns=schema.py, [MESSAGES CONTROL]