Skip to content

Commit 0e5e3fe

Browse files
authored
Enable mypy warn unused ignores (#7335)
* warn unused ignores in mypy * fix tyoe ignores in typed ops * fix mypy issues * fix one more mypy issue
1 parent 0aee4fe commit 0e5e3fe

22 files changed

+84
-86
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ exclude_lines = ["pragma: no cover", "if TYPE_CHECKING"]
2727
exclude = 'xarray/util/generate_.*\.py'
2828
files = "xarray"
2929
show_error_codes = true
30+
warn_unused_ignores = true
3031

3132
# Most of the numerical computing stack doesn't have type annotations yet.
3233
[[tool.mypy.overrides]]

xarray/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from importlib.metadata import version as _version
4141
except ImportError:
4242
# if the fallback library is missing, we are doomed.
43-
from importlib_metadata import version as _version # type: ignore[no-redef]
43+
from importlib_metadata import version as _version
4444

4545
try:
4646
__version__ = _version("xarray")

xarray/backends/locks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def _get_lock_maker(scheduler=None):
6161
try:
6262
from dask.distributed import Lock as DistributedLock
6363
except ImportError:
64-
DistributedLock = None # type: ignore
64+
DistributedLock = None
6565
return DistributedLock
6666
else:
6767
raise KeyError(scheduler)

xarray/core/_typed_ops.pyi

Lines changed: 52 additions & 52 deletions
Large diffs are not rendered by default.

xarray/core/alignment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ def _get_dim_pos_indexers(
490490
obj_idx = matching_indexes.get(key)
491491
if obj_idx is not None:
492492
if self.reindex[key]:
493-
indexers = obj_idx.reindex_like(aligned_idx, **self.reindex_kwargs) # type: ignore[call-arg]
493+
indexers = obj_idx.reindex_like(aligned_idx, **self.reindex_kwargs)
494494
dim_pos_indexers.update(indexers)
495495

496496
return dim_pos_indexers

xarray/core/combine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def _nested_combine(
377377

378378
# Define type for arbitrarily-nested list of lists recursively
379379
# Currently mypy cannot handle this but other linters can (https://stackoverflow.com/a/53845083/3154101)
380-
DATASET_HYPERCUBE = Union[Dataset, Iterable["DATASET_HYPERCUBE"]] # type: ignore
380+
DATASET_HYPERCUBE = Union[Dataset, Iterable["DATASET_HYPERCUBE"]] # type: ignore[misc]
381381

382382

383383
def combine_nested(

xarray/core/computation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,7 @@ def dot(
17341734
dim_counts.update(arr.dims)
17351735
dims = tuple(d for d, c in dim_counts.items() if c > 1)
17361736

1737-
dot_dims: set[Hashable] = set(dims) # type:ignore[arg-type]
1737+
dot_dims: set[Hashable] = set(dims)
17381738

17391739
# dimensions to be parallelized
17401740
broadcast_dims = common_dims - dot_dims

xarray/core/coordinates.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ def dtypes(self) -> Frozen[Hashable, np.dtype]:
5454

5555
@property
5656
def indexes(self) -> Indexes[pd.Index]:
57-
return self._data.indexes # type: ignore[attr-defined]
57+
return self._data.indexes
5858

5959
@property
6060
def xindexes(self) -> Indexes[Index]:
61-
return self._data.xindexes # type: ignore[attr-defined]
61+
return self._data.xindexes
6262

6363
@property
6464
def variables(self):
@@ -116,11 +116,9 @@ def to_index(self, ordered_dims: Sequence[Hashable] | None = None) -> pd.Index:
116116
raise ValueError("no valid index for a 0-dimensional object")
117117
elif len(ordered_dims) == 1:
118118
(dim,) = ordered_dims
119-
return self._data.get_index(dim) # type: ignore[attr-defined]
119+
return self._data.get_index(dim)
120120
else:
121-
indexes = [
122-
self._data.get_index(k) for k in ordered_dims # type: ignore[attr-defined]
123-
]
121+
indexes = [self._data.get_index(k) for k in ordered_dims]
124122

125123
# compute the sizes of the repeat and tile for the cartesian product
126124
# (taken from pandas.core.reshape.util)

xarray/core/dataarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ def __init__(
428428

429429
# TODO(shoyer): document this argument, once it becomes part of the
430430
# public interface.
431-
self._indexes = indexes # type: ignore[assignment]
431+
self._indexes = indexes
432432

433433
self._close = None
434434

xarray/core/groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ def _flox_reduce(
713713
elif dim is ...:
714714
parsed_dim = tuple(self._original_obj.dims)
715715
else:
716-
parsed_dim = tuple(dim) # type:ignore[arg-type]
716+
parsed_dim = tuple(dim)
717717

718718
# Do this so we raise the same error message whether flox is present or not.
719719
# Better to control it here than in flox.
@@ -747,7 +747,7 @@ def _flox_reduce(
747747
result = xarray_reduce(
748748
self._original_obj.drop_vars(non_numeric),
749749
group,
750-
dim=parsed_dim, # type:ignore[arg-type] # https://github.com/xarray-contrib/flox/issues/96
750+
dim=parsed_dim,
751751
expected_groups=expected_groups,
752752
isbin=isbin,
753753
keep_attrs=keep_attrs,

0 commit comments

Comments
 (0)