Skip to content

Commit ee4db94

Browse files
committed
fix: avoid using asdict in combine-reducers's reducer as it can get too costly for large dataclasses and may even run into errors
1 parent 684a61c commit ee4db94

File tree

4 files changed

+43
-44
lines changed

4 files changed

+43
-44
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+
- fix: avoid using `asdict` in combine-reducers's reducer as it can get too costly for large dataclasses and may even run into errors
6+
37
## Version 0.20.0
48

59
- feat: add `memoization` option to `autorun`, default is `True`, compatible with old behavior, if set to `False`, calling the function explicitly will always run it regardless of the selector's value

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ dependencies = ["python-immutable >= 1.1.1", "python-strtobool >= 1.0.0"]
1313
[tool.uv]
1414
dev-dependencies = [
1515
"poethepoet >= 0.24.4",
16-
"pyright >= 1.1.376",
17-
"ruff >= 0.6.0",
16+
"pyright >= 1.1.396",
17+
"ruff >= 0.9.10",
1818
"pytest >= 8.1.1",
1919
"pytest-cov >= 4.1.0",
2020
"pytest-timeout >= 2.3.1",

redux/combine_reducers.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import functools
66
import operator
77
import uuid
8-
from dataclasses import asdict, fields
8+
from dataclasses import fields
99
from typing import TYPE_CHECKING, Any, TypeVar, cast
1010

1111
from immutable import make_immutable
@@ -74,18 +74,16 @@ def combined_reducer(
7474
)
7575
state = state_class(
7676
_id=state._id, # noqa: SLF001
77-
**(
78-
{
79-
key_: (
80-
reducer_result.state
81-
if is_complete_reducer_result(reducer_result)
82-
else reducer_result
83-
)
84-
if key == key_
85-
else getattr(state, key_)
86-
for key_ in reducers
87-
}
88-
),
77+
**{
78+
key_: (
79+
reducer_result.state
80+
if is_complete_reducer_result(reducer_result)
81+
else reducer_result
82+
)
83+
if key == key_
84+
else getattr(state, key_)
85+
for key_ in reducers
86+
},
8987
)
9088
result_actions += (
9189
reducer_result.actions or []
@@ -109,11 +107,8 @@ def combined_reducer(
109107
cast(Any, state_class).__dataclass_fields__ = fields_copy
110108

111109
state = state_class(
112-
**{
113-
key_: getattr(state, key_)
114-
for key_ in asdict(state)
115-
if key_ != key
116-
},
110+
_id=state._id, # noqa: SLF001
111+
**{key_: getattr(state, key_) for key_ in reducers if key_ != key},
117112
)
118113

119114
reducers_results = {

uv.lock

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

0 commit comments

Comments
 (0)