Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modules to check-untyped #8242

Merged
merged 8 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,48 @@ module = [
]

# Gradually we want to add more modules to this list, ratcheting up our total
# coverage. Once a module is here, functions require annotations in order to
# pass mypy. It would be especially useful to have tests here, because without
# annotating test functions, we don't have a great way of testing our type
# annotations — even with just `-> None` is sufficient for mypy to check them.
# coverage. Once a module is here, functions are checked by mypy regardless of
# whether they have type annotations. It would be especially useful to have test
# files listed here, because without them being checked, we don't have a great
# way of testing our annotations.
[[tool.mypy.overrides]]
disallow_untyped_defs = true
max-sixty marked this conversation as resolved.
Show resolved Hide resolved
module = ["xarray.core.rolling_exp"]
check_untyped_defs = true
module = [
"xarray.core.accessor_dt",
"xarray.core.accessor_str",
"xarray.core.alignment",
"xarray.core.computation",
"xarray.core.rolling_exp",
"xarray.indexes.*",
"xarray.tests.*",
]
# This then excludes some modules from the above list. (So ideally we remove
# from here in time...)
[[tool.mypy.overrides]]
check_untyped_defs = false
module = [
"xarray.tests.test_coarsen",
"xarray.tests.test_coding_times",
"xarray.tests.test_combine",
"xarray.tests.test_computation",
"xarray.tests.test_concat",
"xarray.tests.test_coordinates",
"xarray.tests.test_dask",
"xarray.tests.test_dataarray",
"xarray.tests.test_duck_array_ops",
"xarray.tests.test_groupby",
"xarray.tests.test_indexing",
"xarray.tests.test_merge",
"xarray.tests.test_missing",
"xarray.tests.test_parallelcompat",
"xarray.tests.test_plot",
"xarray.tests.test_sparse",
"xarray.tests.test_ufuncs",
"xarray.tests.test_units",
"xarray.tests.test_utils",
"xarray.tests.test_variable",
"xarray.tests.test_weighted",
]

[tool.ruff]
builtins = ["ellipsis"]
Expand Down
11 changes: 6 additions & 5 deletions xarray/core/computation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import operator
import warnings
from collections import Counter
from collections.abc import Hashable, Iterable, Mapping, Sequence, Set
from collections.abc import Hashable, Iterable, Iterator, Mapping, Sequence, Set
from typing import TYPE_CHECKING, Any, Callable, Literal, TypeVar, Union, overload

import numpy as np
Expand Down Expand Up @@ -163,7 +163,7 @@ def to_gufunc_string(self, exclude_dims=frozenset()):
if exclude_dims:
exclude_dims = [self.dims_map[dim] for dim in exclude_dims]

counter = Counter()
counter: Counter = Counter()

def _enumerate(dim):
if dim in exclude_dims:
Expand Down Expand Up @@ -571,7 +571,7 @@ def apply_groupby_func(func, *args):
assert groupbys, "must have at least one groupby to iterate over"
first_groupby = groupbys[0]
(grouper,) = first_groupby.groupers
if any(not grouper.group.equals(gb.groupers[0].group) for gb in groupbys[1:]):
if any(not grouper.group.equals(gb.groupers[0].group) for gb in groupbys[1:]): # type: ignore[union-attr]
raise ValueError(
"apply_ufunc can only perform operations over "
"multiple GroupBy objects at once if they are all "
Expand All @@ -583,6 +583,7 @@ def apply_groupby_func(func, *args):

iterators = []
for arg in args:
iterator: Iterator[Any]
if isinstance(arg, GroupBy):
iterator = (value for _, value in arg)
elif hasattr(arg, "dims") and grouped_dim in arg.dims:
Expand All @@ -597,9 +598,9 @@ def apply_groupby_func(func, *args):
iterator = itertools.repeat(arg)
iterators.append(iterator)

applied = (func(*zipped_args) for zipped_args in zip(*iterators))
applied: Iterator = (func(*zipped_args) for zipped_args in zip(*iterators))
applied_example, applied = peek_at(applied)
combine = first_groupby._combine
combine = first_groupby._combine # type: ignore[attr-defined]
if isinstance(applied_example, tuple):
combined = tuple(combine(output) for output in zip(*applied))
else:
Expand Down
2 changes: 1 addition & 1 deletion xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,7 @@ def __iter__(self) -> Iterator[Hashable]:
if TYPE_CHECKING:
# needed because __getattr__ is returning Any and otherwise
# this class counts as part of the SupportsArray Protocol
__array__ = None
__array__ = None # type: ignore[var-annotated,unused-ignore]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

FYI I was getting this locally but not in CI — not sure why — but on balance seems reasonable to exclude. Possible a dependency issue; we can try removing some of these ignore[unused-ignore] in the future manually, given they definitionally elude our other checks...


else:

Expand Down