Skip to content

Commit 85310a6

Browse files
dlatypovshuahkh
authored andcommitted
kunit: tool: fix newly introduced typechecker errors
After upgrading mypy and pytype from pip, we see 2 new errors when running ./tools/testing/kunit/run_checks.py. Error #1: mypy and pytype They now deduce that importlib.util.spec_from_file_location() can return None and note that we're not checking for this. We validate that the arch is valid (i.e. the file exists) beforehand. Add in an `asssert spec is not None` to appease the checkers. Error #2: pytype bug google/pytype#1057 It doesn't like `from datetime import datetime`, specifically that a type shares a name with a module. We can workaround this by either * renaming the import or just using `import datetime` * passing the new `--fix-module-collisions` flag to pytype. We pick the first option for now because * the flag is quite new, only in the 2021.11.29 release. * I'd prefer if people can just run `pytype <file>` Signed-off-by: Daniel Latypov <[email protected]> Reviewed-by: Brendan Higgins <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 1ee2ba8 commit 85310a6

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

tools/testing/kunit/kunit_kernel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def get_source_tree_ops_from_qemu_config(config_path: str,
209209
# exists as a file.
210210
module_path = '.' + os.path.join(os.path.basename(QEMU_CONFIGS_DIR), os.path.basename(config_path))
211211
spec = importlib.util.spec_from_file_location(module_path, config_path)
212+
assert spec is not None
212213
config = importlib.util.module_from_spec(spec)
213214
# See https://github.com/python/typeshed/pull/2626 for context.
214215
assert isinstance(spec.loader, importlib.abc.Loader)

tools/testing/kunit/kunit_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from __future__ import annotations
1313
import re
1414

15-
from datetime import datetime
15+
import datetime
1616
from enum import Enum, auto
1717
from functools import reduce
1818
from typing import Iterable, Iterator, List, Optional, Tuple
@@ -517,7 +517,7 @@ def green(text: str) -> str:
517517

518518
def print_with_timestamp(message: str) -> None:
519519
"""Prints message with timestamp at beginning."""
520-
print('[%s] %s' % (datetime.now().strftime('%H:%M:%S'), message))
520+
print('[%s] %s' % (datetime.datetime.now().strftime('%H:%M:%S'), message))
521521

522522
def format_test_divider(message: str, len_message: int) -> str:
523523
"""

0 commit comments

Comments
 (0)