Skip to content

Commit

Permalink
kunit: tool: add subscripts for type annotations where appropriate
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Daniel Latypov authored and Shuah Khan committed Mar 17, 2023
1 parent 2c6a96d commit 695e260
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions tools/testing/kunit/kunit_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def make(self, jobs, build_dir: str, make_options) -> None:
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!')


Expand All @@ -112,7 +112,7 @@ def make_arch_config(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_conf
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',
Expand Down Expand Up @@ -141,7 +141,7 @@ def make_arch_config(self, base_kunitconfig: kunit_config.Kconfig) -> kunit_conf
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'])
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/kunit/kunit_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
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()

Expand Down
2 changes: 1 addition & 1 deletion tools/testing/kunit/run_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 695e260

Please sign in to comment.