From patchwork Wed Apr 21 19:22:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1468821 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RuR2/lu8; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQVpC4KnKz9sWD for ; Thu, 22 Apr 2021 05:23:30 +1000 (AEST) Received: from localhost ([::1]:44142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZIRb-0003iP-Qx for incoming@patchwork.ozlabs.org; Wed, 21 Apr 2021 15:23:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQu-0003eG-KP for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49944) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQr-0005Wa-QR for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619032960; 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=dBDmtrRvyGaqpX9R6oNckztnlUNPJGk6TWXJdfpggVY=; b=RuR2/lu8z9S8m5G7rCWVCNDqIaKgbmEMr9Sc2enuUFaxy1rf7q0rOvZQvoUf0HB71ytgm/ mcDOZqX55Foa1UVKfZoXj0RBP+C2FZNtLE8q2UKGMICtIAfv3WE/J2OK4ZeOmod+qH2cbd AohRIerLmNs7INcqh88xQsNS6d1cXfQ= 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-600-7_531YaQMPigIlyk-TdHyg-1; Wed, 21 Apr 2021 15:22:36 -0400 X-MC-Unique: 7_531YaQMPigIlyk-TdHyg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CA57E87A826; Wed, 21 Apr 2021 19:22:35 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-152.rdu2.redhat.com [10.10.118.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3B375C1B4; Wed, 21 Apr 2021 19:22:34 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v3 1/8] qapi/error: Repurpose QAPIError as an abstract base exception class Date: Wed, 21 Apr 2021 15:22:26 -0400 Message-Id: <20210421192233.3542904-2-jsnow@redhat.com> In-Reply-To: <20210421192233.3542904-1-jsnow@redhat.com> References: <20210421192233.3542904-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , John Snow , Eduardo Habkost , Michael Roth , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Rename QAPIError to QAPISourceError, and then create a new QAPIError class that serves as the basis for all of our other custom exceptions, without specifying any class properties. This leaves QAPIError as a package-wide error class that's suitable for any current or future errors. (Right now, we don't have any errors that DON'T also want to specify a Source location, but this MAY change. In these cases, a common abstract ancestor would be desired.) Add docstrings to explain the intended function of each error class. Signed-off-by: John Snow --- docs/sphinx/qapidoc.py | 3 ++- scripts/qapi/error.py | 11 +++++++++-- scripts/qapi/schema.py | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/sphinx/qapidoc.py b/docs/sphinx/qapidoc.py index b7a2d39c105..87c67ab23f8 100644 --- a/docs/sphinx/qapidoc.py +++ b/docs/sphinx/qapidoc.py @@ -34,7 +34,8 @@ from sphinx.util.nodes import nested_parse_with_titles import sphinx from qapi.gen import QAPISchemaVisitor -from qapi.schema import QAPIError, QAPISemError, QAPISchema +from qapi.error import QAPIError, QAPISemError +from qapi.schema import QAPISchema # Sphinx up to 1.6 uses AutodocReporter; 1.7 and later diff --git a/scripts/qapi/error.py b/scripts/qapi/error.py index ae60d9e2fe8..126dda7c9b2 100644 --- a/scripts/qapi/error.py +++ b/scripts/qapi/error.py @@ -13,6 +13,11 @@ class QAPIError(Exception): + """Base class for all exceptions from the QAPI package.""" + + +class QAPISourceError(QAPIError): + """Error class for all exceptions identifying a source location.""" def __init__(self, info, col, msg): Exception.__init__(self) self.info = info @@ -27,7 +32,8 @@ def __str__(self): return loc + ': ' + self.msg -class QAPIParseError(QAPIError): +class QAPIParseError(QAPISourceError): + """Error class for all QAPI schema parsing errors.""" def __init__(self, parser, msg): col = 1 for ch in parser.src[parser.line_pos:parser.pos]: @@ -38,6 +44,7 @@ def __init__(self, parser, msg): super().__init__(parser.info, col, msg) -class QAPISemError(QAPIError): +class QAPISemError(QAPISourceError): + """Error class for semantic QAPI errors.""" def __init__(self, info, msg): super().__init__(info, None, msg) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index 703b446fd21..c277fcacc53 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -20,7 +20,7 @@ from typing import Optional from .common import POINTER_SUFFIX, c_name -from .error import QAPIError, QAPISemError +from .error import QAPISemError, QAPISourceError from .expr import check_exprs from .parser import QAPISchemaParser @@ -875,7 +875,8 @@ def _def_entity(self, ent): other_ent = self._entity_dict.get(ent.name) if other_ent: if other_ent.info: - where = QAPIError(other_ent.info, None, "previous definition") + where = QAPISourceError(other_ent.info, None, + "previous definition") raise QAPISemError( ent.info, "'%s' is already defined\n%s" % (ent.name, where)) From patchwork Wed Apr 21 19:22:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1468820 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Pkfsk48p; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQVpC2yPjz9sVw for ; Thu, 22 Apr 2021 05:23:30 +1000 (AEST) Received: from localhost ([::1]:44122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZIRb-0003hm-81 for incoming@patchwork.ozlabs.org; Wed, 21 Apr 2021 15:23:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQu-0003fi-Oo for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47917) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQq-0005VI-Rh for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619032959; 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=99DEEllPzNQalb3WGQwj/ArABxJ3NhtgsKM35wwXMSk=; b=Pkfsk48pcL1n0Ftu6k1FGfzCAzR7PB2gUDOZ6eOotMeTGU0sw9/hU32fs2XxBkoObsL6iS 0uEJX73wx5kFDfQjEco9XW0L8m9q75/qBCmlWxr2HyZa/5TG1jP8gQgXeGmcKw+DIwdLuW xoxifm6ArSkKDCeIN9/ICWZtJhRSkQk= 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-401-8yYztLoyOwqS3FGY3kwORA-1; Wed, 21 Apr 2021 15:22:37 -0400 X-MC-Unique: 8yYztLoyOwqS3FGY3kwORA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C1E1C801983; Wed, 21 Apr 2021 19:22:36 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-152.rdu2.redhat.com [10.10.118.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id F18F85C1B4; Wed, 21 Apr 2021 19:22:35 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v3 2/8] qapi/error: Use Python3-style super() Date: Wed, 21 Apr 2021 15:22:27 -0400 Message-Id: <20210421192233.3542904-3-jsnow@redhat.com> In-Reply-To: <20210421192233.3542904-1-jsnow@redhat.com> References: <20210421192233.3542904-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , John Snow , Eduardo Habkost , Michael Roth , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Missed in commit 2cae67bcb5 "qapi: Use super() now we have Python 3". Signed-off-by: John Snow Reviewed-by: Markus Armbruster --- scripts/qapi/error.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qapi/error.py b/scripts/qapi/error.py index 126dda7c9b2..38bd7c4dd6a 100644 --- a/scripts/qapi/error.py +++ b/scripts/qapi/error.py @@ -19,7 +19,7 @@ class QAPIError(Exception): class QAPISourceError(QAPIError): """Error class for all exceptions identifying a source location.""" def __init__(self, info, col, msg): - Exception.__init__(self) + super().__init__() self.info = info self.col = col self.msg = msg From patchwork Wed Apr 21 19:22:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1468823 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KV/wr8ot; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQVsP2MpTz9sVw for ; Thu, 22 Apr 2021 05:26:17 +1000 (AEST) Received: from localhost ([::1]:52576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZIUJ-0007Cd-AR for incoming@patchwork.ozlabs.org; Wed, 21 Apr 2021 15:26:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42926) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQw-0003hu-2Q for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24007) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQr-0005Wg-Tn for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619032961; 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=oNjYbJmAWqqsSY03QnHmyUPUGm5MRQ02Y2/NtVK6rIg=; b=KV/wr8otm0Xs3m4+pPdz27ElCR8YGh8sKvo2n5ZjnRO5B0YHmVvNMMEq7jWKzbpsjIX9zI qrndx2bpEAy8AkZ40zS3/VNE3Qhk4+i8lTVpmblpwHTgv+qJaa4EMrL2BlXNrGYS3QguaL tNNT7ZhtCAoaOxTBpsoviqwp4lPDwtQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-565-zMb1oKDsPAWXXj-mx50pYw-1; Wed, 21 Apr 2021 15:22:38 -0400 X-MC-Unique: zMb1oKDsPAWXXj-mx50pYw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B8094107ACCA; Wed, 21 Apr 2021 19:22:37 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-152.rdu2.redhat.com [10.10.118.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8D395C1B4; Wed, 21 Apr 2021 19:22:36 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v3 3/8] qapi/error: Make QAPISourceError 'col' parameter optional Date: Wed, 21 Apr 2021 15:22:28 -0400 Message-Id: <20210421192233.3542904-4-jsnow@redhat.com> In-Reply-To: <20210421192233.3542904-1-jsnow@redhat.com> References: <20210421192233.3542904-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , John Snow , Eduardo Habkost , Michael Roth , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" It's already treated as optional, with one direct caller and some subclass callers passing 'None'. Make it officially optional, which requires moving the position of the argument to come after all required parameters. QAPISemError becomes functionally identical to QAPISourceError. Keep the name to preserve its semantic meaning and avoid code churn, but remove the now-useless __init__ wrapper. Signed-off-by: John Snow --- scripts/qapi/error.py | 8 +++----- scripts/qapi/schema.py | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/scripts/qapi/error.py b/scripts/qapi/error.py index 38bd7c4dd6a..d179a3bd0c7 100644 --- a/scripts/qapi/error.py +++ b/scripts/qapi/error.py @@ -18,11 +18,11 @@ class QAPIError(Exception): class QAPISourceError(QAPIError): """Error class for all exceptions identifying a source location.""" - def __init__(self, info, col, msg): + def __init__(self, info, msg, col=None): super().__init__() self.info = info - self.col = col self.msg = msg + self.col = col def __str__(self): loc = str(self.info) @@ -41,10 +41,8 @@ def __init__(self, parser, msg): col = (col + 7) % 8 + 1 else: col += 1 - super().__init__(parser.info, col, msg) + super().__init__(parser.info, msg, col) class QAPISemError(QAPISourceError): """Error class for semantic QAPI errors.""" - def __init__(self, info, msg): - super().__init__(info, None, msg) diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py index c277fcacc53..3a4172fb749 100644 --- a/scripts/qapi/schema.py +++ b/scripts/qapi/schema.py @@ -875,8 +875,7 @@ def _def_entity(self, ent): other_ent = self._entity_dict.get(ent.name) if other_ent: if other_ent.info: - where = QAPISourceError(other_ent.info, None, - "previous definition") + where = QAPISourceError(other_ent.info, "previous definition") raise QAPISemError( ent.info, "'%s' is already defined\n%s" % (ent.name, where)) From patchwork Wed Apr 21 19:22:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1468827 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ddft+qdU; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQVwv1QRCz9sWD for ; Thu, 22 Apr 2021 05:29:18 +1000 (AEST) Received: from localhost ([::1]:32978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZIXD-0002Eo-K1 for incoming@patchwork.ozlabs.org; Wed, 21 Apr 2021 15:29:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIR3-0003yk-KQ for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43747) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIR1-0005dL-TB for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619032971; 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=O1UFhIcIO1sB0rYOq17pQK4R3ILF1OU6LlNmhkawpmk=; b=Ddft+qdURdtAn5dyon9fVxB4DPKVmJrcsueOTZ2m67sdjpbhECbc2KdaKxjNwvk5+5PcE3 Y3nm+GD6bzIHsAZ2RX2iDKXcLgPuRRv4hx30AuQl1HaK9cQj4eJLedHxP6WcHBnDrhnj9P K5BeCJGnep5h/YuxZmBL/R9+s1/6APg= 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-585-37xIrnzTPS2564t1Q9xF3w-1; Wed, 21 Apr 2021 15:22:39 -0400 X-MC-Unique: 37xIrnzTPS2564t1Q9xF3w-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B230780432C; Wed, 21 Apr 2021 19:22:38 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-152.rdu2.redhat.com [10.10.118.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDBD25C1D5; Wed, 21 Apr 2021 19:22:37 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v3 4/8] qapi/error: assert QAPISourceInfo is not None Date: Wed, 21 Apr 2021 15:22:29 -0400 Message-Id: <20210421192233.3542904-5-jsnow@redhat.com> In-Reply-To: <20210421192233.3542904-1-jsnow@redhat.com> References: <20210421192233.3542904-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , John Snow , Eduardo Habkost , Michael Roth , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Built-in stuff is not parsed from a source file, and therefore have no QAPISourceInfo. If such None info was used for reporting an error, built-in stuff would be broken. Programming error. Instead of reporting a confusing error with bogus source location then, we better crash. We currently crash only if self.col was set. Assert that self.info is not None in order to crash reliably. We can not yet change the type of the initializer to prove this cannot happen at static analysis time before the remainder of the code is fully typed. Signed-off-by: John Snow --- scripts/qapi/error.py | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/qapi/error.py b/scripts/qapi/error.py index d179a3bd0c7..d0bc7af6e76 100644 --- a/scripts/qapi/error.py +++ b/scripts/qapi/error.py @@ -25,6 +25,7 @@ def __init__(self, info, msg, col=None): self.col = col def __str__(self): + assert self.info is not None loc = str(self.info) if self.col is not None: assert self.info.line is not None From patchwork Wed Apr 21 19:22:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1468824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VWjsgDsM; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQVsT07nMz9sVw for ; Thu, 22 Apr 2021 05:26:21 +1000 (AEST) Received: from localhost ([::1]:52740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZIUN-0007Hz-1k for incoming@patchwork.ozlabs.org; Wed, 21 Apr 2021 15:26:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQz-0003ql-SS for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQy-0005aZ-1h for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619032967; 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=EW3Kri7fJM7UoCzllKDsdwY/tpGuX1B83+UwKw9TpzE=; b=VWjsgDsMXImVm3ilz6qfSLn/QsjKZ1TooWaPwBOhoZOM0DsnvNRmr61UYXCBiXnPkvz4W0 8fKY9yQiaXU7FCYjrYvgrmdrKaFDSXwwKV/sBpS8IVbQM8G/1lr05XwegdzzGqPuE4VMdX jqixSicnZDmwhxZ3Z4NZELkxD0qqE5E= 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-557-m5HAR9SqMNuEen7JqLG_ug-1; Wed, 21 Apr 2021 15:22:40 -0400 X-MC-Unique: m5HAR9SqMNuEen7JqLG_ug-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A780B87A83C; Wed, 21 Apr 2021 19:22:39 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-152.rdu2.redhat.com [10.10.118.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id D88BA5C1B4; Wed, 21 Apr 2021 19:22:38 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v3 5/8] qapi/error.py: move QAPIParseError to parser.py Date: Wed, 21 Apr 2021 15:22:30 -0400 Message-Id: <20210421192233.3542904-6-jsnow@redhat.com> In-Reply-To: <20210421192233.3542904-1-jsnow@redhat.com> References: <20210421192233.3542904-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , John Snow , Eduardo Habkost , Michael Roth , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Keeping it in error.py will create some cyclic import problems when we add types to the QAPISchemaParser. Callers don't need to know the details of QAPIParseError unless they are parsing or dealing directly with the parser, so this won't create any harsh new requirements for callers in the general case. Update error.py with a little docstring that gives a nod to where the error may now be found. Signed-off-by: John Snow --- scripts/qapi/error.py | 22 ++++++++-------------- scripts/qapi/parser.py | 14 +++++++++++++- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/scripts/qapi/error.py b/scripts/qapi/error.py index d0bc7af6e76..6723c5a9d9a 100644 --- a/scripts/qapi/error.py +++ b/scripts/qapi/error.py @@ -1,7 +1,5 @@ # -*- coding: utf-8 -*- # -# QAPI error classes -# # Copyright (c) 2017-2019 Red Hat Inc. # # Authors: @@ -11,6 +9,14 @@ # This work is licensed under the terms of the GNU GPL, version 2. # See the COPYING file in the top-level directory. +""" +QAPI error classes + +Common error classes used throughout the package. Additional errors may +be defined in other modules. At present, `QAPIParseError` is defined in +parser.py. +""" + class QAPIError(Exception): """Base class for all exceptions from the QAPI package.""" @@ -33,17 +39,5 @@ def __str__(self): return loc + ': ' + self.msg -class QAPIParseError(QAPISourceError): - """Error class for all QAPI schema parsing errors.""" - def __init__(self, parser, msg): - col = 1 - for ch in parser.src[parser.line_pos:parser.pos]: - if ch == '\t': - col = (col + 7) % 8 + 1 - else: - col += 1 - super().__init__(parser.info, msg, col) - - class QAPISemError(QAPISourceError): """Error class for semantic QAPI errors.""" diff --git a/scripts/qapi/parser.py b/scripts/qapi/parser.py index 58267c3db9e..ca5e8e18e00 100644 --- a/scripts/qapi/parser.py +++ b/scripts/qapi/parser.py @@ -18,10 +18,22 @@ import os import re -from .error import QAPIParseError, QAPISemError +from .error import QAPISemError, QAPISourceError from .source import QAPISourceInfo +class QAPIParseError(QAPISourceError): + """Error class for all QAPI schema parsing errors.""" + def __init__(self, parser, msg): + col = 1 + for ch in parser.src[parser.line_pos:parser.pos]: + if ch == '\t': + col = (col + 7) % 8 + 1 + else: + col += 1 + super().__init__(parser.info, msg, col) + + class QAPISchemaParser: def __init__(self, fname, previously_included=None, incl_info=None): From patchwork Wed Apr 21 19:22:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1468822 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KnyVHmGo; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQVs36yDkz9sVw for ; Thu, 22 Apr 2021 05:25:59 +1000 (AEST) Received: from localhost ([::1]:51806 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZIU1-0006tg-R8 for incoming@patchwork.ozlabs.org; Wed, 21 Apr 2021 15:25:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQw-0003j0-JX for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51241) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQv-0005Yw-3F for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619032964; 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=1HZ54izTjiISS10lHuMMPhWPYTcoMyywaeGobK3r3Nw=; b=KnyVHmGoMkd6HuqsNseq5jevm1zdmpE2+Y7MjFcjM+UfAUimNom94dJhOzTi0ZazpnWDrg aloAWTz2qhr1U6YdiEAJREEyLsAcN0g+fe0jnMRtiQLCIlsgw965ipxoi77J6aai5RWjqQ CnWm1g2Ew3uCSxNrTZdIfA1ImTJK8Vk= 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-141-ktbQ7b1ePGmup3oDaM57Lw-1; Wed, 21 Apr 2021 15:22:41 -0400 X-MC-Unique: ktbQ7b1ePGmup3oDaM57Lw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9DBEB189829A; Wed, 21 Apr 2021 19:22:40 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-152.rdu2.redhat.com [10.10.118.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0CC75C1B4; Wed, 21 Apr 2021 19:22:39 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v3 6/8] qapi/error.py: enable pylint checks Date: Wed, 21 Apr 2021 15:22:31 -0400 Message-Id: <20210421192233.3542904-7-jsnow@redhat.com> In-Reply-To: <20210421192233.3542904-1-jsnow@redhat.com> References: <20210421192233.3542904-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=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-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , John Snow , Eduardo Habkost , Michael Roth , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.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 fb0386d529a..88efbf71cb2 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=error.py, - parser.py, +ignore-patterns=parser.py, schema.py, From patchwork Wed Apr 21 19:22:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1468828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=UclIVKY0; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQW0B1M3yz9sVw for ; Thu, 22 Apr 2021 05:32:10 +1000 (AEST) Received: from localhost ([::1]:40096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZIa0-0005Eb-4k for incoming@patchwork.ozlabs.org; Wed, 21 Apr 2021 15:32:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42986) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIR5-00041l-1e for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34425) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIR1-0005dW-WC for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619032971; 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=7B7hkrDfVXmz2SvFNkwRPgkbsX8rXgk8lpQh6GeMUkk=; b=UclIVKY0OQ2Lk4IL+dLQFV1qlfvAD/b5DSUYS0xtqcMyZB4iZGKpAN4SeqEinZZiqPzf6i oCQLabTWrEmmb3S911spJKe6ne70aunJR521hNCkvnaOF/hAAXrUTavQVF1bKaLkFbQUZ7 LBWW0m9xPpU5mcQVfnuiVOXpz3Xr+jw= 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-136-cux0jnaGMqG3Fkf-shKeKg-1; Wed, 21 Apr 2021 15:22:42 -0400 X-MC-Unique: cux0jnaGMqG3Fkf-shKeKg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 929B11020C20; Wed, 21 Apr 2021 19:22:41 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-152.rdu2.redhat.com [10.10.118.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id C43A35C1B4; Wed, 21 Apr 2021 19:22:40 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v3 7/8] qapi/error: Add type hints Date: Wed, 21 Apr 2021 15:22:32 -0400 Message-Id: <20210421192233.3542904-8-jsnow@redhat.com> In-Reply-To: <20210421192233.3542904-1-jsnow@redhat.com> References: <20210421192233.3542904-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , John Snow , Eduardo Habkost , Michael Roth , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" No functional change. Note: QAPISourceError's info parameter is Optional[] because schema.py treats the info property of its various classes as Optional to accommodate built-in types, which have no source. See prior commit 'qapi/error: assert QAPISourceInfo is not None'. Signed-off-by: John Snow --- Random aside: It may appear clunky to have to type __str__, but after I mentioned it on the Python typing SIG list, it was noted that this is actually one of very few magic methods that has a "known" type in advance, so there wasn't much desire to special case the typing for it. Signed-off-by: John Snow --- scripts/qapi/error.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/qapi/error.py b/scripts/qapi/error.py index 6723c5a9d9a..e35e4ddb26a 100644 --- a/scripts/qapi/error.py +++ b/scripts/qapi/error.py @@ -17,6 +17,10 @@ parser.py. """ +from typing import Optional + +from .source import QAPISourceInfo + class QAPIError(Exception): """Base class for all exceptions from the QAPI package.""" @@ -24,13 +28,16 @@ class QAPIError(Exception): class QAPISourceError(QAPIError): """Error class for all exceptions identifying a source location.""" - def __init__(self, info, msg, col=None): + def __init__(self, + info: Optional[QAPISourceInfo], + msg: str, + col: Optional[int] = None): super().__init__() self.info = info self.msg = msg self.col = col - def __str__(self): + def __str__(self) -> str: assert self.info is not None loc = str(self.info) if self.col is not None: From patchwork Wed Apr 21 19:22:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1468826 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MqmmrUqm; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FQVwv0vzhz9sVw for ; Thu, 22 Apr 2021 05:29:17 +1000 (AEST) Received: from localhost ([::1]:32944 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lZIXD-0002E4-0d for incoming@patchwork.ozlabs.org; Wed, 21 Apr 2021 15:29:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42954) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQz-0003p5-4Y for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20168) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lZIQw-0005Zb-4f for qemu-devel@nongnu.org; Wed, 21 Apr 2021 15:22:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619032965; 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=puwGCK7mHQMv6KhSjdhQPjq8HPu5ifxXwuatn+/3awE=; b=MqmmrUqmlGl9KutuR5bnlKzTMs0eD5rnfoZrkOCMJH6CTvKFVRI9PEr4i6CiQJhEpwCcFB QrgpGKloHonksgxdzhl9rvKpmoMdZGIphl88J2QLmuaqj571QZMNidrJL5nmuF7gDDO/Jz TEwLXtTBWJ8vJxuCWaOVnqrNus6i2NM= 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-24-p0arvmdaMKGIeIBrfgLlPg-1; Wed, 21 Apr 2021 15:22:43 -0400 X-MC-Unique: p0arvmdaMKGIeIBrfgLlPg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 883EB18982A3; Wed, 21 Apr 2021 19:22:42 +0000 (UTC) Received: from scv.redhat.com (ovpn-118-152.rdu2.redhat.com [10.10.118.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id B986D5C1B4; Wed, 21 Apr 2021 19:22:41 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org, Markus Armbruster Subject: [PATCH v3 8/8] qapi/error.py: enable mypy checks Date: Wed, 21 Apr 2021 15:22:33 -0400 Message-Id: <20210421192233.3542904-9-jsnow@redhat.com> In-Reply-To: <20210421192233.3542904-1-jsnow@redhat.com> References: <20210421192233.3542904-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=jsnow@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , John Snow , Eduardo Habkost , Michael Roth , Cleber Rosa Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: John Snow --- (This can be squashed with the previous commit when staged.) 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 7797c834328..54ca4483d6d 100644 --- a/scripts/qapi/mypy.ini +++ b/scripts/qapi/mypy.ini @@ -3,11 +3,6 @@ strict = True disallow_untyped_calls = False python_version = 3.6 -[mypy-qapi.error] -disallow_untyped_defs = False -disallow_incomplete_defs = False -check_untyped_defs = False - [mypy-qapi.parser] disallow_untyped_defs = False disallow_incomplete_defs = False