Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kunit: tool: undo type subscripts for subprocess.Popen

Writing `subprocess.Popen[str]` requires python 3.9+.
kunit.py has an assertion that the python version is 3.7+, so we should
try to stay backwards compatible.

This conflicts a bit with commit 1da2e6220e11 ("kunit: tool: fix
pre-existing `mypy --strict` errors and update run_checks.py"), since
mypy complains like so
> kunit_kernel.py:95: error: Missing type parameters for generic type "Popen" [type-arg]

Note: `mypy --strict --python-version 3.7` does not work.

We could annotate each file with comments like
`# mypy: disable-error-code="type-arg"
but then we might still get nudged to break back-compat in other files.

This patch adds a `mypy.ini` file since it seems like the only way to
disable specific error codes for all our files.

Note: run_checks.py doesn't need to specify `--config_file mypy.ini`,
but I think being explicit is better, particularly since most kernel
devs won't be familiar with how mypy works.

Fixes: 695e26030858 ("kunit: tool: add subscripts for type annotations where appropriate")
Reported-by: SeongJae Park <sj@kernel.org>
Link: https://lore.kernel.org/linux-kselftest/20230501171520.138753-1-sj@kernel.org
Signed-off-by: Daniel Latypov <dlatypov@google.com>
Tested-by: SeongJae Park <sj@kernel.org>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Daniel Latypov and committed by
Shuah Khan
e30f65c4 ac9a7868

+10 -4
+3 -3
tools/testing/kunit/kunit_kernel.py
··· 92 92 if stderr: # likely only due to build warnings 93 93 print(stderr.decode()) 94 94 95 - def start(self, params: List[str], build_dir: str) -> subprocess.Popen[str]: 95 + def start(self, params: List[str], build_dir: str) -> subprocess.Popen: 96 96 raise RuntimeError('not implemented!') 97 97 98 98 ··· 113 113 kconfig.merge_in_entries(base_kunitconfig) 114 114 return kconfig 115 115 116 - def start(self, params: List[str], build_dir: str) -> subprocess.Popen[str]: 116 + def start(self, params: List[str], build_dir: str) -> subprocess.Popen: 117 117 kernel_path = os.path.join(build_dir, self._kernel_path) 118 118 qemu_command = ['qemu-system-' + self._qemu_arch, 119 119 '-nodefaults', ··· 142 142 kconfig.merge_in_entries(base_kunitconfig) 143 143 return kconfig 144 144 145 - def start(self, params: List[str], build_dir: str) -> subprocess.Popen[str]: 145 + def start(self, params: List[str], build_dir: str) -> subprocess.Popen: 146 146 """Runs the Linux UML binary. Must be named 'linux'.""" 147 147 linux_bin = os.path.join(build_dir, 'linux') 148 148 params.extend(['mem=1G', 'console=tty', 'kunit_shutdown=halt'])
+6
tools/testing/kunit/mypy.ini
··· 1 + [mypy] 2 + strict = True 3 + 4 + # E.g. we can't write subprocess.Popen[str] until Python 3.9+. 5 + # But kunit.py tries to support Python 3.7+, so let's disable it. 6 + disable_error_code = type-arg
+1 -1
tools/testing/kunit/run_checks.py
··· 23 23 'kunit_tool_test.py': ['./kunit_tool_test.py'], 24 24 'kunit smoke test': ['./kunit.py', 'run', '--kunitconfig=lib/kunit', '--build_dir=kunit_run_checks'], 25 25 'pytype': ['/bin/sh', '-c', 'pytype *.py'], 26 - 'mypy': ['mypy', '--strict', '--exclude', '_test.py$', '--exclude', 'qemu_configs/', '.'], 26 + 'mypy': ['mypy', '--config-file', 'mypy.ini', '--exclude', '_test.py$', '--exclude', 'qemu_configs/', '.'], 27 27 } 28 28 29 29 # The user might not have mypy or pytype installed, skip them if so.