python-redux 0.19.1__tar.gz → 0.19.2.dev2250307103575157485__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/PKG-INFO +1 -1
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/_version.py +2 -2
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/autorun.py +41 -41
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/basic_types.py +55 -42
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/main.py +65 -32
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/.gitignore +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/LICENSE +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/README.md +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/pyproject.toml +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/__init__.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/combine_reducers.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/py.typed +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/serialization_mixin.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/side_effect_runner.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/__init__.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/__init__.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/event_loop.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/monitor.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/snapshot.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/store.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/wait_for.py +0 -0
- {python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/plugin.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-redux
|
|
3
|
-
Version: 0.19.
|
|
3
|
+
Version: 0.19.2.dev2250307103575157485
|
|
4
4
|
Summary: Redux implementation for Python
|
|
5
5
|
Project-URL: homepage, https://github.com/sassanh/python-redux/
|
|
6
6
|
Project-URL: repository, https://github.com/sassanh/python-redux/
|
|
@@ -17,5 +17,5 @@ __version__: str
|
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
|
18
18
|
version_tuple: VERSION_TUPLE
|
|
19
19
|
|
|
20
|
-
__version__ = version = '0.19.
|
|
21
|
-
__version_tuple__ = version_tuple = (0, 19,
|
|
20
|
+
__version__ = version = '0.19.2.dev2250307103575157485'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 19, 2, 'dev2250307103575157485')
|
|
@@ -17,11 +17,11 @@ from typing import (
|
|
|
17
17
|
|
|
18
18
|
from redux.basic_types import (
|
|
19
19
|
Action,
|
|
20
|
-
|
|
20
|
+
Args,
|
|
21
21
|
AutorunOptions,
|
|
22
|
-
AutorunOriginalReturnType,
|
|
23
22
|
ComparatorOutput,
|
|
24
23
|
Event,
|
|
24
|
+
ReturnType,
|
|
25
25
|
SelectorOutput,
|
|
26
26
|
State,
|
|
27
27
|
)
|
|
@@ -58,8 +58,8 @@ class Autorun(
|
|
|
58
58
|
Event,
|
|
59
59
|
SelectorOutput,
|
|
60
60
|
ComparatorOutput,
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
ReturnType,
|
|
62
|
+
Args,
|
|
63
63
|
],
|
|
64
64
|
):
|
|
65
65
|
def __init__(
|
|
@@ -69,10 +69,10 @@ class Autorun(
|
|
|
69
69
|
selector: Callable[[State], SelectorOutput],
|
|
70
70
|
comparator: Callable[[State], Any] | None,
|
|
71
71
|
func: Callable[
|
|
72
|
-
Concatenate[SelectorOutput,
|
|
73
|
-
|
|
72
|
+
Concatenate[SelectorOutput, Args],
|
|
73
|
+
ReturnType,
|
|
74
74
|
],
|
|
75
|
-
options: AutorunOptions[
|
|
75
|
+
options: AutorunOptions[ReturnType],
|
|
76
76
|
) -> None:
|
|
77
77
|
self.__name__ = func.__name__
|
|
78
78
|
self._store = store
|
|
@@ -109,10 +109,9 @@ class Autorun(
|
|
|
109
109
|
self._latest_value = Future()
|
|
110
110
|
self._latest_value.set_result(options.default_value)
|
|
111
111
|
else:
|
|
112
|
-
self._latest_value:
|
|
112
|
+
self._latest_value: ReturnType = options.default_value
|
|
113
113
|
self._subscriptions: set[
|
|
114
|
-
Callable[[
|
|
115
|
-
| weakref.ref[Callable[[AutorunOriginalReturnType], Any]]
|
|
114
|
+
Callable[[ReturnType], Any] | weakref.ref[Callable[[ReturnType], Any]]
|
|
116
115
|
] = set()
|
|
117
116
|
|
|
118
117
|
if self._check(store._state) and self._options.initial_call: # noqa: SLF001
|
|
@@ -137,8 +136,8 @@ class Autorun(
|
|
|
137
136
|
Event,
|
|
138
137
|
SelectorOutput,
|
|
139
138
|
ComparatorOutput,
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
ReturnType,
|
|
140
|
+
Args,
|
|
142
141
|
],
|
|
143
142
|
) -> None:
|
|
144
143
|
for subscriber_ in self._subscriptions.copy():
|
|
@@ -158,8 +157,8 @@ class Autorun(
|
|
|
158
157
|
Event,
|
|
159
158
|
SelectorOutput,
|
|
160
159
|
ComparatorOutput,
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
ReturnType,
|
|
161
|
+
Args,
|
|
163
162
|
],
|
|
164
163
|
task: Task,
|
|
165
164
|
*,
|
|
@@ -179,8 +178,8 @@ class Autorun(
|
|
|
179
178
|
Event,
|
|
180
179
|
SelectorOutput,
|
|
181
180
|
ComparatorOutput,
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
ReturnType,
|
|
182
|
+
Args,
|
|
184
183
|
],
|
|
185
184
|
state: State | None,
|
|
186
185
|
) -> bool:
|
|
@@ -211,16 +210,16 @@ class Autorun(
|
|
|
211
210
|
Event,
|
|
212
211
|
SelectorOutput,
|
|
213
212
|
ComparatorOutput,
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
ReturnType,
|
|
214
|
+
Args,
|
|
216
215
|
],
|
|
217
|
-
*args:
|
|
218
|
-
**kwargs:
|
|
216
|
+
*args: Args.args,
|
|
217
|
+
**kwargs: Args.kwargs,
|
|
219
218
|
) -> None:
|
|
220
219
|
self._should_be_called = False
|
|
221
220
|
func = self._func() if isinstance(self._func, weakref.ref) else self._func
|
|
222
221
|
if func and self._last_selector_result is not None:
|
|
223
|
-
value:
|
|
222
|
+
value: ReturnType = func(
|
|
224
223
|
self._last_selector_result,
|
|
225
224
|
*args,
|
|
226
225
|
**kwargs,
|
|
@@ -229,7 +228,7 @@ class Autorun(
|
|
|
229
228
|
if iscoroutine(value) and create_task:
|
|
230
229
|
if self._options.auto_await:
|
|
231
230
|
future = Future()
|
|
232
|
-
self._latest_value = cast(
|
|
231
|
+
self._latest_value = cast(ReturnType, future)
|
|
233
232
|
create_task(
|
|
234
233
|
value,
|
|
235
234
|
callback=functools.partial(
|
|
@@ -245,7 +244,7 @@ class Autorun(
|
|
|
245
244
|
):
|
|
246
245
|
self._latest_value.close()
|
|
247
246
|
self._latest_value = cast(
|
|
248
|
-
|
|
247
|
+
ReturnType,
|
|
249
248
|
AwaitableWrapper(value),
|
|
250
249
|
)
|
|
251
250
|
else:
|
|
@@ -259,16 +258,17 @@ class Autorun(
|
|
|
259
258
|
Event,
|
|
260
259
|
SelectorOutput,
|
|
261
260
|
ComparatorOutput,
|
|
262
|
-
|
|
263
|
-
|
|
261
|
+
ReturnType,
|
|
262
|
+
Args,
|
|
264
263
|
],
|
|
265
|
-
*args:
|
|
266
|
-
**kwargs:
|
|
267
|
-
) ->
|
|
264
|
+
*args: Args.args,
|
|
265
|
+
**kwargs: Args.kwargs,
|
|
266
|
+
) -> ReturnType:
|
|
268
267
|
state = self._store._state # noqa: SLF001
|
|
269
|
-
|
|
268
|
+
self._check(state)
|
|
269
|
+
if self._should_be_called or args or kwargs or not self._options.memoization:
|
|
270
270
|
self._call(*args, **kwargs)
|
|
271
|
-
return cast(
|
|
271
|
+
return cast(ReturnType, self._latest_value)
|
|
272
272
|
|
|
273
273
|
def __repr__(
|
|
274
274
|
self: Autorun[
|
|
@@ -277,8 +277,8 @@ class Autorun(
|
|
|
277
277
|
Event,
|
|
278
278
|
SelectorOutput,
|
|
279
279
|
ComparatorOutput,
|
|
280
|
-
|
|
281
|
-
|
|
280
|
+
ReturnType,
|
|
281
|
+
Args,
|
|
282
282
|
],
|
|
283
283
|
) -> str:
|
|
284
284
|
return (
|
|
@@ -294,11 +294,11 @@ class Autorun(
|
|
|
294
294
|
Event,
|
|
295
295
|
SelectorOutput,
|
|
296
296
|
ComparatorOutput,
|
|
297
|
-
|
|
298
|
-
|
|
297
|
+
ReturnType,
|
|
298
|
+
Args,
|
|
299
299
|
],
|
|
300
|
-
) ->
|
|
301
|
-
return cast(
|
|
300
|
+
) -> ReturnType:
|
|
301
|
+
return cast(ReturnType, self._latest_value)
|
|
302
302
|
|
|
303
303
|
def subscribe(
|
|
304
304
|
self: Autorun[
|
|
@@ -307,10 +307,10 @@ class Autorun(
|
|
|
307
307
|
Event,
|
|
308
308
|
SelectorOutput,
|
|
309
309
|
ComparatorOutput,
|
|
310
|
-
|
|
311
|
-
|
|
310
|
+
ReturnType,
|
|
311
|
+
Args,
|
|
312
312
|
],
|
|
313
|
-
callback: Callable[[
|
|
313
|
+
callback: Callable[[ReturnType], Any],
|
|
314
314
|
*,
|
|
315
315
|
initial_run: bool | None = None,
|
|
316
316
|
keep_ref: bool | None = None,
|
|
@@ -343,8 +343,8 @@ class Autorun(
|
|
|
343
343
|
Event,
|
|
344
344
|
SelectorOutput,
|
|
345
345
|
ComparatorOutput,
|
|
346
|
-
|
|
347
|
-
|
|
346
|
+
ReturnType,
|
|
347
|
+
Args,
|
|
348
348
|
],
|
|
349
349
|
) -> inspect.Signature:
|
|
350
350
|
return self._signature
|
|
@@ -42,12 +42,10 @@ Event = TypeVar('Event', bound=BaseEvent | None, infer_variance=True)
|
|
|
42
42
|
Event2 = TypeVar('Event2', bound=BaseEvent, infer_variance=True)
|
|
43
43
|
SelectorOutput = TypeVar('SelectorOutput', infer_variance=True)
|
|
44
44
|
ComparatorOutput = TypeVar('ComparatorOutput', infer_variance=True)
|
|
45
|
-
|
|
46
|
-
ViewOriginalReturnType = TypeVar('ViewOriginalReturnType', infer_variance=True)
|
|
45
|
+
ReturnType = TypeVar('ReturnType', infer_variance=True)
|
|
47
46
|
Comparator = Callable[[State], ComparatorOutput]
|
|
48
47
|
EventHandler = Callable[[Event], Any] | Callable[[], Any]
|
|
49
|
-
|
|
50
|
-
ViewArgs = ParamSpec('ViewArgs')
|
|
48
|
+
Args = ParamSpec('Args')
|
|
51
49
|
Payload = TypeVar('Payload', bound=Any, default=None)
|
|
52
50
|
|
|
53
51
|
|
|
@@ -129,36 +127,37 @@ class CreateStoreOptions(Immutable, Generic[Action, Event]):
|
|
|
129
127
|
# Autorun
|
|
130
128
|
|
|
131
129
|
|
|
132
|
-
class AutorunOptions(Immutable, Generic[
|
|
133
|
-
default_value:
|
|
130
|
+
class AutorunOptions(Immutable, Generic[ReturnType]):
|
|
131
|
+
default_value: ReturnType | None = None
|
|
134
132
|
auto_await: bool = True
|
|
135
133
|
initial_call: bool = True
|
|
136
134
|
reactive: bool = True
|
|
135
|
+
memoization: bool = True
|
|
137
136
|
keep_ref: bool = True
|
|
138
137
|
subscribers_initial_run: bool = True
|
|
139
138
|
subscribers_keep_ref: bool = True
|
|
140
139
|
|
|
141
140
|
|
|
142
|
-
AutorunOptionsWithDefault = AutorunOptions[
|
|
141
|
+
AutorunOptionsWithDefault = AutorunOptions[ReturnType]
|
|
143
142
|
AutorunOptionsWithoutDefault = AutorunOptions[Never]
|
|
144
143
|
|
|
145
144
|
|
|
146
145
|
class AutorunReturnType(
|
|
147
146
|
Protocol,
|
|
148
|
-
Generic[
|
|
147
|
+
Generic[ReturnType, Args],
|
|
149
148
|
):
|
|
150
149
|
def __call__(
|
|
151
150
|
self: AutorunReturnType,
|
|
152
|
-
*args:
|
|
153
|
-
**kwargs:
|
|
154
|
-
) ->
|
|
151
|
+
*args: Args.args,
|
|
152
|
+
**kwargs: Args.kwargs,
|
|
153
|
+
) -> ReturnType: ...
|
|
155
154
|
|
|
156
155
|
@property
|
|
157
|
-
def value(self: AutorunReturnType) ->
|
|
156
|
+
def value(self: AutorunReturnType) -> ReturnType: ...
|
|
158
157
|
|
|
159
158
|
def subscribe(
|
|
160
159
|
self: AutorunReturnType,
|
|
161
|
-
callback: Callable[[
|
|
160
|
+
callback: Callable[[ReturnType], Any],
|
|
162
161
|
*,
|
|
163
162
|
initial_run: bool | None = None,
|
|
164
163
|
keep_ref: bool | None = None,
|
|
@@ -171,67 +170,68 @@ class AutorunReturnType(
|
|
|
171
170
|
|
|
172
171
|
class AutorunDecorator(
|
|
173
172
|
Protocol,
|
|
174
|
-
Generic[SelectorOutput,
|
|
173
|
+
Generic[SelectorOutput, ReturnType],
|
|
175
174
|
):
|
|
176
175
|
@overload
|
|
177
176
|
def __call__(
|
|
178
177
|
self: AutorunDecorator,
|
|
179
178
|
func: Callable[
|
|
180
|
-
Concatenate[SelectorOutput,
|
|
181
|
-
|
|
179
|
+
Concatenate[SelectorOutput, Args],
|
|
180
|
+
ReturnType,
|
|
182
181
|
],
|
|
183
|
-
) -> AutorunReturnType[
|
|
182
|
+
) -> AutorunReturnType[ReturnType, Args]: ...
|
|
184
183
|
|
|
185
184
|
@overload
|
|
186
185
|
def __call__(
|
|
187
186
|
self: AutorunDecorator,
|
|
188
187
|
func: Callable[
|
|
189
|
-
Concatenate[SelectorOutput,
|
|
190
|
-
Awaitable[
|
|
188
|
+
Concatenate[SelectorOutput, Args],
|
|
189
|
+
Awaitable[ReturnType],
|
|
191
190
|
],
|
|
192
|
-
) -> AutorunReturnType[Awaitable[
|
|
191
|
+
) -> AutorunReturnType[Awaitable[ReturnType], Args]: ...
|
|
193
192
|
|
|
194
193
|
|
|
195
194
|
class UnknownAutorunDecorator(Protocol, Generic[SelectorOutput]):
|
|
196
195
|
def __call__(
|
|
197
196
|
self: UnknownAutorunDecorator,
|
|
198
197
|
func: Callable[
|
|
199
|
-
Concatenate[SelectorOutput,
|
|
200
|
-
|
|
198
|
+
Concatenate[SelectorOutput, Args],
|
|
199
|
+
ReturnType,
|
|
201
200
|
],
|
|
202
|
-
) -> AutorunReturnType[
|
|
201
|
+
) -> AutorunReturnType[ReturnType, Args]: ...
|
|
203
202
|
|
|
204
203
|
|
|
205
204
|
# View
|
|
206
205
|
|
|
207
206
|
|
|
208
|
-
class ViewOptions(Immutable, Generic[
|
|
209
|
-
default_value:
|
|
207
|
+
class ViewOptions(Immutable, Generic[ReturnType]):
|
|
208
|
+
default_value: ReturnType | None = None
|
|
209
|
+
memoization: bool = True
|
|
210
210
|
keep_ref: bool = True
|
|
211
211
|
subscribers_initial_run: bool = True
|
|
212
212
|
subscribers_keep_ref: bool = True
|
|
213
213
|
|
|
214
214
|
|
|
215
|
-
ViewOptionsWithDefault = ViewOptions[
|
|
215
|
+
ViewOptionsWithDefault = ViewOptions[ReturnType]
|
|
216
216
|
ViewOptionsWithoutDefault = ViewOptions[Never]
|
|
217
217
|
|
|
218
218
|
|
|
219
219
|
class ViewReturnType(
|
|
220
220
|
Protocol,
|
|
221
|
-
Generic[
|
|
221
|
+
Generic[ReturnType, Args],
|
|
222
222
|
):
|
|
223
223
|
def __call__(
|
|
224
224
|
self: ViewReturnType,
|
|
225
|
-
*args:
|
|
226
|
-
**kwargs:
|
|
227
|
-
) ->
|
|
225
|
+
*args: Args.args,
|
|
226
|
+
**kwargs: Args.kwargs,
|
|
227
|
+
) -> ReturnType: ...
|
|
228
228
|
|
|
229
229
|
@property
|
|
230
|
-
def value(self: ViewReturnType) ->
|
|
230
|
+
def value(self: ViewReturnType) -> ReturnType: ...
|
|
231
231
|
|
|
232
232
|
def subscribe(
|
|
233
233
|
self: ViewReturnType,
|
|
234
|
-
callback: Callable[[
|
|
234
|
+
callback: Callable[[ReturnType], Any],
|
|
235
235
|
*,
|
|
236
236
|
initial_run: bool | None = None,
|
|
237
237
|
keep_ref: bool | None = None,
|
|
@@ -242,35 +242,48 @@ class ViewReturnType(
|
|
|
242
242
|
|
|
243
243
|
class ViewDecorator(
|
|
244
244
|
Protocol,
|
|
245
|
-
Generic[SelectorOutput,
|
|
245
|
+
Generic[SelectorOutput, ReturnType],
|
|
246
246
|
):
|
|
247
247
|
@overload
|
|
248
248
|
def __call__(
|
|
249
249
|
self: ViewDecorator,
|
|
250
250
|
func: Callable[
|
|
251
|
-
Concatenate[SelectorOutput,
|
|
252
|
-
|
|
251
|
+
Concatenate[SelectorOutput, Args],
|
|
252
|
+
ReturnType,
|
|
253
253
|
],
|
|
254
|
-
) -> ViewReturnType[
|
|
254
|
+
) -> ViewReturnType[ReturnType, Args]: ...
|
|
255
255
|
|
|
256
256
|
@overload
|
|
257
257
|
def __call__(
|
|
258
258
|
self: ViewDecorator,
|
|
259
259
|
func: Callable[
|
|
260
|
-
Concatenate[SelectorOutput,
|
|
261
|
-
Awaitable[
|
|
260
|
+
Concatenate[SelectorOutput, Args],
|
|
261
|
+
Awaitable[ReturnType],
|
|
262
262
|
],
|
|
263
|
-
) -> ViewReturnType[Awaitable[
|
|
263
|
+
) -> ViewReturnType[Awaitable[ReturnType], Args]: ...
|
|
264
264
|
|
|
265
265
|
|
|
266
266
|
class UnknownViewDecorator(Protocol, Generic[SelectorOutput]):
|
|
267
267
|
def __call__(
|
|
268
268
|
self: UnknownViewDecorator,
|
|
269
269
|
func: Callable[
|
|
270
|
-
Concatenate[SelectorOutput,
|
|
271
|
-
|
|
270
|
+
Concatenate[SelectorOutput, Args],
|
|
271
|
+
ReturnType,
|
|
272
272
|
],
|
|
273
|
-
) -> ViewReturnType[
|
|
273
|
+
) -> ViewReturnType[ReturnType, Args]: ...
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
# With Store
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
class WithStateDecorator(
|
|
280
|
+
Protocol,
|
|
281
|
+
Generic[SelectorOutput],
|
|
282
|
+
):
|
|
283
|
+
def __call__(
|
|
284
|
+
self: WithStateDecorator,
|
|
285
|
+
func: Callable[Concatenate[SelectorOutput, Args], ReturnType],
|
|
286
|
+
) -> Callable[Args, ReturnType]: ...
|
|
274
287
|
|
|
275
288
|
|
|
276
289
|
class EventSubscriber(Protocol):
|
|
@@ -7,9 +7,10 @@ import inspect
|
|
|
7
7
|
import queue
|
|
8
8
|
import weakref
|
|
9
9
|
from collections import defaultdict
|
|
10
|
-
from collections.abc import
|
|
10
|
+
from collections.abc import Callable
|
|
11
11
|
from threading import Lock, Thread
|
|
12
12
|
from typing import (
|
|
13
|
+
TYPE_CHECKING,
|
|
13
14
|
Any,
|
|
14
15
|
Concatenate,
|
|
15
16
|
Generic,
|
|
@@ -21,12 +22,11 @@ from redux.autorun import Autorun
|
|
|
21
22
|
from redux.basic_types import (
|
|
22
23
|
Action,
|
|
23
24
|
ActionMiddleware,
|
|
24
|
-
|
|
25
|
+
Args,
|
|
25
26
|
AutorunDecorator,
|
|
26
27
|
AutorunOptions,
|
|
27
28
|
AutorunOptionsWithDefault,
|
|
28
29
|
AutorunOptionsWithoutDefault,
|
|
29
|
-
AutorunOriginalReturnType,
|
|
30
30
|
AutorunReturnType,
|
|
31
31
|
AwaitableOrNot,
|
|
32
32
|
BaseAction,
|
|
@@ -42,24 +42,27 @@ from redux.basic_types import (
|
|
|
42
42
|
FinishEvent,
|
|
43
43
|
InitAction,
|
|
44
44
|
ReducerType,
|
|
45
|
+
ReturnType,
|
|
45
46
|
SelectorOutput,
|
|
46
47
|
SnapshotAtom,
|
|
47
48
|
State,
|
|
48
49
|
UnknownAutorunDecorator,
|
|
49
50
|
UnknownViewDecorator,
|
|
50
|
-
ViewArgs,
|
|
51
51
|
ViewDecorator,
|
|
52
52
|
ViewOptions,
|
|
53
53
|
ViewOptionsWithDefault,
|
|
54
54
|
ViewOptionsWithoutDefault,
|
|
55
|
-
ViewOriginalReturnType,
|
|
56
55
|
ViewReturnType,
|
|
56
|
+
WithStateDecorator,
|
|
57
57
|
is_complete_reducer_result,
|
|
58
58
|
is_state_reducer_result,
|
|
59
59
|
)
|
|
60
60
|
from redux.serialization_mixin import SerializationMixin
|
|
61
61
|
from redux.side_effect_runner import SideEffectRunnerThread
|
|
62
62
|
|
|
63
|
+
if TYPE_CHECKING:
|
|
64
|
+
from collections.abc import Awaitable
|
|
65
|
+
|
|
63
66
|
|
|
64
67
|
class Store(Generic[State, Action, Event], SerializationMixin):
|
|
65
68
|
"""Redux store for managing state and side effects."""
|
|
@@ -307,16 +310,16 @@ class Store(Generic[State, Action, Event], SerializationMixin):
|
|
|
307
310
|
selector: Callable[[State], SelectorOutput],
|
|
308
311
|
comparator: Callable[[State], ComparatorOutput] | None = None,
|
|
309
312
|
*,
|
|
310
|
-
options: AutorunOptionsWithDefault[
|
|
311
|
-
) -> AutorunDecorator[SelectorOutput,
|
|
313
|
+
options: AutorunOptionsWithDefault[ReturnType],
|
|
314
|
+
) -> AutorunDecorator[SelectorOutput, ReturnType]: ...
|
|
312
315
|
def autorun(
|
|
313
316
|
self: Store[State, Action, Event],
|
|
314
317
|
selector: Callable[[State], SelectorOutput],
|
|
315
318
|
comparator: Callable[[State], ComparatorOutput] | None = None,
|
|
316
319
|
*,
|
|
317
|
-
options: AutorunOptions[
|
|
320
|
+
options: AutorunOptions[ReturnType] | None = None,
|
|
318
321
|
) -> (
|
|
319
|
-
AutorunDecorator[SelectorOutput,
|
|
322
|
+
AutorunDecorator[SelectorOutput, ReturnType]
|
|
320
323
|
| UnknownAutorunDecorator[SelectorOutput]
|
|
321
324
|
):
|
|
322
325
|
"""Create a new autorun, reflecting on state changes."""
|
|
@@ -324,23 +327,23 @@ class Store(Generic[State, Action, Event], SerializationMixin):
|
|
|
324
327
|
@overload
|
|
325
328
|
def decorator(
|
|
326
329
|
func: Callable[
|
|
327
|
-
Concatenate[SelectorOutput,
|
|
328
|
-
|
|
330
|
+
Concatenate[SelectorOutput, Args],
|
|
331
|
+
ReturnType,
|
|
329
332
|
],
|
|
330
|
-
) -> AutorunReturnType[
|
|
333
|
+
) -> AutorunReturnType[ReturnType, Args]: ...
|
|
331
334
|
@overload
|
|
332
335
|
def decorator(
|
|
333
336
|
func: Callable[
|
|
334
|
-
Concatenate[SelectorOutput,
|
|
335
|
-
Awaitable[
|
|
337
|
+
Concatenate[SelectorOutput, Args],
|
|
338
|
+
Awaitable[ReturnType],
|
|
336
339
|
],
|
|
337
|
-
) -> AutorunReturnType[Awaitable[
|
|
340
|
+
) -> AutorunReturnType[Awaitable[ReturnType], Args]: ...
|
|
338
341
|
def decorator(
|
|
339
342
|
func: Callable[
|
|
340
|
-
Concatenate[SelectorOutput,
|
|
341
|
-
AwaitableOrNot[
|
|
343
|
+
Concatenate[SelectorOutput, Args],
|
|
344
|
+
AwaitableOrNot[ReturnType],
|
|
342
345
|
],
|
|
343
|
-
) -> AutorunReturnType[AwaitableOrNot[
|
|
346
|
+
) -> AutorunReturnType[AwaitableOrNot[ReturnType], Args]:
|
|
344
347
|
return Autorun(
|
|
345
348
|
store=self,
|
|
346
349
|
selector=selector,
|
|
@@ -363,40 +366,39 @@ class Store(Generic[State, Action, Event], SerializationMixin):
|
|
|
363
366
|
self: Store[State, Action, Event],
|
|
364
367
|
selector: Callable[[State], SelectorOutput],
|
|
365
368
|
*,
|
|
366
|
-
options: ViewOptionsWithDefault[
|
|
367
|
-
) -> ViewDecorator[SelectorOutput,
|
|
369
|
+
options: ViewOptionsWithDefault[ReturnType],
|
|
370
|
+
) -> ViewDecorator[SelectorOutput, ReturnType]: ...
|
|
368
371
|
def view(
|
|
369
372
|
self: Store[State, Action, Event],
|
|
370
373
|
selector: Callable[[State], SelectorOutput],
|
|
371
374
|
*,
|
|
372
|
-
options: ViewOptions[
|
|
375
|
+
options: ViewOptions[ReturnType] | None = None,
|
|
373
376
|
) -> (
|
|
374
|
-
ViewDecorator[SelectorOutput,
|
|
375
|
-
| UnknownViewDecorator[SelectorOutput]
|
|
377
|
+
ViewDecorator[SelectorOutput, ReturnType] | UnknownViewDecorator[SelectorOutput]
|
|
376
378
|
):
|
|
377
379
|
"""Create a new view, throttling calls for unchanged selector results."""
|
|
378
380
|
|
|
379
381
|
@overload
|
|
380
382
|
def decorator(
|
|
381
383
|
func: Callable[
|
|
382
|
-
Concatenate[SelectorOutput,
|
|
383
|
-
|
|
384
|
+
Concatenate[SelectorOutput, Args],
|
|
385
|
+
ReturnType,
|
|
384
386
|
],
|
|
385
|
-
) -> ViewReturnType[
|
|
387
|
+
) -> ViewReturnType[ReturnType, Args]: ...
|
|
386
388
|
@overload
|
|
387
389
|
def decorator(
|
|
388
390
|
func: Callable[
|
|
389
|
-
Concatenate[SelectorOutput,
|
|
390
|
-
Awaitable[
|
|
391
|
+
Concatenate[SelectorOutput, Args],
|
|
392
|
+
Awaitable[ReturnType],
|
|
391
393
|
],
|
|
392
|
-
) -> ViewReturnType[Awaitable[
|
|
394
|
+
) -> ViewReturnType[Awaitable[ReturnType], Args]: ...
|
|
393
395
|
|
|
394
396
|
def decorator(
|
|
395
397
|
func: Callable[
|
|
396
|
-
Concatenate[SelectorOutput,
|
|
397
|
-
AwaitableOrNot[
|
|
398
|
+
Concatenate[SelectorOutput, Args],
|
|
399
|
+
AwaitableOrNot[ReturnType],
|
|
398
400
|
],
|
|
399
|
-
) -> ViewReturnType[AwaitableOrNot[
|
|
401
|
+
) -> ViewReturnType[AwaitableOrNot[ReturnType], Args]:
|
|
400
402
|
_options = options or ViewOptions()
|
|
401
403
|
return Autorun(
|
|
402
404
|
store=self,
|
|
@@ -408,6 +410,7 @@ class Store(Generic[State, Action, Event], SerializationMixin):
|
|
|
408
410
|
auto_await=True,
|
|
409
411
|
initial_call=False,
|
|
410
412
|
reactive=False,
|
|
413
|
+
memoization=_options.memoization,
|
|
411
414
|
keep_ref=_options.keep_ref,
|
|
412
415
|
subscribers_initial_run=_options.subscribers_initial_run,
|
|
413
416
|
subscribers_keep_ref=_options.subscribers_keep_ref,
|
|
@@ -416,6 +419,36 @@ class Store(Generic[State, Action, Event], SerializationMixin):
|
|
|
416
419
|
|
|
417
420
|
return decorator
|
|
418
421
|
|
|
422
|
+
def with_state(
|
|
423
|
+
self: Store[State, Action, Event],
|
|
424
|
+
selector: Callable[[State], SelectorOutput],
|
|
425
|
+
) -> WithStateDecorator[SelectorOutput]:
|
|
426
|
+
"""Wrap a function, passing the result of the selector as its first argument.
|
|
427
|
+
|
|
428
|
+
Note that it has zero reactivity, it just runs the function with the result
|
|
429
|
+
of the selector whenever it is called explicitly. To make it reactive, use
|
|
430
|
+
`autorun` instead.
|
|
431
|
+
|
|
432
|
+
This is mostly for improving code oragnization and readability. Directly Using
|
|
433
|
+
`store._state` is also possible.
|
|
434
|
+
"""
|
|
435
|
+
|
|
436
|
+
def decorator(
|
|
437
|
+
func: Callable[
|
|
438
|
+
Concatenate[SelectorOutput, Args],
|
|
439
|
+
ReturnType,
|
|
440
|
+
],
|
|
441
|
+
) -> Callable[Args, ReturnType]:
|
|
442
|
+
def wrapper(*args: Args.args, **kwargs: Args.kwargs) -> ReturnType:
|
|
443
|
+
if self._state is None:
|
|
444
|
+
msg = 'Store has not been initialized yet.'
|
|
445
|
+
raise RuntimeError(msg)
|
|
446
|
+
return func(selector(self._state), *args, **kwargs)
|
|
447
|
+
|
|
448
|
+
return wrapper
|
|
449
|
+
|
|
450
|
+
return decorator
|
|
451
|
+
|
|
419
452
|
@property
|
|
420
453
|
def snapshot(self: Store[State, Action, Event]) -> SnapshotAtom:
|
|
421
454
|
"""Return a snapshot of the current state of the store."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/combine_reducers.py
RENAMED
|
File without changes
|
|
File without changes
|
{python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/serialization_mixin.py
RENAMED
|
File without changes
|
{python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux/side_effect_runner.py
RENAMED
|
File without changes
|
|
File without changes
|
{python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/monitor.py
RENAMED
|
File without changes
|
{python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/snapshot.py
RENAMED
|
File without changes
|
{python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/store.py
RENAMED
|
File without changes
|
{python_redux-0.19.1 → python_redux-0.19.2.dev2250307103575157485}/redux_pytest/fixtures/wait_for.py
RENAMED
|
File without changes
|
|
File without changes
|