From d9d63dc9247971e51afb6bab76f95e1e1411d344 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Thu, 26 Dec 2024 17:24:39 +0000 Subject: [PATCH] Add recommended mypy config (#71) * Improve TOC structure * Add recommended mypy config * Add pytest to mypy deps * Fix unreachable messages * Add pydantic zarr to type checking * Remove unused comments * Add a py.typed file * Ignore subclssing any warnings --- .pre-commit-config.yaml | 9 +++++++++ pyproject.toml | 2 ++ src/ome_zarr_models/py.typed | 0 src/ome_zarr_models/v04/hcs.py | 2 +- src/ome_zarr_models/v04/image.py | 2 +- src/ome_zarr_models/v04/image_label.py | 2 +- src/ome_zarr_models/v04/labels.py | 2 +- src/ome_zarr_models/v04/well.py | 2 +- tests/v04/test_multiscales.py | 2 +- 9 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/ome_zarr_models/py.typed diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 170b66a..8f23ec5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,3 +38,12 @@ repos: rev: 0.7.21 # 0.7.19 hooks: - id: mdformat + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: f56614daa94d5cd733d3b7004c5df9caad267b4a # 1.13.0 + hooks: + - id: mypy + additional_dependencies: + - pydantic + - pytest + - pydantic-zarr diff --git a/pyproject.toml b/pyproject.toml index 4de4244..73a89a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,7 +95,9 @@ skip-magic-trailing-comma = false # default is false [tool.mypy] strict = true +warn_unreachable = true plugins = ['pydantic.mypy'] +enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] [[tool.mypy.overrides]] module = ["zarr.*", "pydantic_zarr.*"] diff --git a/src/ome_zarr_models/py.typed b/src/ome_zarr_models/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/src/ome_zarr_models/v04/hcs.py b/src/ome_zarr_models/v04/hcs.py index c460d67..6690432 100644 --- a/src/ome_zarr_models/v04/hcs.py +++ b/src/ome_zarr_models/v04/hcs.py @@ -19,7 +19,7 @@ class HCSAttrs(Base): plate: Plate -class HCS(GroupSpec[HCSAttrs, ArraySpec | GroupSpec]): +class HCS(GroupSpec[HCSAttrs, ArraySpec | GroupSpec]): # type: ignore[misc] """ An OME-zarr high-content screening (HCS) dataset representing a single plate. """ diff --git a/src/ome_zarr_models/v04/image.py b/src/ome_zarr_models/v04/image.py index a85aee5..80fc399 100644 --- a/src/ome_zarr_models/v04/image.py +++ b/src/ome_zarr_models/v04/image.py @@ -74,7 +74,7 @@ class ImageAttrs(Base): omero: Omero | None = None -class Image(GroupSpec[ImageAttrs, ArraySpec | GroupSpec]): +class Image(GroupSpec[ImageAttrs, ArraySpec | GroupSpec]): # type: ignore[misc] """ An OME-zarr multiscale dataset. """ diff --git a/src/ome_zarr_models/v04/image_label.py b/src/ome_zarr_models/v04/image_label.py index c992add..22c8725 100644 --- a/src/ome_zarr_models/v04/image_label.py +++ b/src/ome_zarr_models/v04/image_label.py @@ -119,7 +119,7 @@ class ImageLabelAttrs(Base): multiscales: list[Multiscale] -class ImageLabel(GroupSpec[ImageLabelAttrs, ArraySpec | GroupSpec]): +class ImageLabel(GroupSpec[ImageLabelAttrs, ArraySpec | GroupSpec]): # type: ignore[misc] _check_arrays_compatible = model_validator(mode="after")(_check_arrays_compatible) @classmethod diff --git a/src/ome_zarr_models/v04/labels.py b/src/ome_zarr_models/v04/labels.py index 5dd88e9..db81728 100644 --- a/src/ome_zarr_models/v04/labels.py +++ b/src/ome_zarr_models/v04/labels.py @@ -20,7 +20,7 @@ class LabelsAttrs(Base): ) -class Labels(GroupSpec[LabelsAttrs, ArraySpec | GroupSpec]): +class Labels(GroupSpec[LabelsAttrs, ArraySpec | GroupSpec]): # type: ignore[misc] """ An OME-zarr labels dataset. """ diff --git a/src/ome_zarr_models/v04/well.py b/src/ome_zarr_models/v04/well.py index 1822187..179b6ce 100644 --- a/src/ome_zarr_models/v04/well.py +++ b/src/ome_zarr_models/v04/well.py @@ -72,7 +72,7 @@ class WellAttrs(Base): well: Well -class WellGroup(GroupSpec[WellAttrs, ArraySpec | GroupSpec]): +class WellGroup(GroupSpec[WellAttrs, ArraySpec | GroupSpec]): # type: ignore[misc] def get_image(self, i: int) -> Image: """ Get a single image from this well. diff --git a/tests/v04/test_multiscales.py b/tests/v04/test_multiscales.py index 0614989..833a6a5 100644 --- a/tests/v04/test_multiscales.py +++ b/tests/v04/test_multiscales.py @@ -273,7 +273,7 @@ def test_transform_invalid_second_element( match="The second element of `coordinateTransformations` " "must be a translation transform", ): - Dataset(path="foo", coordinateTransformations=transforms) # type: ignore[arg-type] + Dataset(path="foo", coordinateTransformations=transforms) def test_validate_axes_top_transforms() -> None: