From patchwork Thu Nov 16 01:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Snow X-Patchwork-Id: 13457492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8A2C4C2BB3F for ; Thu, 16 Nov 2023 01:46:08 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r3RQI-0005Er-7h; Wed, 15 Nov 2023 20:44:02 -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 1r3RQG-0005ES-HQ for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:00 -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 1r3RQA-0001zF-Vb for qemu-devel@nongnu.org; Wed, 15 Nov 2023 20:44:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700099033; 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=TBQsMXg0UqMi3OU8BrITW/nluz4TDp30aRzcy06GJIU=; b=QtNr8Q4aM0XhfP9FpKB2g2KyJ3DnPi3/pwBoqHhzOu2P7bDW4e6yzs+1v2R66p/NT/COEq Joyz+gefaf0Nl8tCV8tXFhsIZHjO5/AQAQqF9pTHMP6AfETrJMGMZUdebYRcRox8U8MQAG Q9Cup3oTzBlHTH0YGuzHyI04faLAuNM= 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-593-f3dy58YgPNW8riCMefq4Dg-1; Wed, 15 Nov 2023 20:43:51 -0500 X-MC-Unique: f3dy58YgPNW8riCMefq4Dg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 47AA4810FC1; Thu, 16 Nov 2023 01:43:51 +0000 (UTC) Received: from scv.localdomain (unknown [10.22.32.122]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC58EC15881; Thu, 16 Nov 2023 01:43:50 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Cc: Peter Maydell , Michael Roth , Markus Armbruster , John Snow Subject: [PATCH 00/19] qapi: statically type schema.py Date: Wed, 15 Nov 2023 20:43:31 -0500 Message-ID: <20231116014350.653792-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.099, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Hi! This branch has some comical name like python-qapi-cleanup-pt6-v2 but, simply, it finishes what I started and statically types all of the QAPI generator code. GitLab CI: https://gitlab.com/jsnow/qemu/-/pipelines/1074124051 Patch 1 is an actual fix, Patch 2 is a minor patch for pylint with no runtime effect, Patches 3-15 fix individual typing issues that have some runtime effect. Patch 16 adds typing information, Patch 17 removes the schema.py exemption from the mypy conf, Patches 18-19 are optional. Most of the patches (expect 16) are very small. I'm sure we'll need to rework parts of this, but hey, gotta start somewhere. --js John Snow (19): qapi/schema: fix QAPISchemaEntity.__repr__() qapi/schema: add pylint suppressions qapi/schema: name QAPISchemaInclude entities qapi/schema: declare type for QAPISchemaObjectTypeMember.type qapi/schema: make c_type() and json_type() abstract methods qapi/schema: adjust type narrowing for mypy's benefit qapi/introspect: assert schema.lookup_type did not fail qapi/schema: add static typing and assertions to lookup_type() qapi/schema: assert info is present when necessary qapi/schema: make QAPISchemaArrayType.element_type non-Optional qapi/schema: fix QAPISchemaArrayType.check's call to resolve_type qapi/schema: split "checked" field into "checking" and "checked" qapi/schema: fix typing for QAPISchemaVariants.tag_member qapi/schema: assert QAPISchemaVariants are QAPISchemaObjectType qapi/parser: demote QAPIExpression to Dict[str, Any] qapi/schema: add type hints qapi/schema: turn on mypy strictness qapi/schema: remove unnecessary asserts qapi/schema: refactor entity lookup helpers docs/sphinx/qapidoc.py | 2 +- scripts/qapi/mypy.ini | 5 - scripts/qapi/parser.py | 3 +- scripts/qapi/pylintrc | 5 - scripts/qapi/schema.py | 723 ++++++++++++++++++++++++++++------------- 5 files changed, 498 insertions(+), 240 deletions(-)