Skip to content

Commit ade83de

Browse files
authored
chore: tighten mypy and pytest config (#1167)
Port a few ideas from pypa/packaging: - Add `-p no:legacypath` to pytest addopts. No test uses `tmpdir` or `testdir`, so this keeps the legacy fixtures from coming back. - Enable mypy's `native_parser`. - Set mypy `files`/`exclude` so a bare `mypy` checks the same paths as pre-commit. This also adds `.github/` and `noxfile.py`, which were not checked before, and widens the pre-commit hook regex to match. - Add the `Typing :: Typed` and `Implementation :: CPython` classifiers. Checking noxfile.py found two type errors: `default=shutil.which(...)` passed `str | None` where a `bool` is declared, unlike the `conda` session next to it. Behavior does not change, because the value was only used as a truthy value. Assisted-by: ClaudeCode:claude-opus-5
1 parent c699c47 commit ade83de

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ repos:
4141
rev: v2.3.0
4242
hooks:
4343
- id: mypy
44-
files: ^(nox/|tests/)
44+
files: ^(nox/|tests/|\.github/|noxfile\.py$)
4545
exclude: ^tests/resources/
4646
args: []
4747
additional_dependencies:

noxfile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ def conda_tests(session: nox.Session) -> None:
122122
xonda_tests(session, "conda")
123123

124124

125-
@nox.session(venv_backend="mamba", default=shutil.which("mamba"))
125+
@nox.session(venv_backend="mamba", default=bool(shutil.which("mamba")))
126126
def mamba_tests(session: nox.Session) -> None:
127127
"""Run test suite set up with mamba."""
128128
xonda_tests(session, "mamba")
129129

130130

131-
@nox.session(venv_backend="micromamba", default=shutil.which("micromamba"))
131+
@nox.session(venv_backend="micromamba", default=bool(shutil.which("micromamba")))
132132
def micromamba_tests(session: nox.Session) -> None:
133133
"""Run test suite set up with micromamba."""
134134
xonda_tests(session, "micromamba")
@@ -183,6 +183,8 @@ def docs(session: nox.Session) -> None:
183183

184184
# The following sessions are only to be run in CI to check the nox GHA action
185185
def _check_python_version(session: nox.Session) -> None:
186+
# Callers parametrize with a list of version strings, so this is always a str.
187+
assert isinstance(session.python, str)
186188
if session.python.startswith("pypy"):
187189
# Drop starting "pypy" and maybe "-"
188190
python_version = session.python.lstrip("py-")

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ classifiers = [
3535
"Programming Language :: Python :: 3.13",
3636
"Programming Language :: Python :: 3.14",
3737
"Programming Language :: Python :: 3.15",
38+
"Programming Language :: Python :: Implementation :: CPython",
3839
"Topic :: Software Development :: Testing",
40+
"Typing :: Typed",
3941
]
4042
dependencies = [
4143
"argcomplete>=1.9.4,<4",
@@ -124,17 +126,20 @@ max_supported_python = "3.15"
124126

125127
[tool.mypy]
126128
mypy_path = [ ".github" ]
129+
files = [ ".github", "nox", "noxfile.py", "tests" ]
130+
exclude = [ "^tests/resources/" ]
127131
python_version = "3.10"
128132
warn_unreachable = true
129133
enable_error_code = [ "ignore-without-code", "redundant-expr", "truthy-bool" ]
130134
strict = true
135+
native_parser = true
131136
overrides = [ { module = [ "tox.*" ], ignore_missing_imports = true } ]
132137

133138
[tool.pytest]
134139
ini_options.minversion = "7.0"
135140
ini_options.testpaths = [ "tests" ]
136141
ini_options.pythonpath = [ ".github/" ]
137-
ini_options.addopts = [ "-ra", "--strict-markers", "--strict-config" ]
142+
ini_options.addopts = [ "-ra", "--strict-markers", "--strict-config", "-p", "no:legacypath" ]
138143
ini_options.markers = [
139144
"conda: test requires conda",
140145
]

0 commit comments

Comments
 (0)