diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index c009dfd4f0..b24affa806 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -139,8 +139,8 @@ jobs: . ./mypy-env/bin/activate pip install mypy types-cffi scipy-stubs mypy -p dolfinx - # mypy test - # mypy demo + mypy test + mypy demo - name: Install gmsh and pyvista (and dependencies) run: | diff --git a/python/demo/demo_pml.py b/python/demo/demo_pml.py index 27d4fb9464..c5634bf72d 100644 --- a/python/demo/demo_pml.py +++ b/python/demo/demo_pml.py @@ -214,8 +214,8 @@ def generate_mesh_wire( def compute_a(nu: int, m: complex, alpha: float) -> float: """Compute the Mie coefficient a_nu for a cylinder.""" - J_nu_alpha = jv(nu, alpha) - J_nu_malpha = jv(nu, m * alpha) + J_nu_alpha = jv(nu, alpha) # type: ignore + J_nu_malpha = jv(nu, m * alpha) # type: ignore J_nu_alpha_p = jvp(nu, alpha, 1) J_nu_malpha_p = jvp(nu, m * alpha, 1) diff --git a/python/demo/demo_pyamg.py b/python/demo/demo_pyamg.py index bf6e4e68c8..6708a1ff6e 100644 --- a/python/demo/demo_pyamg.py +++ b/python/demo/demo_pyamg.py @@ -63,7 +63,7 @@ def poisson_problem(dtype: npt.DTypeLike, solver_type: str) -> None: solver_type: pyamg solver type, either "ruge_stuben" or "smoothed_aggregation" """ - real_type = np.real(dtype(0)).dtype + real_type = np.real(dtype(0)).dtype # type: ignore mesh = create_box( comm=MPI.COMM_WORLD, points=[(0.0, 0.0, 0.0), (3.0, 2.0, 1.0)], @@ -84,7 +84,7 @@ def poisson_problem(dtype: npt.DTypeLike, solver_type: str) -> None: dofs = locate_dofs_topological(V=V, entity_dim=fdim, entities=facets) - bc = dirichletbc(value=dtype(0), dofs=dofs, V=V) + bc = dirichletbc(value=dtype(0), dofs=dofs, V=V) # type: ignore u, v = ufl.TrialFunction(V), ufl.TestFunction(V) x = ufl.SpatialCoordinate(mesh) @@ -110,14 +110,14 @@ def poisson_problem(dtype: npt.DTypeLike, solver_type: str) -> None: print(ml) # Solve linear systems - print(f"\nSolve Poisson equation: {dtype.__name__}") + print(f"\nSolve Poisson equation: {dtype!s}") res: list[float] = [] tol = 1e-10 if real_type == np.float64 else 1e-6 uh.x.array[:] = ml.solve(b.array, tol=tol, residuals=res, accel="cg") for i, q in enumerate(res): print(f"Convergence history: iteration {i}, residual= {q}") - with io.XDMFFile(mesh.comm, f"out_pyamg/poisson_{dtype.__name__}.xdmf", "w") as file: + with io.XDMFFile(mesh.comm, f"out_pyamg/poisson_{dtype!s}.xdmf", "w") as file: file.write_mesh(mesh) file.write_function(uh) @@ -126,7 +126,7 @@ def poisson_problem(dtype: npt.DTypeLike, solver_type: str) -> None: # + -def nullspace_elasticty(Q: fem.FunctionSpace) -> list[np.ndarray]: +def nullspace_elasticty(Q: fem.FunctionSpace) -> npt.NDArray: """Create the elasticity (near)nulspace. Args: diff --git a/python/demo/demo_scattering_boundary_conditions.py b/python/demo/demo_scattering_boundary_conditions.py index f3bd735f6d..3c40b83574 100644 --- a/python/demo/demo_scattering_boundary_conditions.py +++ b/python/demo/demo_scattering_boundary_conditions.py @@ -220,8 +220,8 @@ def generate_mesh_wire( # + def compute_a(nu: int, m: complex, alpha: float) -> float: """Compute the a_nu coefficient.""" - J_nu_alpha = jv(nu, alpha) - J_nu_malpha = jv(nu, m * alpha) + J_nu_alpha = jv(nu, alpha) # type: ignore + J_nu_malpha = jv(nu, m * alpha) # type: ignore J_nu_alpha_p = jvp(nu, alpha, 1) J_nu_malpha_p = jvp(nu, m * alpha, 1) diff --git a/python/dolfinx/fem/bcs.py b/python/dolfinx/fem/bcs.py index 10dce42ba3..d4abcaa8a7 100644 --- a/python/dolfinx/fem/bcs.py +++ b/python/dolfinx/fem/bcs.py @@ -12,7 +12,6 @@ from __future__ import annotations -import numbers from collections.abc import Callable, Iterable import numpy as np @@ -172,7 +171,7 @@ def dof_indices(self) -> tuple[npt.NDArray[np.int32], int]: def dirichletbc( - value: Function | Constant | np.ndarray, + value: Function | Constant | np.ndarray | float | complex, dofs: npt.NDArray[np.int32], V: dolfinx.fem.FunctionSpace | None = None, ) -> DirichletBC: @@ -193,7 +192,7 @@ def dirichletbc( A representation of the boundary condition for modifying linear systems. """ - if isinstance(value, numbers.Number): + if isinstance(value, float | complex): value = np.asarray(value) try: