Skip to content

Commit d895810

Browse files
garth-wellsclaude
andcommitted
Fix the mypy errors at source instead of exempting two modules
The previous commit exempted 'dolfinx.la' and 'dolfinx.fem.petsc' from disallow_any_unimported and warn_unused_ignores. That is a blunt instrument: it turns off two checks for every line of two modules to silence three specific errors. Remove it and address them where they occur, which is what AGENTS.md asks for -- PETSc-related type checking disabled on a per-line basis. - 'la.to_scipy' declares a scipy return type, and scipy is untyped, so the declaration itself trips disallow_any_unimported. Ignore that one signature. - The two '# type: ignore[attr-defined]' comments on the cffi lib attributes in 'fem/petsc.py' are never used, because the attributes are Any while cffi is untyped. Delete them. scipy and cffi move into the existing third-party ignore_missing_imports list, beside ufl, ffcx, gmsh and the rest, rather than sitting in a block of their own. Verified in a container reproducing the CI leg: 'Success' for all three targets, 30, 27 and 84 source files. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 09638d1 commit d895810

3 files changed

Lines changed: 9 additions & 21 deletions

File tree

python/dolfinx/fem/petsc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,12 +2059,12 @@ def set_vals(A: int,
20592059
"""
20602060
)
20612061

2062-
MatSetValuesLocal = _lib_cffi.MatSetValuesLocal # type: ignore[attr-defined]
2062+
MatSetValuesLocal = _lib_cffi.MatSetValuesLocal
20632063
"""See PETSc `MatSetValuesLocal
20642064
<https://petsc.org/release/manualpages/Mat/MatSetValuesLocal>`_
20652065
documentation."""
20662066

2067-
MatSetValuesBlockedLocal = _lib_cffi.MatSetValuesBlockedLocal # type: ignore[attr-defined]
2067+
MatSetValuesBlockedLocal = _lib_cffi.MatSetValuesBlockedLocal
20682068
"""See PETSc `MatSetValuesBlockedLocal
20692069
<https://petsc.org/release/manualpages/Mat/MatSetValuesBlockedLocal>`_
20702070
documentation."""

python/dolfinx/la/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ def to_dense(self) -> npt.NDArray[Scalar]:
276276
"""
277277
return self._cpp_object.to_dense() # type: ignore[return-value]
278278

279-
def to_scipy(self, ghosted: bool = False) -> _sparse.csr_matrix | _sparse.bsr_matrix:
279+
def to_scipy( # type: ignore[no-any-unimported]
280+
self, ghosted: bool = False
281+
) -> _sparse.csr_matrix | _sparse.bsr_matrix:
280282
"""Convert to a SciPy CSR/BSR matrix. Data is shared.
281283
282284
Note:

python/pyproject.toml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,6 @@ warn_unused_ignores = true
111111
show_error_codes = true
112112
ignore_missing_imports = false
113113

114-
# scipy and cffi ship no type information, and no stub packages are
115-
# installed in the environments CI checks in: the Spack legs run mypy
116-
# against the environment's interpreter, which has no pip, so stubs cannot
117-
# be added to it. Treat the two as untyped rather than reporting every use
118-
# of them.
119-
[[tool.mypy.overrides]]
120-
module = ["scipy.*", "cffi", "cffi.*", "_cffi_backend"]
121-
ignore_missing_imports = true
122-
123-
# Consequences of the above, kept as narrow as the module list allows:
124-
# 'dolfinx.la' returns a scipy sparse matrix, whose type is therefore Any,
125-
# and the '# type: ignore[attr-defined]' comments on the cffi lib
126-
# attributes in 'dolfinx.fem.petsc' read as unused while cffi is untyped.
127-
[[tool.mypy.overrides]]
128-
module = ["dolfinx.la", "dolfinx.fem.petsc"]
129-
disallow_any_unimported = false
130-
warn_unused_ignores = false
131-
132114
# Test bodies are unannotated pytest functions exercising loose numpy/dtype
133115
# patterns; check_untyped_defs and no_implicit_optional are not enforced
134116
# there.
@@ -195,6 +177,10 @@ module = [
195177
"pyvista",
196178
"pyvistaqt",
197179
"networkx",
180+
"scipy.*",
181+
"cffi",
182+
"cffi.*",
183+
"_cffi_backend",
198184
]
199185
ignore_missing_imports = true
200186

0 commit comments

Comments
 (0)