lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 21 Oct 2021 17:49:36 -0700
From:   Daniel Latypov <>
        Daniel Latypov <>
Subject: [PATCH] kunit: tool: fix typecheck errors about loading qemu configs

Currently, we have these errors:
$ mypy ./tools/testing/kunit/*.py
tools/testing/kunit/ error: Item "_Loader" of "Optional[_Loader]" has no attribute "exec_module"
tools/testing/kunit/ error: Item "None" of "Optional[_Loader]" has no attribute "exec_module"
tools/testing/kunit/ error: Module has no attribute "QEMU_ARCH"
tools/testing/kunit/ error: Module has no attribute "QEMU_ARCH"


pytype currently reports no errors, but that's because there's a comment
disabling it on 213.

This is due to
The fix is to assert the loaded module implements the ABC
(abstract base class) we want which has exec_module support.


pytype is fine with this, but mypy is not:

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 <>
 tools/testing/kunit/ | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tools/testing/kunit/ b/tools/testing/kunit/
index faa6320e900e..c68b17905481 100644
--- a/tools/testing/kunit/
+++ b/tools/testing/kunit/
@@ -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( 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 for context.
+	assert isinstance(spec.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

Powered by blists - more mailing lists