Skip to content

Commit

Permalink
Disable disallow_any_generics for mypy (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
paddyroddy authored Nov 17, 2023
1 parent 6755f15 commit ffea540
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 20 deletions.
4 changes: 3 additions & 1 deletion examples/polar_cap/simons_5_1.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typing

import matplotlib.pyplot as plt
import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -47,7 +49,7 @@ def main() -> None:


def _helper( # noqa: PLR0913
ax: npt.NDArray,
ax: npt.NDArray[typing.Any],
slepian: sleplet.slepian.SlepianPolarCap,
resolution: int,
x: npt.NDArray[np.float_],
Expand Down
6 changes: 5 additions & 1 deletion examples/polar_cap/simons_5_3.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typing

import matplotlib.pyplot as plt
import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -28,7 +30,9 @@ def main() -> None:
plt.close()


def _create_plot(ax: npt.NDArray, position: tuple[int, int], theta_max: int) -> None:
def _create_plot(
ax: npt.NDArray[typing.Any], position: tuple[int, int], theta_max: int
) -> None:
"""Create the plot."""
print(f"theta_max={theta_max}")
slepian = sleplet.slepian.SlepianPolarCap(L, np.deg2rad(theta_max))
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ optional-dependencies = {dev = [
"build",
"mypy",
"pre-commit",
"pytest",
"ruff",
"tox",
"twine",
Expand Down Expand Up @@ -102,7 +103,6 @@ paths.source = [
]

[tool.mypy]
disallow_any_generics = false
disallow_subclassing_any = false
disallow_untyped_decorators = false
explicit_package_bases = true
Expand Down
2 changes: 1 addition & 1 deletion src/sleplet/_data/setup_pooch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
_POOCH.load_registry_from_doi()


def find_on_pooch_then_local(filename: str) -> os.PathLike | None:
def find_on_pooch_then_local(filename: str) -> os.PathLike[str] | None:
"""Find a file on POOCH first and if not look in data folder."""
if filename in _POOCH.registry:
msg = f"Found {filename} at https://doi.org/{_ZENODO_DATA_DOI}"
Expand Down
3 changes: 2 additions & 1 deletion src/sleplet/_mask_methods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import typing

import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -114,7 +115,7 @@ def create_default_region() -> "sleplet.slepian.region.Region":


def create_mesh_region(
mesh_config: dict,
mesh_config: dict[str, typing.Any],
vertices: npt.NDArray[np.float_],
) -> npt.NDArray[np.bool_]:
"""Create a boolean region for the given mesh."""
Expand Down
9 changes: 6 additions & 3 deletions src/sleplet/_mesh_methods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import pathlib
import typing

import igl
import numpy as np
Expand Down Expand Up @@ -40,7 +41,7 @@ def average_functions_on_vertices_to_faces(


def create_mesh_region(
mesh_config: dict,
mesh_config: dict[str, typing.Any],
vertices: npt.NDArray[np.float_],
) -> npt.NDArray[np.bool_]:
"""Create a boolean region for the given mesh."""
Expand All @@ -54,7 +55,7 @@ def create_mesh_region(
)


def extract_mesh_config(mesh_name: str) -> dict:
def extract_mesh_config(mesh_name: str) -> dict[str, float | int | str]:
"""Read in the given mesh region settings file."""
with pathlib.Path.open(
_data_path / f"meshes_regions_{mesh_name}.toml",
Expand Down Expand Up @@ -110,7 +111,9 @@ def mesh_eigendecomposition(
return eigenvalues, eigenvectors, number_basis_functions


def read_mesh(mesh_config: dict) -> tuple[npt.NDArray[np.float_], npt.NDArray[np.int_]]:
def read_mesh(
mesh_config: dict[str, float | int | str]
) -> tuple[npt.NDArray[np.float_], npt.NDArray[np.int_]]:
"""Read in the given mesh."""
vertices, faces = igl.read_triangle_mesh(
str(_data_path / f"meshes_polygons_{mesh_config['FILENAME']}"),
Expand Down
6 changes: 4 additions & 2 deletions src/sleplet/_plotly_methods.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import typing

import plotly.graph_objs as go

_axis = {
Expand Down Expand Up @@ -30,7 +32,7 @@ def create_camera( # noqa: PLR0913
def create_layout(
camera: go.layout.scene.Camera,
*,
annotations: list[dict] | None = None,
annotations: list[dict[str, float | int]] | None = None,
) -> go.Layout:
"""Create the default plotly layout."""
return go.Layout(
Expand Down Expand Up @@ -65,7 +67,7 @@ def create_colour_bar(
bar_len: float = 0.94,
bar_pos: float = 0.97,
font_size: int = 38,
) -> dict:
) -> dict[str, typing.Any]:
"""Create the default plotly colour bar."""
return {
"x": bar_pos,
Expand Down
2 changes: 1 addition & 1 deletion src/sleplet/_scripts/plotting_on_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def _translation_helper(
alpha_pi_frac: float,
beta_pi_frac: float,
shannon: int | None,
) -> tuple[npt.NDArray[np.complex_ | np.float_], str, dict]:
) -> tuple[npt.NDArray[np.complex_ | np.float_], str, dict[str, float | int]]:
"""Perform the translation specific steps."""
msg = f"angles: (alpha, beta) = ({alpha_pi_frac}, {beta_pi_frac})"
_logger.info(msg)
Expand Down
6 changes: 3 additions & 3 deletions src/sleplet/_slepian_arbitrary_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@


def clean_evals_and_evecs(
eigendecomposition: tuple,
eigendecomposition: tuple[npt.NDArray[np.complex_], npt.NDArray[np.complex_]],
) -> tuple[npt.NDArray[np.float_], npt.NDArray[np.complex_]]:
"""Need eigenvalues and eigenvectors to be in a certain format."""
# access values
eigenvalues, eigenvectors = eigendecomposition
eigenvalues_complex, eigenvectors = eigendecomposition

# eigenvalues should be real
eigenvalues = eigenvalues.real
eigenvalues = eigenvalues_complex.real

# Sort eigenvalues and eigenvectors in descending order of eigenvalues
idx = eigenvalues.argsort()[::-1]
Expand Down
10 changes: 9 additions & 1 deletion src/sleplet/_string_methods.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import fractions
import re
import typing

import numpy as np

if typing.TYPE_CHECKING:
import sleplet.functions.coefficients
import sleplet.meshes.mesh_coefficients


def _get_angle_num_dem(angle_fraction: float) -> tuple[int, int]:
"""Get numerator and denominator for a given decimal."""
Expand Down Expand Up @@ -84,7 +89,10 @@ def _convert_camel_case_to_snake_case(name: str) -> str:


def convert_classes_list_to_snake_case(
classes: list,
classes: list[
type["sleplet.functions.coefficients.Coefficients"]
| type["sleplet.meshes.mesh_coefficients.MeshCoefficients"]
],
*,
word_to_remove: str = "",
) -> list[str]:
Expand Down
2 changes: 1 addition & 1 deletion src/sleplet/meshes/mesh_slepian.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def _integral(self: typing_extensions.Self, i: int, j: int) -> float:

@staticmethod
def _clean_evals_and_evecs(
eigendecomposition: tuple,
eigendecomposition: tuple[npt.NDArray[np.float_], npt.NDArray[np.float_]],
) -> tuple[npt.NDArray[np.float_], npt.NDArray[np.float_]]:
"""Need eigenvalues and eigenvectors to be in a certain format."""
# access values
Expand Down
2 changes: 1 addition & 1 deletion src/sleplet/plotting/_create_plot_sphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PlotSphere:
_: dataclasses.KW_ONLY
amplitude: float | None = None
"""Whether to customise the amplitude range of the colour bar."""
annotations: list[dict] = pydantic.Field(default_factory=list)
annotations: list[dict[str, float | int]] = pydantic.Field(default_factory=list)
"""Whether to display any annotations on the surface plot or not."""
normalise: bool = True
"""Whether to normalise the plot or not."""
Expand Down
6 changes: 3 additions & 3 deletions src/sleplet/slepian/slepian_limit_lat_lon.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ def _slepian_matrix(

@staticmethod
def _clean_evals_and_evecs(
eigendecomposition: tuple,
eigendecomposition: tuple[npt.NDArray[np.complex_], npt.NDArray[np.complex_]],
) -> tuple[npt.NDArray[np.float_], npt.NDArray[np.complex_]]:
"""Need eigenvalues and eigenvectors to be in a certain format."""
# access values
eigenvalues, eigenvectors = eigendecomposition
eigenvalues_complex, eigenvectors = eigendecomposition

# eigenvalues should be real
eigenvalues = eigenvalues.real
eigenvalues = eigenvalues_complex.real

# Sort eigenvalues and eigenvectors in descending order of eigenvalues
idx = eigenvalues.argsort()[::-1]
Expand Down

0 comments on commit ffea540

Please sign in to comment.