From 43f038d761693e34345a64bf7eb59932d7bcdfc0 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Mon, 29 Jul 2024 00:29:39 -0700 Subject: [PATCH] modernize type annotations --- meanas/eigensolvers.py | 2 +- meanas/fdfd/bloch.py | 3 ++- meanas/fdfd/farfield.py | 3 ++- meanas/fdfd/functional.py | 2 +- meanas/fdfd/scpml.py | 2 +- meanas/fdfd/solvers.py | 11 ++++++----- meanas/fdfd/waveguide_3d.py | 3 ++- meanas/fdmath/functional.py | 3 ++- meanas/fdmath/operators.py | 2 +- meanas/fdmath/types.py | 2 +- meanas/fdmath/vectorization.py | 3 ++- meanas/fdtd/pml.py | 3 ++- 12 files changed, 23 insertions(+), 16 deletions(-) diff --git a/meanas/eigensolvers.py b/meanas/eigensolvers.py index 7a3a8a7..e8630aa 100644 --- a/meanas/eigensolvers.py +++ b/meanas/eigensolvers.py @@ -1,7 +1,7 @@ """ Solvers for eigenvalue / eigenvector problems """ -from typing import Callable +from collections.abc import Callable import numpy from numpy.typing import NDArray, ArrayLike from numpy.linalg import norm diff --git a/meanas/fdfd/bloch.py b/meanas/fdfd/bloch.py index 12660e7..5ea5e7b 100644 --- a/meanas/fdfd/bloch.py +++ b/meanas/fdfd/bloch.py @@ -94,7 +94,8 @@ This module contains functions for generating and solving the """ -from typing import Callable, Any, cast, Sequence +from typing import Any, cast +from collections.abc import Callable, Sequence import logging import numpy from numpy import pi, real, trace diff --git a/meanas/fdfd/farfield.py b/meanas/fdfd/farfield.py index 5c1caf0..4829d86 100644 --- a/meanas/fdfd/farfield.py +++ b/meanas/fdfd/farfield.py @@ -1,7 +1,8 @@ """ Functions for performing near-to-farfield transformation (and the reverse). """ -from typing import Any, Sequence, cast +from typing import Any, cast +from collections.abc import Sequence import numpy from numpy.fft import fft2, fftshift, fftfreq, ifft2, ifftshift from numpy import pi diff --git a/meanas/fdfd/functional.py b/meanas/fdfd/functional.py index ba2bd70..8b21923 100644 --- a/meanas/fdfd/functional.py +++ b/meanas/fdfd/functional.py @@ -5,7 +5,7 @@ Functional versions of many FDFD operators. These can be useful for performing The functions generated here expect `cfdfield_t` inputs with shape (3, X, Y, Z), e.g. E = [E_x, E_y, E_z] where each (complex) component has shape (X, Y, Z) """ -from typing import Callable +from collections.abc import Callable import numpy from ..fdmath import dx_lists_t, fdfield_t, cfdfield_t, cfdfield_updater_t diff --git a/meanas/fdfd/scpml.py b/meanas/fdfd/scpml.py index bc056e1..f0a8843 100644 --- a/meanas/fdfd/scpml.py +++ b/meanas/fdfd/scpml.py @@ -2,7 +2,7 @@ Functions for creating stretched coordinate perfectly matched layer (PML) absorbers. """ -from typing import Sequence, Callable +from collections.abc import Sequence, Callable import numpy from numpy.typing import NDArray diff --git a/meanas/fdfd/solvers.py b/meanas/fdfd/solvers.py index 0487a06..517ecab 100644 --- a/meanas/fdfd/solvers.py +++ b/meanas/fdfd/solvers.py @@ -2,7 +2,8 @@ Solvers and solver interface for FDFD problems. """ -from typing import Callable, Dict, Any, Optional +from typing import Any +from collections.abc import Callable import logging import numpy @@ -68,12 +69,12 @@ def generic( dxes: dx_lists_t, J: vcfdfield_t, epsilon: vfdfield_t, - mu: Optional[vfdfield_t] = None, - pec: Optional[vfdfield_t] = None, - pmc: Optional[vfdfield_t] = None, + mu: vfdfield_t | None = None, + pec: vfdfield_t | None = None, + pmc: vfdfield_t | None = None, adjoint: bool = False, matrix_solver: Callable[..., ArrayLike] = _scipy_qmr, - matrix_solver_opts: Optional[Dict[str, Any]] = None, + matrix_solver_opts: dict[str, Any] | None = None, ) -> vcfdfield_t: """ Conjugate gradient FDFD solver using CSR sparse matrices. diff --git a/meanas/fdfd/waveguide_3d.py b/meanas/fdfd/waveguide_3d.py index 2f499fa..3cffa94 100644 --- a/meanas/fdfd/waveguide_3d.py +++ b/meanas/fdfd/waveguide_3d.py @@ -4,7 +4,8 @@ Tools for working with waveguide modes in 3D domains. This module relies heavily on `waveguide_2d` and mostly just transforms its parameters into 2D equivalents and expands the results back into 3D. """ -from typing import Sequence, Any +from typing import Any +from collections.abc import Sequence import numpy from numpy.typing import NDArray from numpy import complexfloating diff --git a/meanas/fdmath/functional.py b/meanas/fdmath/functional.py index 91d8d29..0e90f2b 100644 --- a/meanas/fdmath/functional.py +++ b/meanas/fdmath/functional.py @@ -3,7 +3,8 @@ Math functions for finite difference simulations Basic discrete calculus etc. """ -from typing import Sequence, Callable +from typing import TypeVar +from collections.abc import Sequence, Callable import numpy from numpy.typing import NDArray diff --git a/meanas/fdmath/operators.py b/meanas/fdmath/operators.py index 79ddfee..fe9847b 100644 --- a/meanas/fdmath/operators.py +++ b/meanas/fdmath/operators.py @@ -3,7 +3,7 @@ Matrix operators for finite difference simulations Basic discrete calculus etc. """ -from typing import Sequence +from collections.abc import Sequence import numpy from numpy.typing import NDArray from numpy import floating diff --git a/meanas/fdmath/types.py b/meanas/fdmath/types.py index b78e93f..bc678ea 100644 --- a/meanas/fdmath/types.py +++ b/meanas/fdmath/types.py @@ -1,7 +1,7 @@ """ Types shared across multiple submodules """ -from typing import Sequence, Callable, MutableSequence +from collections.abc import Sequence, Callable, MutableSequence from numpy.typing import NDArray from numpy import floating, complexfloating diff --git a/meanas/fdmath/vectorization.py b/meanas/fdmath/vectorization.py index 0a9f8ad..fef3c5e 100644 --- a/meanas/fdmath/vectorization.py +++ b/meanas/fdmath/vectorization.py @@ -4,7 +4,8 @@ and a 1D array representation of that field `[f_x0, f_x1, f_x2,... f_y0,... f_z0 Vectorized versions of the field use row-major (ie., C-style) ordering. """ -from typing import overload, Sequence +from typing import overload +from collections.abc import Sequence import numpy from numpy.typing import ArrayLike diff --git a/meanas/fdtd/pml.py b/meanas/fdtd/pml.py index 65d71e6..9c3aec5 100644 --- a/meanas/fdtd/pml.py +++ b/meanas/fdtd/pml.py @@ -7,7 +7,8 @@ PML implementations """ # TODO retest pmls! -from typing import Callable, Sequence, Any +from typing import Any +from collections.abc import Callable, Sequence from copy import deepcopy import numpy from numpy.typing import NDArray, DTypeLike