From 5dcb5bfebe04302beb732259f3e805bd31691ed8 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sat, 20 Nov 2021 12:30:50 +0100 Subject: [PATCH] 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] --- xarray/util/generate_reductions.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/xarray/util/generate_reductions.py b/xarray/util/generate_reductions.py index 2ad65bab08b..ac3a1b500a0 100644 --- a/xarray/util/generate_reductions.py +++ b/xarray/util/generate_reductions.py @@ -21,15 +21,18 @@ # This file was generated using xarray.util.generate_reductions. Do not edit manually. import sys -from typing import Any, Callable, Hashable, Optional, Sequence, Union +from typing import TYPE_CHECKING, Any, Callable, Hashable, Optional, Sequence, Union from . import duck_array_ops -from .types import T_DataArray, T_Dataset if sys.version_info >= (3, 8): from typing import Protocol else: - from typing_extensions import Protocol''' + from typing_extensions import Protocol + +if TYPE_CHECKING: + from .dataset import Dataset + from.dataarray import DataArray''' OBJ_PREAMBLE = """ @@ -42,22 +45,22 @@ def reduce( keep_attrs: bool = None, keepdims: bool = False, **kwargs: Any, - ) -> T_{obj}: + ) -> "{obj}": ...""" CLASS_PREAMBLE = """ -class {obj}{cls}Reductions: +class {obj}{cls}Reductions({obj}Reduce): __slots__ = ()""" TEMPLATE_REDUCTION_SIGNATURE = ''' def {method}( - self: {obj}Reduce, + self, dim: Union[None, Hashable, Sequence[Hashable]] = None,{extra_kwargs} keep_attrs: bool = None, **kwargs, - ) -> T_{obj}: + ) -> "{obj}": """ Reduce this {obj}'s data by applying ``{method}`` along some dimension(s).