Skip to content

Commit a97de62

Browse files
committed
refactor: use custom value NOT_SET = object() instead of None to signal the absence of a value for the default_value parameter in AutorunOptions and internally in Autorun class for properties storing last selector result and last call result
1 parent 9676fd3 commit a97de62

File tree

8 files changed

+19
-6
lines changed

8 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Upcoming
4+
5+
- refactor: use custom value `NOT_SET = object()` instead of `None` to signal the absence of a value for the `default_value` parameter in `AutorunOptions` and internally in `Autorun` class for properties storing last selector result and last call result
6+
37
## Version 0.24.0
48

59
- chore: add badges in `README.md` and classifiers in `pyproject.toml`

redux/autorun.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818

1919
from redux.basic_types import (
20+
NOT_SET,
2021
Action,
2122
Args,
2223
AutoAwait,
@@ -133,7 +134,7 @@ def __init__( # noqa: C901, PLR0912
133134
)
134135
self._options = options
135136

136-
self._last_selector_result: SelectorOutput | None = None
137+
self._last_selector_result: SelectorOutput | None = NOT_SET
137138
self._last_comparator_result: ComparatorOutput = cast(
138139
'ComparatorOutput',
139140
object(),
@@ -268,7 +269,7 @@ def call(
268269
) -> None:
269270
"""Call the wrapped function with the current state of the store."""
270271
func = self._func() if isinstance(self._func, weakref.ref) else self._func
271-
if func and self._last_selector_result is not None:
272+
if func and self._last_selector_result is not NOT_SET:
272273
value: ReturnType = call_func(
273274
func,
274275
[self._last_selector_result],
@@ -282,7 +283,7 @@ def call(
282283
is False # only explicit `False` disables auto-await, not `None`
283284
):
284285
if (
285-
self._latest_value is not None
286+
self._latest_value is not NOT_SET
286287
and isinstance(self._latest_value, AwaitableWrapper)
287288
and not self._latest_value.awaited
288289
):

redux/basic_types.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ class StoreOptions(Immutable, Generic[Action, Event]):
153153

154154
AutoAwait = TypeVar('AutoAwait', bound=Literal[True, False, None], infer_variance=True)
155155

156+
NOT_SET = object()
157+
156158

157159
class AutorunOptionsType(Immutable, Generic[ReturnType, AutoAwait]):
158160
default_value: ReturnType | None = None
@@ -218,7 +220,7 @@ def __init__( # noqa: PLR0913
218220

219221

220222
class AutorunOptionsImplementation(Immutable, Generic[ReturnType, AutoAwait]):
221-
default_value: ReturnType | None = None
223+
default_value: ReturnType | None = cast('None', NOT_SET)
222224
auto_await: AutoAwait = cast('AutoAwait', val=None)
223225
initial_call: bool = True
224226
reactive: bool = True
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// store-000
2-
1
2+
null
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
// store-001
2-
3
2+
1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// store-002
2+
null
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// store-003
2+
3
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// store-004
2+
null

0 commit comments

Comments
 (0)