diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 665a5a957..eddd28835 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,6 +30,12 @@ repos: args: [--fix, --exit-non-zero-on-fix] - id: ruff-format groups: [format] + - repo: https://github.com/jsh9/pydoclint + rev: 0.12.0 + hooks: + # Checks docstring parameters against signatures. Options live in [tool.pydoclint] in pyproject.toml. + - id: pydoclint + files: ^src/ - repo: local hooks: - id: mypy diff --git a/pyproject.toml b/pyproject.toml index c034b9058..2d4989fb4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -277,9 +277,24 @@ lint.per-file-ignores."tests/*" = [ "B024", "D", "PT" ] lint.per-file-ignores."tests/conftest.py" = [ "E402" ] lint.per-file-ignores."tests/test_models/test_models.py" = [ "NPY002" ] lint.unfixable = [ "B", "BLE", "C4", "RET", "T20", "UP" ] +lint.external = [ "DOC1" ] # pydoclint parameter checks, see [tool.pydoclint] lint.isort.required-imports = [ "from __future__ import annotations" ] lint.pydocstyle.convention = "numpy" +[tool.pydoclint] +# Check that documented parameters match the function signature (missing or stale names, #1303), +# and that Returns/Yields sections exist. Types (they live in the signatures), order and raises are not checked. +# Docstrings with only a summary (no Parameters section) are skipped. +style = "numpy" +allow-init-docstring = true +arg-type-hints-in-docstring = false +check-return-types = false +check-yield-types = false +skip-checking-raises = true +check-class-attributes = false +check-arg-order = false +omit-stars-when-documenting-varargs = true + [tool.mypy] # TODO: extend to "tests" once the test suite carries type annotations. files = [ "src" ] diff --git a/src/spatialdata/_core/query/spatial_query.py b/src/spatialdata/_core/query/spatial_query.py index b7e7f4ff5..5bd08a01f 100644 --- a/src/spatialdata/_core/query/spatial_query.py +++ b/src/spatialdata/_core/query/spatial_query.py @@ -525,7 +525,7 @@ def bounding_box_query( Shapes are not cut to the bounding box: a shape that intersects it is returned whole. For a `MultiPolygon` this includes components that lie entirely outside the bounding box. To cut the shapes to the bounding box, use :func:`polygon_query` with `clip=True` and the bounding box as polygon, e.g. `shapely.box(xmin, ymin, xmax, ymax)`. - """ + """ # noqa: DOC101, DOC103 (**kwargs only exists for singledispatch; nothing extra is accepted) raise RuntimeError("Unsupported type for bounding_box_query: " + str(type(element)) + ".") diff --git a/src/spatialdata/models/models.py b/src/spatialdata/models/models.py index 6d17c32e2..e3d9c66c9 100644 --- a/src/spatialdata/models/models.py +++ b/src/spatialdata/models/models.py @@ -636,7 +636,7 @@ def parse(cls, data: Any, **kwargs: Any) -> GeoDataFrame: Returns ------- :class:`geopandas.GeoDataFrame` - """ + """ # noqa: DOC102, DOC103 (parameters of the registered implementations) raise TypeError(f"ShapesModel.parse() does not support the type {type(data)}") @parse.register(np.ndarray) @@ -802,7 +802,7 @@ def parse(cls, data: Any, **kwargs: Any) -> DaskDataFrame: ----- The order of the columns of the dataframe returned by the parser is not guaranteed to be the same as the order of the columns in the dataframe passed as an argument. - """ + """ # noqa: DOC102, DOC103 (parameters of the registered implementations) raise TypeError(f"PointsModel.parse() does not support the type {type(data)}") @parse.register(np.ndarray)