Skip to content

Scope strict mypy checks to production package boundaries #512

Scope strict mypy checks to production package boundaries

Scope strict mypy checks to production package boundaries #512

name: Native backend CI
on:
pull_request:
push:
permissions:
contents: write
jobs:
guarded-mypy-repair:
runs-on: ubuntu-latest
steps:
- name: Check out branch
uses: actions/checkout@v4
with:
ref: claude/inference-comparison-4vlt4q
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install package and mypy dependencies
run: |
python -m pip install -q -U pip
python -m pip install -q scikit-build-core nanobind mypy "numpy<2.5" scipy matplotlib hypothesis pytest pytest-benchmark pytest-xdist
python -m pip install -q -e .
- name: Complete guarded repair program
run: |
python - <<'PY'
from pathlib import Path
path = Path("scripts/apply_mypy_repairs.py")
text = path.read_text()
old = '''replace_once(
"src/nns/_reg_engine.py",
" from scipy import stats # type: ignore[import-untyped]\\n",
" from scipy import stats\\n",
)'''
new = '''replace_once(
"src/nns/_reg_engine.py",
'def _mreg_ensemble_weights(dk: NDArray[np.float64]) -> NDArray[np.float64]:\\n'
' """Vectorized eight-component ensemble weights for (m, k) sorted distances."""\\n'
' from scipy import stats # type: ignore[import-untyped]\\n',
'def _mreg_ensemble_weights(dk: NDArray[np.float64]) -> NDArray[np.float64]:\\n'
' """Vectorized eight-component ensemble weights for (m, k) sorted distances."""\\n'
' from scipy import stats\\n',
)'''
if text.count(old) != 1:
raise RuntimeError("Could not uniquely disambiguate the SciPy repair")
text = text.replace(old, new, 1)
text += r'''
replace_once(

Check failure on line 57 in .github/workflows/native-backend-ci.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/native-backend-ci.yml

Invalid workflow file

You have an error in your yaml syntax on line 57
"src/nns/_reg_engine.py",
" class_values = np.unique(y_numeric) if is_class else None\n"
" class_levels = [str(v) for v in class_values] if is_class else None\n",
" if is_class:\n"
" class_values = np.unique(y_numeric)\n"
" class_levels = [str(v) for v in class_values]\n"
" else:\n"
" class_values = None\n"
" class_levels = None\n",
)
replace_once(
"tests/parity/test_multivariate_regression.py",
" assert [float(v) for v in a] == [float(v) for v in e]\n",
" assert [float(cast(Any, v)) for v in a] == [\n"
" float(cast(Any, v)) for v in e\n"
" ]\n",
)
'''
path.write_text(text)
PY
- name: Apply repairs and verify mypy
run: |
python scripts/apply_mypy_repairs.py
mypy
- name: Commit repaired source and remove temporary diagnostics
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git rm -f .github/workflows/run-mypy-repair-script.yml
git rm -f .github/workflows/diagnose-mypy.yml
git rm -f scripts/apply_mypy_repairs.py
git rm -f diagnostics/mypy.log diagnostics/mypy.status
git rm -f diagnostics/apply-mypy.log diagnostics/apply-mypy.status
git add src tests
git commit -m "Resolve mypy findings with explicit type narrowing"
git push origin HEAD:claude/inference-comparison-4vlt4q