Skip to content

Commit 945a30c

Browse files
committed
Upgrade mypy to 1.15
Mypy 1.15 includes fix for <python/mypy#9031>, allowing several "type: ignore" comments to be removed.
1 parent d57f05c commit 945a30c

File tree

5 files changed

+35
-24
lines changed

5 files changed

+35
-24
lines changed

.github/workflows/ci-additional.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
python xarray/util/print_versions.py
117117
- name: Install mypy
118118
run: |
119-
python -m pip install "mypy==1.13" --force-reinstall
119+
python -m pip install mypy
120120
121121
- name: Run mypy
122122
run: |
@@ -125,7 +125,7 @@ jobs:
125125
- name: Upload mypy coverage to Codecov
126126
uses: codecov/codecov-action@v5.3.1
127127
with:
128-
file: mypy_report/cobertura.xml
128+
files: mypy_report/cobertura.xml
129129
flags: mypy
130130
env_vars: PYTHON_VERSION
131131
name: codecov-umbrella
@@ -167,7 +167,7 @@ jobs:
167167
python xarray/util/print_versions.py
168168
- name: Install mypy
169169
run: |
170-
python -m pip install "mypy==1.13" --force-reinstall
170+
python -m pip install mypy
171171
172172
- name: Run mypy
173173
run: |
@@ -176,7 +176,7 @@ jobs:
176176
- name: Upload mypy coverage to Codecov
177177
uses: codecov/codecov-action@v5.3.1
178178
with:
179-
file: mypy_report/cobertura.xml
179+
files: mypy_report/cobertura.xml
180180
flags: mypy-min
181181
env_vars: PYTHON_VERSION
182182
name: codecov-umbrella

.pre-commit-config.yaml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,37 @@ repos:
4242
- id: prettier
4343
args: [--cache-location=.prettier_cache/cache]
4444
- repo: https://github.com/pre-commit/mirrors-mypy
45-
rev: v1.14.1
45+
rev: v1.15.0
4646
hooks:
4747
- id: mypy
48-
# Copied from setup.cfg
49-
exclude: "properties|asv_bench"
48+
files: "^xarray"
49+
exclude: "^xarray/util/generate_.*\\.py$"
5050
# This is slow and so we take it out of the fast-path; requires passing
5151
# `--hook-stage manual` to pre-commit
5252
stages: [manual]
53-
additional_dependencies: [
54-
# Type stubs
55-
types-python-dateutil,
56-
types-setuptools,
57-
types-PyYAML,
58-
types-pytz,
59-
typing-extensions>=4.1.0,
60-
numpy,
61-
]
53+
additional_dependencies:
54+
# Type stubs plus additional dependencies from ci/requirements/environment.yml
55+
# required in order to satisfy most (ideally all) type checks. This is rather
56+
# brittle, so it is difficult (if not impossible) to get mypy to succeed in
57+
# this context, even when it succeeds in CI.
58+
- dask
59+
- distributed
60+
- hypothesis
61+
- matplotlib
62+
- numpy==2.1.3
63+
- pandas-stubs
64+
- pytest
65+
- types-colorama
66+
- types-defusedxml
67+
- types-docutils
68+
- types-pexpect
69+
- types-psutil
70+
- types-Pygments
71+
- types-python-dateutil
72+
- types-pytz
73+
- types-PyYAML
74+
- types-setuptools
75+
- typing-extensions>=4.1.0
6276
- repo: https://github.com/citation-file-format/cff-converter-python
6377
rev: ebf0b5e44d67f8beaa1cd13a0d0393ea04c6058d
6478
hooks:

xarray/core/groupby.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ def reduce_array(ar: DataArray) -> DataArray:
16071607

16081608

16091609
# https://github.com/python/mypy/issues/9031
1610-
class DataArrayGroupBy( # type: ignore[misc]
1610+
class DataArrayGroupBy(
16111611
DataArrayGroupByBase,
16121612
DataArrayGroupByAggregations,
16131613
ImplementsArrayReduce,
@@ -1774,8 +1774,7 @@ def assign(self, **kwargs: Any) -> Dataset:
17741774
return self.map(lambda ds: ds.assign(**kwargs))
17751775

17761776

1777-
# https://github.com/python/mypy/issues/9031
1778-
class DatasetGroupBy( # type: ignore[misc]
1777+
class DatasetGroupBy(
17791778
DatasetGroupByBase,
17801779
DatasetGroupByAggregations,
17811780
ImplementsDatasetReduce,

xarray/core/indexing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def __init__(self, key: tuple[slice | np.ndarray[Any, np.dtype[np.generic]], ...
480480
)
481481
if ndim is None:
482482
ndim = k.ndim # type: ignore[union-attr]
483-
elif ndim != k.ndim:
483+
elif ndim != k.ndim: # type: ignore[union-attr]
484484
ndims = [k.ndim for k in key if isinstance(k, np.ndarray)]
485485
raise ValueError(
486486
"invalid indexer key: ndarray arguments "

xarray/core/resample.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ def _interpolate(self, kind="linear", **kwargs) -> T_Xarray:
232232
)
233233

234234

235-
# https://github.com/python/mypy/issues/9031
236-
class DataArrayResample( # type: ignore[misc]
235+
class DataArrayResample(
237236
Resample["DataArray"], DataArrayGroupByBase, DataArrayResampleAggregations
238237
):
239238
"""DataArrayGroupBy object specialized to time resampling operations over a
@@ -375,8 +374,7 @@ def asfreq(self) -> DataArray:
375374
return self.mean(None if self._dim is None else [self._dim])
376375

377376

378-
# https://github.com/python/mypy/issues/9031
379-
class DatasetResample( # type: ignore[misc]
377+
class DatasetResample(
380378
Resample["Dataset"], DatasetGroupByBase, DatasetResampleAggregations
381379
):
382380
"""DatasetGroupBy object specialized to resampling a specified dimension"""

0 commit comments

Comments
 (0)