Skip to content

Commit 3708af6

Browse files
committed
feat(core): add _type field to the serialized immutable instances
1 parent 616dfc2 commit 3708af6

File tree

83 files changed

+247
-101
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+247
-101
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+
## Version 0.16.1
4+
5+
- feat(core): add `_type` field to the serialized immutable instances
6+
37
## Version 0.16.0
48

59
- feat(core): add blocking `wait_for_event_handlers` method to `Store` to wait for all event handlers to finish

poetry.lock

Lines changed: 96 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "python-redux"
3-
version = "0.16.0"
3+
version = "0.16.1"
44
description = "Redux implementation for Python"
55
authors = ["Sassan Haradji <[email protected]>"]
66
license = "Apache-2.0"
@@ -14,14 +14,16 @@ packages = [{ include = "redux" }, { include = "redux_pytest" }]
1414
python = "^3.11"
1515
python-immutable = "^1.1.1"
1616
python-strtobool = "^1.0.0"
17+
pyright = "^1.1.378"
18+
ruff = "^0.6.3"
1719

1820
[tool.poetry.group.dev]
1921
optional = true
2022

2123
[tool.poetry.group.dev.dependencies]
2224
poethepoet = "^0.24.4"
2325
pyright = "^1.1.376"
24-
ruff = "^0.5.7"
26+
ruff = "^0.6.0"
2527
pytest = "^8.1.1"
2628
pytest-cov = "^4.1.0"
2729
pytest-timeout = "^2.3.1"

redux/serialization_mixin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def _serialize_dataclass_to_dict(
3737
cls: type[SerializationMixin],
3838
obj: Immutable,
3939
) -> dict[str, Any]:
40-
result = {}
40+
result: dict[str, object] = {'_type': obj.__class__.__name__}
4141
for field in dataclasses.fields(obj):
4242
value = cls.serialize_value(getattr(obj, field.name))
4343
result[field.name] = value

redux_pytest/fixtures/event_loop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def create_task(self: LoopThread, coro: Coroutine) -> None:
2525
self.loop.call_soon_threadsafe(self.loop.create_task, coro)
2626

2727

28-
@pytest.fixture()
28+
@pytest.fixture
2929
def event_loop() -> LoopThread:
3030
loop_thread = LoopThread()
3131
loop_thread.start()

redux_pytest/fixtures/monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def monitor(self: StoreMonitor, store: Store) -> None:
3939
self.store.register_event_middleware(self._event_middleware)
4040

4141

42-
@pytest.fixture()
42+
@pytest.fixture
4343
def store_monitor(store: Store, mocker: MockerFixture) -> StoreMonitor:
4444
"""Fixture to check if an action was dispatched."""
4545
monitor = StoreMonitor(mocker)

redux_pytest/fixtures/snapshot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ def close(self: StoreSnapshot[State]) -> None:
145145
assert not json_path.exists(), f'Snapshot {filename} not taken'
146146

147147

148-
@pytest.fixture()
148+
@pytest.fixture
149149
def snapshot_prefix() -> str | None:
150150
"""Return the prefix for the snapshots."""
151151
return None
152152

153153

154-
@pytest.fixture()
154+
@pytest.fixture
155155
def store_snapshot(
156156
request: SubRequest,
157157
store: Store,

redux_pytest/fixtures/store.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
from redux.main import Store
1111

1212

13-
@pytest.fixture()
14-
def store() -> Store: # noqa: PT004 # pragma: no cover
13+
@pytest.fixture
14+
def store() -> Store: # pragma: no cover
1515
"""Provide current store (this is a placeholder returning None)."""
1616
msg = 'This fixture should be overridden.'
1717
raise NotImplementedError(msg)
1818

1919

20-
@pytest.fixture()
20+
@pytest.fixture
2121
def needs_finish(store: Store) -> Generator:
2222
"""Dispatch a finish action after the test."""
2323
yield None

redux_pytest/fixtures/wait_for.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def wrapper(*args: WaitForArgs.args, **kwargs: WaitForArgs.kwargs) -> None:
157157
return decorator(check) if check else decorator
158158

159159

160-
@pytest.fixture()
160+
@pytest.fixture
161161
def wait_for() -> Generator[WaitFor, None, None]:
162162
"""Provide `wait_for` decorator."""
163163
context = WaitFor()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-000
22
{
3+
"_type": "StateType",
34
"value": 0
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-001
22
{
3+
"_type": "StateType",
34
"value": 1
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-002
22
{
3+
"_type": "StateType",
34
"value": 3
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-003
22
{
3+
"_type": "StateType",
34
"value": 4
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-000
22
{
3+
"_type": "StateType",
34
"value": 0
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-001
22
{
3+
"_type": "StateType",
34
"value": 1
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-002
22
{
3+
"_type": "StateType",
34
"value": 3
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-003
22
{
3+
"_type": "StateType",
34
"value": 4
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-000
22
{
3+
"_type": "StateType",
34
"value": 0
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-001
22
{
3+
"_type": "StateType",
34
"value": 1
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-002
22
{
3+
"_type": "StateType",
34
"value": 3
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-003
22
{
3+
"_type": "StateType",
34
"value": 4
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-000
22
{
3+
"_type": "StateType",
34
"value": 0
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-001
22
{
3+
"_type": "StateType",
34
"value": 1
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-002
22
{
3+
"_type": "StateType",
34
"value": 3
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-003
22
{
3+
"_type": "StateType",
34
"value": 4
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-000
22
{
3+
"_type": "StateType",
34
"value": 0
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-001
22
{
3+
"_type": "StateType",
34
"value": 1
45
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// store-002
22
{
3+
"_type": "StateType",
34
"value": 4
45
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// store-000
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 10
68
},
79
"straight": {
10+
"_type": "CountStateType",
811
"count": 0
912
}
1013
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// store-001
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 11
68
},
79
"straight": {
10+
"_type": "CountStateType",
811
"count": 1
912
}
1013
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// store-002
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 12
68
},
79
"inverse": {
10+
"_type": "CountStateType",
811
"count": -1
912
},
1013
"straight": {
14+
"_type": "CountStateType",
1115
"count": 2
1216
}
1317
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// store-003
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 12
68
},
79
"inverse": {
10+
"_type": "CountStateType",
811
"count": -1
912
}
1013
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// store-004
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 10
68
},
79
"inverse": {
10+
"_type": "CountStateType",
811
"count": 1
912
}
1013
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// store-005
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 8
68
},
79
"inverse": {
10+
"_type": "CountStateType",
811
"count": 3
912
}
1013
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// store-autorun-000
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 10
68
},
79
"straight": {
10+
"_type": "CountStateType",
811
"count": 0
912
}
1013
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// store-autorun-001
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 11
68
},
79
"straight": {
10+
"_type": "CountStateType",
811
"count": 1
912
}
1013
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// store-autorun-002
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 12
68
},
79
"inverse": {
10+
"_type": "CountStateType",
811
"count": -1
912
},
1013
"straight": {
14+
"_type": "CountStateType",
1115
"count": 2
1216
}
1317
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// store-autorun-003
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 10
68
},
79
"inverse": {
10+
"_type": "CountStateType",
811
"count": 1
912
}
1013
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// store-autorun-004
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 8
68
},
79
"inverse": {
10+
"_type": "CountStateType",
811
"count": 3
912
}
1013
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// store-autorun_subscription-000
22
{
33
"_id": "e3e70682c2094cac629f6fbed82c07cd",
4+
"_type": "StateType",
45
"base10": {
6+
"_type": "CountStateType",
57
"count": 10
68
},
79
"straight": {
10+
"_type": "CountStateType",
811
"count": 0
912
}
1013
}

0 commit comments

Comments
 (0)