kunit: tool: add subscripts for type annotations where appropriate
authorDaniel Latypov <dlatypov@google.com>
Thu, 16 Mar 2023 22:06:36 +0000 (15:06 -0700)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 17 Mar 2023 18:28:18 +0000 (12:28 -0600)
E.g. for subprocess.Popen, it can be opened in `text=True` mode where it
returns strings, or `text=False` where it returns bytes.
To differentiate, you can annotate types as `Popen[str]` or
`Popen[bytes]`.

This patch should add subscripts in all the places we were missing them.

Reported-by: Johannes Berg <johannes.berg@intel.com>
Link: https://lore.kernel.org/linux-kselftest/20230315105055.9b2be0153625.I7a2cb99b95dff216c0feed4604255275e0b156a7@changeid/
Signed-off-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/kunit/kunit_kernel.py
tools/testing/kunit/kunit_printer.py
tools/testing/kunit/run_checks.py

index 53e90c3358348dbef24c2bdba395decf60b95ab2..e6fc8fcb071a831a0344856fe9fa1e4b51feb79e 100644 (file)
@@ -92,7 +92,7 @@ class LinuxSourceTreeOperations:
                if stderr:  # likely only due to build warnings
                        print(stderr.decode())
 
-       def start(self, params: List[str], build_dir: str) -> subprocess.Popen:
+       def start(self, params: List[str], build_dir: str) -> subprocess.Popen[str]:
                raise RuntimeError('not implemented!')
 
 
@@ -112,7 +112,7 @@ class LinuxSourceTreeOperationsQemu(LinuxSourceTreeOperations):
                kconfig.merge_in_entries(base_kunitconfig)
                return kconfig
 
-       def start(self, params: List[str], build_dir: str) -> subprocess.Popen:
+       def start(self, params: List[str], build_dir: str) -> subprocess.Popen[str]:
                kernel_path = os.path.join(build_dir, self._kernel_path)
                qemu_command = ['qemu-system-' + self._qemu_arch,
                                '-nodefaults',
@@ -141,7 +141,7 @@ class LinuxSourceTreeOperationsUml(LinuxSourceTreeOperations):
                kconfig.merge_in_entries(base_kunitconfig)
                return kconfig
 
-       def start(self, params: List[str], build_dir: str) -> subprocess.Popen:
+       def start(self, params: List[str], build_dir: str) -> subprocess.Popen[str]:
                """Runs the Linux UML binary. Must be named 'linux'."""
                linux_bin = os.path.join(build_dir, 'linux')
                params.extend(['mem=1G', 'console=tty', 'kunit_shutdown=halt'])
index 5f1cc55ecdf5893e75e5b5f8a2bf2923ed8b40bc..015adf87dc2c773ac164d4979c2b3a7f96c63aa5 100644 (file)
@@ -15,7 +15,7 @@ _RESET = '\033[0;0m'
 class Printer:
        """Wraps a file object, providing utilities for coloring output, etc."""
 
-       def __init__(self, output: typing.IO):
+       def __init__(self, output: typing.IO[str]):
                self._output = output
                self._use_color = output.isatty()
 
index 066e6f938f6dcccc23dcaff4faa48a30e301f7f4..61cece1684df0654bf65c1bc1ed26d3b9f1aebc4 100755 (executable)
@@ -37,7 +37,7 @@ def main(argv: Sequence[str]) -> None:
        if argv:
                raise RuntimeError('This script takes no arguments')
 
-       future_to_name: Dict[futures.Future, str] = {}
+       future_to_name: Dict[futures.Future[None], str] = {}
        executor = futures.ThreadPoolExecutor(max_workers=len(commands))
        for name, argv in commands.items():
                if name in necessary_deps and shutil.which(necessary_deps[name]) is None: