Skip to content

Issue #1877 type hints common module#1878

Merged
JoerivanEngelen merged 14 commits into
masterfrom
issue_#1877_type_hints_common_module
Jul 8, 2026
Merged

Issue #1877 type hints common module#1878
JoerivanEngelen merged 14 commits into
masterfrom
issue_#1877_type_hints_common_module

Conversation

@JoerivanEngelen

@JoerivanEngelen JoerivanEngelen commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #1877

Description

Fix mypy errors for common module

Checklist

  • Links to correct issue
  • Update changelog, if changes affect users
  • PR title starts with Issue #nr, e.g. Issue #737
  • Unit tests were added
  • If feature added: Added/extended example
  • If feature added: Added feature to API documentation
  • If pixi.lock was changed: Ran pixi run generate-sbom and committed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to bring the imod.common module under mypy checking (by removing its exclusion) and resolves the resulting typing errors by tightening/adjusting annotations across common utilities, serializers, and a few related interfaces.

Changes:

  • Enabled mypy checking for imod.common.* by removing it from mypy overrides.
  • Added/adjusted type annotations in imod.common utilities (schemata, regrid, mask, dtype, etc.) to satisfy mypy.
  • Minor typing cleanups in serializers and interfaces (e.g., encoding dict types, options return type, validate parameters).

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pyproject.toml Removes mypy override excluding imod.common.* so mypy checks this module.
imod/msw/model.py Tightens validate parameter type to bool.
imod/common/utilities/value_filters.py Forces scalar variable names to str for list[str] typing.
imod/common/utilities/schemata.py Adjusts schemata helper typing (but currently narrows too far; see comments).
imod/common/utilities/regrid.py Refactors regrid-method extraction for typing and adjusts defaultdict typing.
imod/common/utilities/mask.py Adds/clarifies typing for masking and alignment results.
imod/common/utilities/dump_model.py Tightens validate type and adds typing for toml content structure.
imod/common/utilities/dtype.py Changes dtype parameter typing (currently too narrow; see comments).
imod/common/utilities/dataclass_type.py Improves Protocol field/return typing for dataclass-like objects.
imod/common/utilities/clip.py Removes an extra mypy ignore code (misc).
imod/common/serializer/zarrserializer.py Adds local variable type annotations for zip/non-zip store handling.
imod/common/serializer/netcdfserializer.py Narrows return type for netcdf encoding mapping.
imod/common/interfaces/imodel.py Types options property as dict[str, Any].
Comments suppressed due to low confidence (1)

imod/common/utilities/dtype.py:35

  • For consistency with is_float (and to support pandas extension dtypes used in tests), is_bool should accept a broader dtype type than np.dtype (e.g. Any).
def is_bool(dtype: np.dtype) -> bool:
    try:
        return np.issubdtype(dtype, np.bool_)
    except TypeError:
        return issubclass(dtype.type, np.bool)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread imod/common/utilities/schemata.py
Comment thread imod/common/utilities/dtype.py
Comment thread imod/common/utilities/dtype.py Outdated
Comment on lines +166 to +172
def __get_regrid_methods_as_dict(package: IRegridPackage) -> dict[str, RegridVarType]:
"""
Returns the regrid methods of a package as a dictionary. Separated function
to set an ignore for mypy.
"""
regrid_methods = package.get_regrid_methods()
return asdict(regrid_methods) # type: ignore[arg-type]
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@JoerivanEngelen JoerivanEngelen merged commit 72c8c00 into master Jul 8, 2026
3 of 8 checks passed
@JoerivanEngelen JoerivanEngelen deleted the issue_#1877_type_hints_common_module branch July 8, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add type hints for common module

2 participants