Skip to content

Commit

Permalink
Fix mypy checks (typing.Optional) (#2444)
Browse files Browse the repository at this point in the history
* typing.Optional

* flake
  • Loading branch information
mscroggs authored Nov 10, 2022
1 parent c56d30b commit d0d8a42
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion python/dolfinx/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""General tools for timing and configuration"""

import functools
import typing

from dolfinx import cpp as _cpp
from dolfinx.cpp.common import (IndexMap, git_commit_hash, has_adios2, # noqa
Expand Down Expand Up @@ -63,7 +64,7 @@ class Timer:
list_timings(comm, [TimingType.wall, TimingType.user])
"""

def __init__(self, name: str = None):
def __init__(self, name: typing.Optional[str] = None):
if name is None:
self._cpp_object = _cpp.common.Timer()
else:
Expand Down
6 changes: 3 additions & 3 deletions python/dolfinx/fem/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ def _assemble_vector_array(b: np.ndarray, L: FormMetaClass, constants=None, coef

@functools.singledispatch
def assemble_matrix(a: typing.Any,
bcs: typing.List[DirichletBCMetaClass] = None,
bcs: typing.Optional[typing.List[DirichletBCMetaClass]] = None,
diagonal: float = 1.0, constants=None, coeffs=None):
return _assemble_matrix_form(a, bcs, diagonal, constants, coeffs)


@assemble_matrix.register
def _assemble_matrix_csr(A: la.MatrixCSRMetaClass, a: form_types,
bcs: typing.List[DirichletBCMetaClass] = None,
bcs: typing.Optional[typing.List[DirichletBCMetaClass]] = None,
diagonal: float = 1.0, constants=None, coeffs=None) -> la.MatrixCSRMetaClass:
"""Assemble bilinear form into a matrix.
Expand Down Expand Up @@ -245,7 +245,7 @@ def _assemble_matrix_csr(A: la.MatrixCSRMetaClass, a: form_types,


@assemble_matrix.register(FormMetaClass)
def _assemble_matrix_form(a: form_types, bcs: typing.List[DirichletBCMetaClass] = None,
def _assemble_matrix_form(a: form_types, bcs: typing.Optional[typing.List[DirichletBCMetaClass]] = None,
diagonal: float = 1.0,
constants=None, coeffs=None) -> la.MatrixCSRMetaClass:
"""Assemble bilinear form into a matrix.
Expand Down
5 changes: 3 additions & 2 deletions python/dolfinx/fem/bcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def locate_dofs_topological(V: typing.Union[dolfinx.fem.FunctionSpace, typing.It

class DirichletBCMetaClass:
def __init__(self, value: typing.Union[Function, Constant, numpy.ndarray],
dofs: numpy.typing.ArrayLike, V: dolfinx.fem.FunctionSpace = None):
dofs: numpy.typing.ArrayLike, V: typing.Optional[dolfinx.fem.FunctionSpace] = None):
"""Representation of Dirichlet boundary condition which is imposed on
a linear system.
Expand Down Expand Up @@ -140,7 +140,8 @@ def function_space(self) -> dolfinx.fem.FunctionSpace:


def dirichletbc(value: typing.Union[Function, Constant, np.ndarray],
dofs: numpy.typing.NDArray[np.int32], V: dolfinx.fem.FunctionSpace = None) -> DirichletBCMetaClass:
dofs: numpy.typing.NDArray[np.int32],
V: typing.Optional[dolfinx.fem.FunctionSpace] = None) -> DirichletBCMetaClass:
"""Create a representation of Dirichlet boundary condition which
is imposed on a linear system.
Expand Down
2 changes: 1 addition & 1 deletion python/dolfinx/fem/petsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ class LinearProblem:
"""

def __init__(self, a: ufl.Form, L: ufl.Form, bcs: typing.List[DirichletBCMetaClass] = [],
u: _Function = None, petsc_options={}, form_compiler_options={}, jit_options={}):
u: typing.Optional[_Function] = None, petsc_options={}, form_compiler_options={}, jit_options={}):
"""Initialize solver for a linear variational problem.
Args:
Expand Down
4 changes: 2 additions & 2 deletions python/dolfinx/io/gmshio.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def cell_perm_array(cell_type: CellType, num_nodes: int) -> typing.List[int]:
if _has_gmsh:
__all__ += ["extract_topology_and_markers", "extract_geometry", "model_to_mesh", "read_from_msh"]

def extract_topology_and_markers(model: gmsh.model, name: str = None):
def extract_topology_and_markers(model: gmsh.model, name: typing.Optional[str] = None):
"""Extract all entities tagged with a physical marker in the gmsh
model, and collect the data per cell type.
Expand Down Expand Up @@ -132,7 +132,7 @@ def extract_topology_and_markers(model: gmsh.model, name: str = None):

return topologies

def extract_geometry(model: gmsh.model, name: str = None) -> npt.NDArray[np.float64]:
def extract_geometry(model: gmsh.model, name: typing.Optional[str] = None) -> npt.NDArray[np.float64]:
"""Extract the mesh geometry from a gmsh model as an array of shape
(num_nodes, 3), where the i-th row corresponds to the i-th node in the
mesh.
Expand Down
2 changes: 1 addition & 1 deletion python/dolfinx/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def locate_entities_boundary(mesh: Mesh, dim: int, marker: typing.Callable) -> n
}


def refine(mesh: Mesh, edges: np.ndarray = None, redistribute: bool = True) -> Mesh:
def refine(mesh: Mesh, edges: typing.Optional[np.ndarray] = None, redistribute: bool = True) -> Mesh:
"""Refine a mesh
Args:
Expand Down

0 comments on commit d0d8a42

Please sign in to comment.