Skip to content

Commit 5dcb5bf

Browse files
committed
Attempt fixing typing errors
Mixing in DatasetReduce fixes: xarray/tests/test_groupby.py:460: error: Invalid self argument "Dataset" to attribute function "mean" with type "Callable[[DatasetReduce, Optional[Hashable], Optional[bool], Optional[bool], KwArg(Any)], T_Dataset]" [misc] Switching to "Dateset" as returned type fixes: xarray/tests/test_groupby.py:77: error: Need type annotation for "expected" [var-annotated]
1 parent c7e9d96 commit 5dcb5bf

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

xarray/util/generate_reductions.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@
2121
# This file was generated using xarray.util.generate_reductions. Do not edit manually.
2222
2323
import sys
24-
from typing import Any, Callable, Hashable, Optional, Sequence, Union
24+
from typing import TYPE_CHECKING, Any, Callable, Hashable, Optional, Sequence, Union
2525
2626
from . import duck_array_ops
27-
from .types import T_DataArray, T_Dataset
2827
2928
if sys.version_info >= (3, 8):
3029
from typing import Protocol
3130
else:
32-
from typing_extensions import Protocol'''
31+
from typing_extensions import Protocol
32+
33+
if TYPE_CHECKING:
34+
from .dataset import Dataset
35+
from.dataarray import DataArray'''
3336

3437
OBJ_PREAMBLE = """
3538
@@ -42,22 +45,22 @@ def reduce(
4245
keep_attrs: bool = None,
4346
keepdims: bool = False,
4447
**kwargs: Any,
45-
) -> T_{obj}:
48+
) -> "{obj}":
4649
..."""
4750

4851

4952
CLASS_PREAMBLE = """
5053
51-
class {obj}{cls}Reductions:
54+
class {obj}{cls}Reductions({obj}Reduce):
5255
__slots__ = ()"""
5356

5457
TEMPLATE_REDUCTION_SIGNATURE = '''
5558
def {method}(
56-
self: {obj}Reduce,
59+
self,
5760
dim: Union[None, Hashable, Sequence[Hashable]] = None,{extra_kwargs}
5861
keep_attrs: bool = None,
5962
**kwargs,
60-
) -> T_{obj}:
63+
) -> "{obj}":
6164
"""
6265
Reduce this {obj}'s data by applying ``{method}`` along some dimension(s).
6366

0 commit comments

Comments
 (0)