Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1227489pxb; Thu, 21 Oct 2021 18:54:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbVD+9a8M95nRtmoXPyfXXTkw5Dw3JIRZt3VphLMsH+02oFQ2zJ+lO7TJWJAYMVFKUA2j+ X-Received: by 2002:a17:90b:1910:: with SMTP id mp16mr10851520pjb.30.1634867672122; Thu, 21 Oct 2021 18:54:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634867672; cv=none; d=google.com; s=arc-20160816; b=LrZDvwOKxSUel4nBhWdXQDTUAH41BgkxU4n07VT50Wbzs53IuS08K7cJx50D37NZU1 WKgR7JVaPlLzp3cOjgOGPBBnYlRs0nh4fM00gqHIz1L6z01BMLTH7w09Vta4lJuanf5O bbxHlsXWJfy2sSc8zdLX2Xmz4wpESPvtSGinxAEomCaiz/nrOzRHIMvkMlmIes5h+9dl 0fqfFYKA5xqBjGZw+dUpXheq4PHIgrJiNo6UFfHtbtuYtowmDqlXXaVg1qjXqC7HY6Qu IBWqEOwK/4yTiC6DlhGXJqi6Ii04Ao8Qa819pI09bI1VddvBDrD4AYw7HWIkc+l0kdkH xvVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RqJHISvUCdhEFp+Jfgg5EOh8TgpsKhCaH+eHcg+5i2Y=; b=KjVYkTFXeHA5lLOP6oIJTYk93Qk4EW050RfpQjYvb6xV/U/mkt4o/11/CHeOh4HZYa IHf16LdNCI25tIIZOYSNWccqMdSDu7rwPbMj7zxKBoZdla5siT+ae211cLRZ9GH6BmcM Wv2B57zXBBEyyPu4aW5Rb+o6HD8EmWVk2T6oPztrOsygeqK2LheE53DVfvnPZ3dz2R+6 8ua2G3r9G+oou4juGjACKUjyzQr7BUCtX9ZNQMa7hr/lPnzjxgR0nwkPvF5Gm9M7U8ng vFOLo3kNC4wUhHdhhsEiIFR6z+Z3qcceoAf7QwlSQNPdY74wP1kmz2rLd0o6dbCn+9tU kYZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=geA75xij; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si12290331plf.362.2021.10.21.18.54.18; Thu, 21 Oct 2021 18:54:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=geA75xij; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230521AbhJVByc (ORCPT + 99 others); Thu, 21 Oct 2021 21:54:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbhJVByb (ORCPT ); Thu, 21 Oct 2021 21:54:31 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AED1BC061764 for ; Thu, 21 Oct 2021 18:52:14 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id i12so2302082wrb.7 for ; Thu, 21 Oct 2021 18:52:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RqJHISvUCdhEFp+Jfgg5EOh8TgpsKhCaH+eHcg+5i2Y=; b=geA75xiju7ZMZN4ckoJltl1taoSytz0vDR0aUH2zGkzS5LlcaCLYJ3v2j65OVqS4d0 LhNXXiHE1nTM1iJlHxOLKkwEKqE8scg/s4lgsQOOjDPUCmbeZlgy3mT9AiIfPILncws/ uWxZO8gzRA5niJ2cNZTrDedqyQ0yUDXEmIO8Ipohvu4ukJoYznxsDQdkzQE+pMtNyNWf zEU5A2mOwsB30h9aiQvUxUrRzH5lTZ8ba9mZ+wD5n3XY5VNlivfz1e3HFa+KiDdils8R 9ITkrwBZPx+mboOIkxpjLC8Dv3tAeODQEfoYNTyTNtVWsOCxeaGy9/FTFVYmeFOX2qun Ql7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RqJHISvUCdhEFp+Jfgg5EOh8TgpsKhCaH+eHcg+5i2Y=; b=G0Nl+vWMw2+8vi3Rviwrq95coBqTiFozsAy0iXLKZ4GrysCaG5KqdFmogXfE5qjJiv vot+BQV+Ze3tcBl5oVUSntt/NRbie9rKl4gR/bBQcrVwDuYDr5yZhR4V/3FyhBxMdqzR G6z7fR80OnxdS2rao7bqo3rvr1PehX3WkVolyxES+GpJyVTn0CPJvi0W2SkdyENVfZ0q D9eN2bqOIYbul9e3IUQ86dNhvsCecfoxFQwewt0Up65+klj1SEKgNX9XMZz4VkoVywjx oCP2xWOOiLjQ5hoa8TkWgve0llAe3mo7m4VKzkgZVDRE3Swc4xhCQfh0lJp9oU+SgbJs 8oEA== X-Gm-Message-State: AOAM532YzB27SUiBjiPPGHv4Vv0gqe5EbNZJPG4SFNeb/3vWoQYKDpu/ 6HXcqT/g3nPOSUTjDGXUyRRaogAwO31M5hYdalFqrg== X-Received: by 2002:a05:6000:1362:: with SMTP id q2mr11861419wrz.44.1634867533110; Thu, 21 Oct 2021 18:52:13 -0700 (PDT) MIME-Version: 1.0 References: <20211022004936.2049804-1-dlatypov@google.com> In-Reply-To: <20211022004936.2049804-1-dlatypov@google.com> From: David Gow Date: Fri, 22 Oct 2021 09:52:01 +0800 Message-ID: Subject: Re: [PATCH] kunit: tool: fix typecheck errors about loading qemu configs To: Daniel Latypov Cc: Brendan Higgins , Linux Kernel Mailing List , KUnit Development , "open list:KERNEL SELFTEST FRAMEWORK" , Shuah Khan Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 22, 2021 at 8:49 AM 'Daniel Latypov' via KUnit Development wrote: > > Currently, we have these errors: > $ mypy ./tools/testing/kunit/*.py > tools/testing/kunit/kunit_kernel.py:213: error: Item "_Loader" of "Optional[_Loader]" has no attribute "exec_module" > tools/testing/kunit/kunit_kernel.py:213: error: Item "None" of "Optional[_Loader]" has no attribute "exec_module" > tools/testing/kunit/kunit_kernel.py:214: error: Module has no attribute "QEMU_ARCH" > tools/testing/kunit/kunit_kernel.py:215: error: Module has no attribute "QEMU_ARCH" > > exec_module > =========== > > pytype currently reports no errors, but that's because there's a comment > disabling it on 213. > > This is due to https://github.com/python/typeshed/pull/2626. > The fix is to assert the loaded module implements the ABC > (abstract base class) we want which has exec_module support. > > QEMU_ARCH > ========= > > pytype is fine with this, but mypy is not: > https://github.com/python/mypy/issues/5059 > > Add a check that the loaded module does indeed have QEMU_ARCH. > Note: this is not enough to appease mypy, so we also add a comment to > squash the warning. > > Signed-off-by: Daniel Latypov > --- Thanks -- this has been annoying me quite a bit, so it's good to have it fixed. It's a bit of a shame mypy needs the additional comment, but what can you do... Reviewed-by: David Gow Cheers, -- David > tools/testing/kunit/kunit_kernel.py | 15 +++++++++------ > 1 file changed, 9 insertions(+), 6 deletions(-) > > diff --git a/tools/testing/kunit/kunit_kernel.py b/tools/testing/kunit/kunit_kernel.py > index faa6320e900e..c68b17905481 100644 > --- a/tools/testing/kunit/kunit_kernel.py > +++ b/tools/testing/kunit/kunit_kernel.py > @@ -207,12 +207,15 @@ def get_source_tree_ops_from_qemu_config(config_path: str, > module_path = '.' + os.path.join(os.path.basename(QEMU_CONFIGS_DIR), os.path.basename(config_path)) > spec = importlib.util.spec_from_file_location(module_path, config_path) > config = importlib.util.module_from_spec(spec) > - # TODO(brendanhiggins@google.com): I looked this up and apparently other > - # Python projects have noted that pytype complains that "No attribute > - # 'exec_module' on _importlib_modulespec._Loader". Disabling for now. > - spec.loader.exec_module(config) # pytype: disable=attribute-error > - return config.QEMU_ARCH.linux_arch, LinuxSourceTreeOperationsQemu( > - config.QEMU_ARCH, cross_compile=cross_compile) > + # See https://github.com/python/typeshed/pull/2626 for context. > + assert isinstance(spec.loader, importlib.abc.Loader) > + spec.loader.exec_module(config) > + > + if not hasattr(config, 'QEMU_ARCH'): > + raise ValueError('qemu_config module missing "QEMU_ARCH": ' + config_path) > + params: qemu_config.QemuArchParams = config.QEMU_ARCH # type: ignore > + return params.linux_arch, LinuxSourceTreeOperationsQemu( > + params, cross_compile=cross_compile) > > class LinuxSourceTree(object): > """Represents a Linux kernel source tree with KUnit tests.""" > > base-commit: 17ac23eb43f0cbefc8bfce44ad51a9f065895f9f > -- > 2.33.0.1079.g6e70778dc9-goog > > -- > You received this message because you are subscribed to the Google Groups "KUnit Development" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kunit-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/kunit-dev/20211022004936.2049804-1-dlatypov%40google.com.