Issue #1877 type hints common module#1878
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.commonutilities (schemata, regrid, mask, dtype, etc.) to satisfy mypy. - Minor typing cleanups in serializers and interfaces (e.g., encoding dict types,
optionsreturn type,validateparameters).
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_boolshould accept a broader dtype type thannp.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 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] |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #1877
Description
Fix mypy errors for
commonmoduleChecklist
Issue #nr, e.g.Issue #737pixi run generate-sbomand committed changes