feat: check type hints in CI against a baseline

Every signature carries annotations and nothing read them. mypy 1.18.2
over install.py and scripts/ reports 993 errors today, among them the
six pack helpers typed zipfile.ZipFile that every caller also hands a
PackRecord. The errors sit in mypy-baseline.txt and the schema job fails
on any error outside it, or on an entry that no longer occurs. Third-party
packages are left out so the result does not depend on the machine: 6 s
locally, run twice and on 3.12 and 3.13 with the same errors.
This commit is contained in:
Abdessamad Derraz committed 2026-11-06 14:47:20 +01:00
1 parent a99682beeb
commit b56ec21728
5 files changed
+1091

No files matched your search

+44
View File
@@ -2834,6 +2834,50 @@ class DeclaredDependenciesMatchTheDocumentedWorkflows(unittest.TestCase):
)
class TheAnnotationsAreChecked(unittest.TestCase):
"""Every signature carried type hints and nothing read them: six pack
helpers declared `zipfile.ZipFile` while every caller also passed a
PackRecord, and 990 such contradictions went through CI green. mypy now
runs in CI against mypy-baseline.txt, the errors the code carried when the
check started."""
BASELINE = ROOT / "mypy-baseline.txt"
ENTRY = re.compile(r"(?P<path>[^:]+\.py):0: error: .+ \[[a-z-]+\]")
def test_ci_holds_the_code_to_the_baseline(self):
body = (ROOT / ".github" / "workflows" / "validate.yml").read_text(
encoding="utf-8"
)
self.assertIn("mypy-baseline filter", body)
self.assertNotIn("--allow-unsynced", body)
def test_every_baseline_entry_names_a_file_that_exists(self):
stale = []
for line in self.BASELINE.read_text(encoding="utf-8").splitlines():
match = self.ENTRY.fullmatch(line)
self.assertIsNotNone(match, f"unreadable baseline entry: {line}")
if not (ROOT / match["path"]).is_file():
stale.append(match["path"])
self.assertEqual(stale, [], "baseline entries for files that are gone")
def test_the_code_reports_no_error_outside_the_baseline(self):
for module in ("mypy", "mypy_baseline"):
try:
__import__(module)
except ImportError:
self.skipTest(f"{module} is not installed (pip install -e '.[dev]')")
report = subprocess.run(
[sys.executable, "-m", "mypy"],
cwd=ROOT, capture_output=True, text=True, check=False,
)
result = subprocess.run(
[sys.executable, "-m", "mypy_baseline", "filter", "--no-colors"],
cwd=ROOT, input=report.stdout, capture_output=True, text=True,
check=False,
)
self.assertEqual(result.returncode, 0, result.stdout)
class TheProjectInstallsWithPip(unittest.TestCase):
"""pyproject declared a dev extra that pip could not install: without a
[build-system] and an explicit module list, setuptools' flat-layout