From bf35bcde61787910d7589cd6f98c5874c9686a22 Mon Sep 17 00:00:00 2001 From: "Patrick J. Roddy" Date: Fri, 24 May 2024 18:19:11 +0100 Subject: [PATCH] Add suggestions from Scientific Python (#379) --- .github/workflows/examples.yaml | 1 + pyproject.toml | 28 +++++++++++++++---- src/sleplet/functions/slepian.py | 3 -- src/sleplet/functions/spherical_harmonic.py | 6 ---- .../meshes/_mesh_slepian_decomposition.py | 3 -- src/sleplet/meshes/mesh_basis_functions.py | 3 -- src/sleplet/meshes/mesh_slepian_functions.py | 3 -- src/sleplet/slepian/_slepian_decomposition.py | 3 -- 8 files changed, 24 insertions(+), 26 deletions(-) diff --git a/.github/workflows/examples.yaml b/.github/workflows/examples.yaml index eec0c73bb..05b8c7b18 100644 --- a/.github/workflows/examples.yaml +++ b/.github/workflows/examples.yaml @@ -7,6 +7,7 @@ on: - main - renovate/** pull_request: + workflow_dispatch: concurrency: cancel-in-progress: true diff --git a/pyproject.toml b/pyproject.toml index b348d6270..c6cb2faa6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -110,6 +110,11 @@ paths.source = [ [tool.mypy] disallow_subclassing_any = false disallow_untyped_decorators = false +enable_error_code = [ + "ignore-without-code", + "redundant-expr", + "truthy-bool", +] explicit_package_bases = true ignore_missing_imports = true plugins = [ @@ -118,20 +123,33 @@ plugins = [ ] strict = true warn_return_any = false +warn_unreachable = true [tool.pytest.ini_options] -addopts = """ - --color=yes - --import-mode=importlib - --verbose -""" +addopts = [ + "--color=yes", + "--import-mode=importlib", + "--strict-config", + "--strict-markers", + "--verbose", + "-ra", +] +filterwarnings = [ + "error", +] +log_cli_level = "INFO" +minversion = 6 testpaths = [ "tests", ] +xfail_strict = true [tool.ruff] fix = true force-exclude = true +src = [ + "src", +] lint.ignore = [ "COM812", "D105", diff --git a/src/sleplet/functions/slepian.py b/src/sleplet/functions/slepian.py index e5a579c1e..e0d28f82d 100644 --- a/src/sleplet/functions/slepian.py +++ b/src/sleplet/functions/slepian.py @@ -82,9 +82,6 @@ def _check_rank( cls, # noqa: ANN101 v: int, ) -> int: - if not isinstance(v, int): - msg = "rank should be an integer" - raise TypeError(msg) if v < 0: msg = "rank cannot be negative" raise ValueError(msg) diff --git a/src/sleplet/functions/spherical_harmonic.py b/src/sleplet/functions/spherical_harmonic.py index 8f01c6e59..998b0288b 100644 --- a/src/sleplet/functions/spherical_harmonic.py +++ b/src/sleplet/functions/spherical_harmonic.py @@ -55,9 +55,6 @@ def _check_ell( v: int, info: pydantic.ValidationInfo, ) -> int: - if not isinstance(v, int): - msg = "ell should be an integer" - raise TypeError(msg) if v < 0: msg = "ell should be positive" raise ValueError(msg) @@ -72,9 +69,6 @@ def _check_m( v: int, info: pydantic.ValidationInfo, ) -> int: - if not isinstance(v, int): - msg = "m should be an integer" - raise TypeError(msg) if abs(v) > info.data["ell"]: msg = "the magnitude of m should be less than ell" raise ValueError(msg) diff --git a/src/sleplet/meshes/_mesh_slepian_decomposition.py b/src/sleplet/meshes/_mesh_slepian_decomposition.py index 3809b9f72..94160194d 100644 --- a/src/sleplet/meshes/_mesh_slepian_decomposition.py +++ b/src/sleplet/meshes/_mesh_slepian_decomposition.py @@ -117,9 +117,6 @@ def _detect_method(self: typing_extensions.Self) -> None: def _validate_rank(self: typing_extensions.Self, rank: int) -> None: """Check the requested rank is valid.""" - if not isinstance(rank, int): - msg = "rank should be an integer" - raise TypeError(msg) if rank < 0: msg = "rank cannot be negative" raise ValueError(msg) diff --git a/src/sleplet/meshes/mesh_basis_functions.py b/src/sleplet/meshes/mesh_basis_functions.py index a29d46d1c..1d4630adc 100644 --- a/src/sleplet/meshes/mesh_basis_functions.py +++ b/src/sleplet/meshes/mesh_basis_functions.py @@ -69,9 +69,6 @@ def _check_rank( cls, # noqa: ANN101 v: int, ) -> int: - if not isinstance(v, int): - msg = "rank should be an integer" - raise TypeError(msg) if v < 0: msg = "rank cannot be negative" raise ValueError(msg) diff --git a/src/sleplet/meshes/mesh_slepian_functions.py b/src/sleplet/meshes/mesh_slepian_functions.py index 1bd29a732..788287edf 100644 --- a/src/sleplet/meshes/mesh_slepian_functions.py +++ b/src/sleplet/meshes/mesh_slepian_functions.py @@ -71,9 +71,6 @@ def _check_rank( cls, # noqa: ANN101 v: int, ) -> int: - if not isinstance(v, int): - msg = "rank should be an integer" - raise TypeError(msg) if v < 0: msg = "rank cannot be negative" raise ValueError(msg) diff --git a/src/sleplet/slepian/_slepian_decomposition.py b/src/sleplet/slepian/_slepian_decomposition.py index ee14ed4c3..79ac29486 100644 --- a/src/sleplet/slepian/_slepian_decomposition.py +++ b/src/sleplet/slepian/_slepian_decomposition.py @@ -123,9 +123,6 @@ def _detect_method(self: typing_extensions.Self) -> None: def _validate_rank(self: typing_extensions.Self, rank: int) -> None: """Check the requested rank is valid.""" - if not isinstance(rank, int): - msg = "rank should be an integer" - raise TypeError(msg) if rank < 0: msg = "rank cannot be negative" raise ValueError(msg)