From patchwork Thu Feb 1 22:42:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 1894228 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=SMMR08br; dkim-atps=neutral Authentication-Results: legolas.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=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TQvCd5RH5z23h9 for ; Fri, 2 Feb 2024 09:46:37 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVfmA-0006Ia-N5; Thu, 01 Feb 2024 17:43:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVfm8-0006Gg-J2 for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVflp-0006aC-4k for qemu-devel@nongnu.org; Thu, 01 Feb 2024 17:43:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706827374; 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; bh=SZ2BuUwZedumd7wAOOy0375BmtmEb3sTpJ8FTGLhqp4=; b=SMMR08br5XFc93xe0kiINR69dJqHVQiB2Ssl+xcvt40qBQMmsky5K85h6vEva9Vv7FCgJh f040t6j9rzTKlHnKoOEzRIXYxMLxcNK0HBBsl5e/qumZSu2qcX3rdFjwisk5MOuqApZkF7 9Y0ibnA/jCPSadxx+LxFZK4owr9UvwQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-83-nsyxm8MzMBKVTAd_nhxf1g-1; Thu, 01 Feb 2024 17:42:51 -0500 X-MC-Unique: nsyxm8MzMBKVTAd_nhxf1g-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A4B45185A780; Thu, 1 Feb 2024 22:42:50 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.18.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 572E12166B33; Thu, 1 Feb 2024 22:42:50 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH v3 00/20] qapi: statically type schema.py Date: Thu, 1 Feb 2024 17:42:26 -0500 Message-ID: <20240201224246.39480-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.292, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is *v3*, for some definitions of "version" and "three". It's still got some parts that Markus isn't wildly fond of, but I needed a synchronization part for discussing the remaining nits. (Sorry Markus.) v3: - 01: fixed alphabetization (... sigh) - 03: updated docstring, added super calls, renamed argument to @defn, reflowed long lines - 04: updated commit message - 05: updated commit message - 06: pushed type hints into later commit - 09: removed default argument and stuffed into next patch - 10: Added the parts Markus doesn't like (Sorry) - 11: updated commit message - 12: updated commit message - 13: Split into two patches. Kept stuff Markus doesn't like (Sorry) - 14: New, split from 13. I know this probably doesn't address everything, so if I didn't change it, feel free to re-flag so I can keep the feedback in one spot on the new series. (Sorry sorry sorry sorry sorry.) v2: - dropped the resolve_type refactoring patch - added QAPISchemaDefinition - misc bits and pieces. 001/19:[down] 'qapi: sort pylint suppressions' New, Markus's suggestion. 002/19:[0001] [FC] 'qapi/schema: add pylint suppressions' Added newline, Markus's RB 003/19:[down] 'qapi: create QAPISchemaDefinition' New, Markus's suggestion. 004/19:[0002] [FC] 'qapi/schema: declare type for QAPISchemaObjectTypeMember.type' Adjusted commit message and comment. 005/19:[down] 'qapi/schema: declare type for QAPISchemaArrayType.element_type' Patch renamed; removed @property trick in favor of static type declaration 006/19:[0009] [FC] 'qapi/schema: make c_type() and json_type() abstract methods' Use abc.ABC and @abstractmethod 007/19:[0001] [FC] 'qapi/schema: adjust type narrowing for mypy's benefit' Adjusted commit message; left in an assertion that is removed later instead. 008/19:[down] 'qapi/schema: add type narrowing to lookup_type()' Renamed removed type hints which get added later in the series instead simplified logic. 009/19:[down] 'qapi/schema: allow resolve_type to be used for built-in types' New patch. (Types are added later.) 010/19:[down] 'qapi: use schema.resolve_type instead of schema.lookup_type' New patch, replaces old 07/19 "assert schema.lookup_type did not fail" 011/19:[0011] [FC] 'qapi/schema: fix QAPISchemaArrayType.check's call to resolve_type' Dramatically simplified. 012/19:[----] [--] 'qapi/schema: assert info is present when necessary' 013/19:[----] [--] 'qapi/schema: split "checked" field into "checking" and "checked"' Changed the commit message, but actually struggled finding anything simpler than what I already had, owing to the fact that q_empty is a valid construct and I can't seem to avoid adding a new state variable here. 014/19:[----] [-C] 'qapi/schema: fix typing for QAPISchemaVariants.tag_member' Also unchanged from review, I think this is simplest still... 015/19:[down] 'qapi/schema: assert inner type of QAPISchemaVariants in check_clash()' Renamed, changed commit message and comment. 016/19:[----] [--] 'qapi/parser: demote QAPIExpression to Dict[str, Any]' 017/19:[0042] [FC] 'qapi/schema: add type hints' Mostly contextual changes. 018/19:[----] [--] 'qapi/schema: turn on mypy strictness' 019/19:[0006] [FC] 'qapi/schema: remove unnecessary asserts' Zapped a few more. John Snow (20): qapi: sort pylint suppressions qapi/schema: add pylint suppressions qapi: create QAPISchemaDefinition qapi/schema: declare type for QAPISchemaObjectTypeMember.type qapi/schema: declare type for QAPISchemaArrayType.element_type qapi/schema: make c_type() and json_type() abstract methods qapi/schema: adjust type narrowing for mypy's benefit qapi/schema: add type narrowing to lookup_type() qapi/schema: assert resolve_type has 'info' and 'what' args on error qapi: use schema.resolve_type instead of schema.lookup_type qapi/schema: fix QAPISchemaArrayType.check's call to resolve_type qapi/schema: assert info is present when necessary qapi/schema: split "checked" field into "checking" and "checked" qapi/schema: Don't initialize "members" with `None` qapi/schema: fix typing for QAPISchemaVariants.tag_member qapi/schema: assert inner type of QAPISchemaVariants in check_clash() qapi/parser: demote QAPIExpression to Dict[str, Any] qapi/schema: add type hints qapi/schema: turn on mypy strictness qapi/schema: remove unnecessary asserts scripts/qapi/introspect.py | 4 +- scripts/qapi/mypy.ini | 5 - scripts/qapi/parser.py | 3 +- scripts/qapi/pylintrc | 11 +- scripts/qapi/schema.py | 794 ++++++++++++++++++++++++------------- 5 files changed, 534 insertions(+), 283 deletions(-)