28
28
# type hints
29
29
P = ParamSpec ("P" )
30
30
TDataset = TypeVar ("TDataset" , bound = xr .Dataset )
31
- TDataset_ = TypeVar ("TDataset_" , bound = xr .Dataset , contravariant = True )
32
31
33
32
34
33
class DataClass (Protocol [P ]):
35
34
"""Type hint for a dataclass object."""
36
35
37
- __init__ : Callable [P , None ]
36
+ def __init__ (self , * args : P .args , ** kwargs : P .kwargs ) -> None :
37
+ ...
38
+
38
39
__dataclass_fields__ : Dict [str , Field [Any ]]
39
40
40
41
41
- class DatasetClass (Protocol [P , TDataset_ ]):
42
+ class DatasetClass (Protocol [P , TDataset ]):
42
43
"""Type hint for a dataclass object with a Dataset factory."""
43
44
44
- __init__ : Callable [P , None ]
45
+ def __init__ (self , * args : P .args , ** kwargs : P .kwargs ) -> None :
46
+ ...
47
+
45
48
__dataclass_fields__ : Dict [str , Field [Any ]]
46
- __dataoptions__ : DataOptions [TDataset_ ]
49
+ __dataoptions__ : DataOptions [TDataset ]
47
50
48
51
49
52
# custom classproperty
@@ -55,7 +58,7 @@ class classproperty:
55
58
56
59
"""
57
60
58
- def __init__ (self , func : Callable [..., Callable [ P , TDataset ] ]) -> None :
61
+ def __init__ (self , func : Callable [..., Any ]) -> None :
59
62
self .__func__ = func
60
63
61
64
def __get__ (
@@ -141,9 +144,9 @@ class AsDataset:
141
144
def new (cls : Type [DatasetClass [P , TDataset ]]) -> Callable [P , TDataset ]:
142
145
"""Create a Dataset object from dataclass parameters."""
143
146
144
- init = copy (cls .__init__ )
147
+ init = copy (cls .__init__ ) # type: ignore
148
+ init .__doc__ = cls .__init__ .__doc__ # type: ignore
145
149
init .__annotations__ ["return" ] = TDataset
146
- init .__doc__ = cls .__init__ .__doc__
147
150
148
151
@wraps (init )
149
152
def new (
0 commit comments