9
9
Any ,
10
10
Concatenate ,
11
11
Generic ,
12
- Never ,
12
+ Literal ,
13
13
ParamSpec ,
14
14
Protocol ,
15
15
TypeAlias ,
16
16
TypeGuard ,
17
+ cast ,
17
18
overload ,
18
19
)
19
20
@@ -144,10 +145,75 @@ class StoreOptions(Immutable, Generic[Action, Event]):
144
145
145
146
# Autorun
146
147
148
+ AutoAwait = TypeVar ('AutoAwait' , bound = Literal [True , False , None ], infer_variance = True )
147
149
148
- class AutorunOptions (Immutable , Generic [ReturnType ]):
150
+
151
+ class AutorunOptionsType (Immutable , Generic [ReturnType , AutoAwait ]):
152
+ default_value : ReturnType | None = None
153
+ auto_await : AutoAwait = cast ('AutoAwait' , val = None )
154
+ initial_call : bool = True
155
+ reactive : bool = True
156
+ memoization : bool = True
157
+ keep_ref : bool = True
158
+ subscribers_initial_run : bool = True
159
+ subscribers_keep_ref : bool = True
160
+
161
+ @overload
162
+ def __init__ (
163
+ self : AutorunOptionsType [ReturnType , Literal [None ]], # type: ignore[reportInvalidTypeVar]
164
+ * ,
165
+ default_value : ReturnType | None = None ,
166
+ auto_await : Literal [None ] | None = None ,
167
+ initial_call : bool = True ,
168
+ reactive : bool = True ,
169
+ memoization : bool = True ,
170
+ keep_ref : bool = True ,
171
+ subscribers_initial_run : bool = True ,
172
+ subscribers_keep_ref : bool = True ,
173
+ ) -> None : ...
174
+ @overload
175
+ def __init__ (
176
+ self : AutorunOptionsType [ReturnType , Literal [True ]], # type: ignore[reportInvalidTypeVar]
177
+ * ,
178
+ default_value : ReturnType | None = None ,
179
+ auto_await : Literal [True ],
180
+ initial_call : bool = True ,
181
+ reactive : bool = True ,
182
+ memoization : bool = True ,
183
+ keep_ref : bool = True ,
184
+ subscribers_initial_run : bool = True ,
185
+ subscribers_keep_ref : bool = True ,
186
+ ) -> None : ...
187
+ @overload
188
+ def __init__ (
189
+ self : AutorunOptionsType [ReturnType , Literal [False ]], # type: ignore[reportInvalidTypeVar]
190
+ * ,
191
+ default_value : ReturnType | None = None ,
192
+ auto_await : Literal [False ],
193
+ initial_call : bool = True ,
194
+ reactive : bool = True ,
195
+ memoization : bool = True ,
196
+ keep_ref : bool = True ,
197
+ subscribers_initial_run : bool = True ,
198
+ subscribers_keep_ref : bool = True ,
199
+ ) -> None : ...
200
+ def __init__ ( # noqa: PLR0913
201
+ self : AutorunOptionsType ,
202
+ * ,
203
+ default_value : ReturnType | None = None ,
204
+ auto_await : bool | None = None ,
205
+ initial_call : bool = True ,
206
+ reactive : bool = True ,
207
+ memoization : bool = True ,
208
+ keep_ref : bool = True ,
209
+ subscribers_initial_run : bool = True ,
210
+ subscribers_keep_ref : bool = True ,
211
+ ) -> None : ...
212
+
213
+
214
+ class AutorunOptionsImplementation (Immutable , Generic [ReturnType , AutoAwait ]):
149
215
default_value : ReturnType | None = None
150
- auto_await : bool = True
216
+ auto_await : AutoAwait = cast ( 'AutoAwait' , val = None )
151
217
initial_call : bool = True
152
218
reactive : bool = True
153
219
memoization : bool = True
@@ -156,8 +222,7 @@ class AutorunOptions(Immutable, Generic[ReturnType]):
156
222
subscribers_keep_ref : bool = True
157
223
158
224
159
- AutorunOptionsWithDefault = AutorunOptions [ReturnType ]
160
- AutorunOptionsWithoutDefault = AutorunOptions [Never ]
225
+ AutorunOptions = cast ('type[AutorunOptionsType]' , AutorunOptionsImplementation )
161
226
162
227
163
228
class AutorunReturnType (
@@ -186,34 +251,39 @@ def unsubscribe(self: AutorunReturnType) -> None: ...
186
251
__name__ : str
187
252
188
253
189
- class AutorunDecorator (Protocol , Generic [SelectorOutput , ReturnType ]):
254
+ class AutorunDecorator (Protocol , Generic [ReturnType , SelectorOutput , AutoAwait ]):
190
255
@overload
191
256
def __call__ (
192
- self : AutorunDecorator ,
257
+ self : AutorunDecorator [ReturnType , SelectorOutput , Literal [None ]],
258
+ func : Callable [
259
+ Concatenate [SelectorOutput , Args ],
260
+ Awaitable [ReturnType ],
261
+ ],
262
+ ) -> AutorunReturnType [None , Args ]: ...
263
+ @overload
264
+ def __call__ (
265
+ self : AutorunDecorator [ReturnType , SelectorOutput , Literal [None ]],
193
266
func : Callable [
194
267
Concatenate [SelectorOutput , Args ],
195
268
ReturnType ,
196
269
],
197
270
) -> AutorunReturnType [ReturnType , Args ]: ...
198
-
199
271
@overload
200
272
def __call__ (
201
- self : AutorunDecorator ,
273
+ self : AutorunDecorator [ ReturnType , SelectorOutput , Literal [ True ]] ,
202
274
func : Callable [
203
275
Concatenate [SelectorOutput , Args ],
204
276
Awaitable [ReturnType ],
205
277
],
206
- ) -> AutorunReturnType [Awaitable [ReturnType ], Args ]: ...
207
-
208
-
209
- class UnknownAutorunDecorator (Protocol , Generic [SelectorOutput ]):
278
+ ) -> AutorunReturnType [None , Args ]: ...
279
+ @overload
210
280
def __call__ (
211
- self : UnknownAutorunDecorator ,
281
+ self : AutorunDecorator [ ReturnType , SelectorOutput , Literal [ False ]] ,
212
282
func : Callable [
213
283
Concatenate [SelectorOutput , Args ],
214
- ReturnType ,
284
+ Awaitable [ ReturnType ] ,
215
285
],
216
- ) -> AutorunReturnType [ReturnType , Args ]: ...
286
+ ) -> AutorunReturnType [Awaitable [ ReturnType ] , Args ]: ...
217
287
218
288
219
289
# View
@@ -227,10 +297,6 @@ class ViewOptions(Immutable, Generic[ReturnType]):
227
297
subscribers_keep_ref : bool = True
228
298
229
299
230
- ViewOptionsWithDefault = ViewOptions [ReturnType ]
231
- ViewOptionsWithoutDefault = ViewOptions [Never ]
232
-
233
-
234
300
class ViewReturnType (
235
301
Protocol ,
236
302
Generic [ReturnType , Args ],
@@ -257,17 +323,8 @@ def unsubscribe(self: ViewReturnType) -> None: ...
257
323
258
324
class ViewDecorator (
259
325
Protocol ,
260
- Generic [SelectorOutput , ReturnType ],
326
+ Generic [ReturnType , SelectorOutput ],
261
327
):
262
- @overload
263
- def __call__ (
264
- self : ViewDecorator ,
265
- func : Callable [
266
- Concatenate [SelectorOutput , Args ],
267
- ReturnType ,
268
- ],
269
- ) -> ViewReturnType [ReturnType , Args ]: ...
270
-
271
328
@overload
272
329
def __call__ (
273
330
self : ViewDecorator ,
@@ -277,10 +334,9 @@ def __call__(
277
334
],
278
335
) -> ViewReturnType [Awaitable [ReturnType ], Args ]: ...
279
336
280
-
281
- class UnknownViewDecorator (Protocol , Generic [SelectorOutput ]):
337
+ @overload
282
338
def __call__ (
283
- self : UnknownViewDecorator ,
339
+ self : ViewDecorator ,
284
340
func : Callable [
285
341
Concatenate [SelectorOutput , Args ],
286
342
ReturnType ,
0 commit comments