Skip to content

Commit

Permalink
Attempt fixing typing errors
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
Illviljan committed Nov 20, 2021
1 parent c7e9d96 commit 5dcb5bf
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions xarray/util/generate_reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand All @@ -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).
Expand Down

0 comments on commit 5dcb5bf

Please sign in to comment.