Skip to content

Commit 6be5548

Browse files
committed
#121 Fix type hints of dataset module
1 parent dce2fc3 commit 6be5548

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

xarray_dataclasses/dataset.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
TDataset = TypeVar("TDataset", bound=xr.Dataset)
31-
TDataset_ = TypeVar("TDataset_", bound=xr.Dataset, 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 DatasetClass(Protocol[P, TDataset_]):
42+
class DatasetClass(Protocol[P, TDataset]):
4243
"""Type hint for a dataclass object with a Dataset 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[TDataset_]
49+
__dataoptions__: DataOptions[TDataset]
4750

4851

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

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

6164
def __get__(
@@ -141,9 +144,9 @@ class AsDataset:
141144
def new(cls: Type[DatasetClass[P, TDataset]]) -> Callable[P, TDataset]:
142145
"""Create a Dataset object from dataclass parameters."""
143146

144-
init = copy(cls.__init__)
147+
init = copy(cls.__init__) # type: ignore
148+
init.__doc__ = cls.__init__.__doc__ # type: ignore
145149
init.__annotations__["return"] = TDataset
146-
init.__doc__ = cls.__init__.__doc__
147150

148151
@wraps(init)
149152
def new(

0 commit comments

Comments
 (0)