Skip to content

Commit

Permalink
Require future annotations import, fix ruff fallout
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Sep 18, 2024
1 parent 3d850bc commit 773abeb
Show file tree
Hide file tree
Showing 41 changed files with 185 additions and 104 deletions.
2 changes: 2 additions & 0 deletions contrib/pov-nodes/nodal_points.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import numpy as np
from pov import (
Background,
Expand Down
2 changes: 2 additions & 0 deletions contrib/pov-nodes/pov.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/205451
from __future__ import annotations

import os

import numpy as np
Expand Down
1 change: 1 addition & 0 deletions contrib/weights-from-festa-sommariva.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
These rules are licensed under the GPL and are not included by default.
"""
from __future__ import annotations

import re

Expand Down
1 change: 1 addition & 0 deletions contrib/weights-from-fortran.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /usr/bin/env python
from __future__ import annotations

import re

Expand Down
4 changes: 2 additions & 2 deletions contrib/weights-from-jaskowiec-sukumar.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
The quadrature rules can be found in the supplemental material at the same
URL and should be a file named ``nme6528-sup-0002-supinfo.tar``.
"""
from __future__ import annotations

import pathlib
import re
import sys
import tarfile
from typing import Optional


FILE_ORDER_REGEX = re.compile(r"cubature_tet_sym_p(\d{1,2})_n\d{1,3}_expand.txt")
Expand Down Expand Up @@ -64,7 +64,7 @@ def extract_rules_if_not(path: pathlib.Path) -> pathlib.Path:


def generate_jaskowiec_sukumar_quadrature_rules(
infolder: pathlib.Path, outfile: Optional[pathlib.Path] = None
infolder: pathlib.Path, outfile: pathlib.Path | None = None
) -> None:
import numpy as np

Expand Down
1 change: 1 addition & 0 deletions contrib/weights-from-txt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#! /usr/bin/env python
from __future__ import annotations

import sys

Expand Down
1 change: 1 addition & 0 deletions contrib/weights-from-witherden-vincent.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
They are available under a Creative Commons license.
"""
from __future__ import annotations

import os

Expand Down
2 changes: 2 additions & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from importlib import metadata
from urllib.request import urlopen

Expand Down
2 changes: 2 additions & 0 deletions examples/derivative.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import numpy as np

import modepy as mp
Expand Down
2 changes: 2 additions & 0 deletions examples/plot-basis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import matplotlib.pyplot as pt
import numpy as np

Expand Down
2 changes: 2 additions & 0 deletions examples/plot-nodes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import matplotlib.pyplot as pt
import numpy as np

Expand Down
2 changes: 2 additions & 0 deletions examples/plot-quadrature-nodes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import matplotlib.pyplot as plt
import numpy as np

Expand Down
2 changes: 2 additions & 0 deletions examples/plot-warp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import matplotlib.pyplot as pt
import numpy as np

Expand Down
3 changes: 3 additions & 0 deletions modepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


__copyright__ = """Copyright (C) 2009, 2010, 2013 Andreas Kloeckner, Tim Warburton,
Jan Hesthaven, Xueyu Zhu"""

Expand Down
21 changes: 12 additions & 9 deletions modepy/matrices.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


__copyright__ = "Copyright (C) 2013 Andreas Kloeckner"

__license__ = """
Expand All @@ -21,7 +24,7 @@
"""


from typing import Callable, Optional, Sequence, Tuple, Union
from typing import Callable, Sequence
from warnings import warn

import numpy as np
Expand Down Expand Up @@ -117,7 +120,7 @@ def vandermonde(
def multi_vandermonde(
functions: Sequence[Callable[[np.ndarray], Sequence[np.ndarray]]],
nodes: np.ndarray
) -> Tuple[np.ndarray, ...]:
) -> tuple[np.ndarray, ...]:
"""Evaluate multiple (generalized) Vandermonde matrices.
The Vandermonde Matrix is given by :math:`V_{i,j} := f_j(x_i)`
Expand Down Expand Up @@ -213,8 +216,8 @@ def differentiation_matrices(
basis: Sequence[Callable[[np.ndarray], np.ndarray]],
grad_basis: Sequence[Callable[[np.ndarray], Sequence[np.ndarray]]],
nodes: np.ndarray,
from_nodes: Optional[np.ndarray] = None
) -> Tuple[np.ndarray, ...]:
from_nodes: np.ndarray | None = None
) -> tuple[np.ndarray, ...]:
"""Return matrices carrying out differentiation on nodal values in the
:math:`(r,s,t)` unit directions. (See :ref:`tri-coords` and
:ref:`tet-coords`.)
Expand Down Expand Up @@ -253,7 +256,7 @@ def differentiation_matrices(
def diff_matrices(
basis: Basis,
nodes: np.ndarray,
from_nodes: Optional[np.ndarray] = None
from_nodes: np.ndarray | None = None
):
"""Like :func:`differentiation_matrices`, but for a given :class:`~modepy.Basis`.
Expand All @@ -264,7 +267,7 @@ def diff_matrices(


def diff_matrix_permutation(
node_tuples: Sequence[Tuple[int, ...]],
node_tuples: Sequence[tuple[int, ...]],
ref_axis: int
) -> np.ndarray:
"""Return a :mod:`numpy` array *permutation* of integers so that::
Expand All @@ -290,7 +293,7 @@ def diff_matrix_permutation(


def inverse_mass_matrix(
basis: Union[Basis, Sequence[Callable[[np.ndarray], np.ndarray]]],
basis: Basis | Sequence[Callable[[np.ndarray], np.ndarray]],
nodes: np.ndarray
) -> np.ndarray:
"""Return a matrix :math:`A=M^{-1}`, which is the inverse of the one returned
Expand Down Expand Up @@ -325,7 +328,7 @@ def inverse_mass_matrix(


def mass_matrix(
basis: Union[Basis, Sequence[Callable[[np.ndarray], np.ndarray]]],
basis: Basis | Sequence[Callable[[np.ndarray], np.ndarray]],
nodes: np.ndarray
) -> np.ndarray:
r"""Return a mass matrix :math:`M`, which obeys
Expand Down Expand Up @@ -370,7 +373,7 @@ def modal_quad_mass_matrix(
def nodal_quad_mass_matrix(
quadrature: Quadrature,
test_functions: Sequence[Callable[[np.ndarray], np.ndarray]],
nodes: Optional[np.ndarray] = None,
nodes: np.ndarray | None = None,
) -> np.ndarray:
r"""Using the *quadrature*, provide a matrix :math:`M` that
satisfies:
Expand Down
8 changes: 5 additions & 3 deletions modepy/modal_decay.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


__copyright__ = "Copyright (C) 2010-2012 Andreas Kloeckner"

__license__ = """
Expand All @@ -20,7 +23,6 @@
THE SOFTWARE.
"""

from typing import Tuple

import numpy as np
import numpy.linalg as la
Expand Down Expand Up @@ -88,7 +90,7 @@ def simplex_interp_error_coefficient_estimator_matrix(


def make_mode_number_vector(
mode_order_tuples: Tuple[Tuple[int, ...], ...],
mode_order_tuples: tuple[tuple[int, ...], ...],
ignored_modes: int) -> np.ndarray:
node_cnt = len(mode_order_tuples)

Expand Down Expand Up @@ -152,7 +154,7 @@ def skyline_pessimize(modal_values: np.ndarray) -> np.ndarray:

def fit_modal_decay(
coeffs: np.ndarray, dims: int, n: int,
ignored_modes: int = 1) -> Tuple[np.ndarray, np.ndarray]:
ignored_modes: int = 1) -> tuple[np.ndarray, np.ndarray]:
"""Fit a curve to the modal decay on each element.
:arg coeffs: an array of shape ``(num_elements, num_modes)`` containing modal
Expand Down
Loading

0 comments on commit 773abeb

Please sign in to comment.