Skip to content

Commit dce2fc3

Browse files
committed
#121 Fix type hints of dataarray module
1 parent 6747f7c commit dce2fc3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

xarray_dataclasses/dataarray.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,25 @@
2828
# type hints
2929
P = ParamSpec("P")
3030
TDataArray = TypeVar("TDataArray", bound=xr.DataArray)
31-
TDataArray_ = TypeVar("TDataArray_", bound=xr.DataArray, contravariant=True)
3231

3332

3433
class DataClass(Protocol[P]):
3534
"""Type hint for a dataclass object."""
3635

37-
__init__: Callable[P, None]
36+
def __init__(self, *args: P.args, **kwargs: P.kwargs) -> None:
37+
...
38+
3839
__dataclass_fields__: Dict[str, Field[Any]]
3940

4041

41-
class DataArrayClass(Protocol[P, TDataArray_]):
42+
class DataArrayClass(Protocol[P, TDataArray]):
4243
"""Type hint for a dataclass object with a DataArray factory."""
4344

44-
__init__: Callable[P, None]
45+
def __init__(self, *args: P.args, **kwargs: P.kwargs) -> None:
46+
...
47+
4548
__dataclass_fields__: Dict[str, Field[Any]]
46-
__dataoptions__: DataOptions[TDataArray_]
49+
__dataoptions__: DataOptions[TDataArray]
4750

4851

4952
# custom classproperty
@@ -55,7 +58,7 @@ class classproperty:
5558
5659
"""
5760

58-
def __init__(self, func: Callable[..., Callable[P, TDataArray]]) -> None:
61+
def __init__(self, func: Callable[..., Any]) -> None:
5962
self.__func__ = func
6063

6164
def __get__(
@@ -143,9 +146,9 @@ class AsDataArray:
143146
def new(cls: Type[DataArrayClass[P, TDataArray]]) -> Callable[P, TDataArray]:
144147
"""Create a DataArray object from dataclass parameters."""
145148

146-
init = copy(cls.__init__)
149+
init = copy(cls.__init__) # type: ignore
150+
init.__doc__ = cls.__init__.__doc__ # type: ignore
147151
init.__annotations__["return"] = TDataArray
148-
init.__doc__ = cls.__init__.__doc__
149152

150153
@wraps(init)
151154
def new(

0 commit comments

Comments
 (0)