Make mypy work again #8
2 changed files with 17 additions and 12 deletions
Run mypy in the "lint" session
It needs the dependencies of `velofy` installed, and it now also reports "# type: ignore" comments without an error code or that are not needed anymore
commit
570c9c9fcb
23
noxfile.py
23
noxfile.py
|
|
@ -3,7 +3,7 @@
|
|||
By default, `uv run nox` runs the sessions that assure code quality:
|
||||
|
||||
- "format": Format source files with `autoflake`, `black`, `flynt`, `isort`, and `ruff`
|
||||
- "lint": Lint source files with `flake8`, `isort`, and `ruff`
|
||||
- "lint": Lint source files with `flake8`, `isort`, `mypy`, and `ruff`
|
||||
- "test": Run the test suite with `pytest`
|
||||
- "doctest": Check if code snippets in the docstrings run
|
||||
|
||||
|
|
@ -176,17 +176,21 @@ def format_code(session: Session) -> None:
|
|||
|
||||
@nox.session(name="lint", python=MAIN_PYTHON)
|
||||
def lint_code(session: Session) -> None:
|
||||
"""Lint source files with `flake8`, `isort`, and `ruff`.
|
||||
"""Lint source files with `flake8`, `isort`, `mypy`, and `ruff`.
|
||||
|
||||
If no extra arguments are provided, all source files are linted.
|
||||
Otherwise, they are interpreted as paths the linters work on recursively.
|
||||
|
||||
`mypy` always checks the entire package regardless
|
||||
because it needs the whole program to follow types across modules.
|
||||
"""
|
||||
start(session)
|
||||
|
||||
# The linters do not need `velofy` installed
|
||||
# because they work on the source files directly
|
||||
install_pinned(
|
||||
session,
|
||||
# `mypy` needs the dependencies of `velofy` installed
|
||||
# because otherwise it treats missing packages as `Any`
|
||||
".",
|
||||
"flake8",
|
||||
"flake8-annotations",
|
||||
"flake8-bandit",
|
||||
|
|
@ -204,8 +208,7 @@ def lint_code(session: Session) -> None:
|
|||
"flake8-todos",
|
||||
"flake8-unused-arguments",
|
||||
"isort",
|
||||
# TODO: See comment on `mypy` below
|
||||
# 'mypy',
|
||||
"mypy",
|
||||
"pep8-naming",
|
||||
"pydoclint[flake8]",
|
||||
"ruff",
|
||||
|
|
@ -225,12 +228,8 @@ def lint_code(session: Session) -> None:
|
|||
session.run("ruff", "--version")
|
||||
session.run("ruff", "check", *locations)
|
||||
|
||||
# TODO: Include `mypy` once it passes
|
||||
# - Only for the *.py files to be packaged
|
||||
# - It then needs the developed package and its dependencies installed
|
||||
# as it treats missing packages as `Any` and reports false successes
|
||||
# session.run('mypy', '--version') # noqa:ERA001
|
||||
# session.run('mypy', PACKAGE_LOCATION) # noqa:ERA001
|
||||
session.run("mypy", "--version")
|
||||
session.run("mypy", PACKAGE_LOCATION)
|
||||
|
||||
|
||||
@nox.session(name="test", python=MAIN_PYTHON)
|
||||
|
|
|
|||
|
|
@ -364,6 +364,12 @@ untyped_calls_exclude = [
|
|||
# Disallow functions without type annotations (or incomplete annotations)
|
||||
disallow_untyped_defs = true
|
||||
|
||||
# Require an error code in all "# type: ignore" comments
|
||||
enable_error_code = ["ignore-without-code"]
|
||||
|
||||
# Report "# type: ignore" comments that are not needed anymore
|
||||
warn_unused_ignores = true
|
||||
|
||||
|
||||
[[tool.mypy.overrides]]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue