Skip to content

Commit eb1a36e

Browse files
committed
Run mypy on noxfile.py and be more restrictive
There is no reason to ignore imports, that only makes checking the types weaker. To be able to check types in a more strict way, we need to use packages (-p) to avoid errors about having the same file in 2 packages (src.frequenz.channels and frequenz.channels), so we need to translate directory to package when running on `src`. Also we need to check individual files separately. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 0962e7a commit eb1a36e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

docs/mkdocstrings_autoapi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
SRC_PATH = "src"
1515
DST_PATH = "reference"
1616

17-
# noqa because mkdocs_gen_files uses a very weird module-level
17+
# type ignore because mkdocs_gen_files uses a very weird module-level
1818
# __getattr__() which messes up the type system
19-
nav = mkdocs_gen_files.Nav() # noqa
19+
nav = mkdocs_gen_files.Nav() # type: ignore
2020

2121
for path in sorted(Path(SRC_PATH).rglob("*.py")):
2222
module_path = path.relative_to(SRC_PATH).with_suffix("")

noxfile.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,26 @@ def pylint(session: nox.Session) -> None:
3434

3535
@nox.session
3636
def mypy(session: nox.Session) -> None:
37-
session.install(".", "mypy")
38-
session.run(
39-
"mypy",
40-
"--ignore-missing-imports",
37+
"""Run mypy to check type hints."""
38+
session.install("-e", ".[docs]", "pytest", "nox", "mypy")
39+
40+
common_args = [
4141
"--namespace-packages",
4242
"--non-interactive",
4343
"--install-types",
4444
"--explicit-package-bases",
45-
"--follow-imports=silent",
4645
"--strict",
47-
*check_dirs,
48-
)
46+
]
47+
48+
pkg_args = []
49+
for pkg in check_dirs:
50+
if pkg == "src":
51+
pkg = "frequenz.channels"
52+
pkg_args.append("-p")
53+
pkg_args.append(pkg)
54+
55+
session.run("mypy", *common_args, *pkg_args)
56+
session.run("mypy", *common_args, *check_files)
4957

5058

5159
@nox.session

0 commit comments

Comments
 (0)