Skip to content

Commit 415d03a

Browse files
committed
refactor: Update module imports for improved type checking and Cython/Python fallback, and add __all__ declarations.
1 parent 21ba246 commit 415d03a

File tree

7 files changed

+3524
-2906
lines changed

7 files changed

+3524
-2906
lines changed

redux/_combine_reducers.c

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

redux/_combine_reducers.pyx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ from .basic_types import (
2727
from immutable import make_immutable
2828

2929
cdef class CombinedReducer:
30+
"""Cython implementation of combined reducer."""
3031
cdef object state_type
3132
cdef object state_class
3233
cdef dict reducers
@@ -176,6 +177,11 @@ def combine_reducers(
176177
event_type=BaseEvent,
177178
**reducers,
178179
):
180+
"""
181+
Combine multiple reducers into a single reducer.
182+
183+
Optimized Cython implementation.
184+
"""
179185
id_ = uuid.uuid4().hex
180186
# Copy reducers dict
181187
reducers_copy = reducers.copy()

redux/_store_core.c

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

redux/_store_core.pyx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ from redux.basic_types import (
2222
StoreOptions,
2323
AutorunOptions,
2424
ViewOptions,
25-
StoreOptions,
26-
AutorunOptions,
27-
ViewOptions,
2825
CompleteReducerResult,
2926
is_state_reducer_result,
3027
NOT_SET,
@@ -60,7 +57,12 @@ cdef class AwaitableWrapper:
6057
def awaited(self):
6158
return self.value[0]
6259

63-
class SubscribeEventCleanup:
60+
cdef class SubscribeEventCleanup:
61+
"""Helper class to handle subscription cleanup."""
62+
63+
cdef object unsubscribe
64+
cdef object handler
65+
6466
def __init__(self, unsubscribe, handler):
6567
self.unsubscribe = unsubscribe
6668
self.handler = handler
@@ -69,7 +71,7 @@ class SubscribeEventCleanup:
6971
return self.unsubscribe()
7072

7173
def __repr__(self):
72-
return f'AwaitableWrapper({self.coro}, awaited={self.awaited})'
74+
return f'SubscribeEventCleanup(handler={self.handler})'
7375
from libc.stdlib cimport malloc, free
7476

7577
cdef class Store:
@@ -439,6 +441,7 @@ cdef class Store:
439441

440442

441443
cdef class Autorun:
444+
"""Cython implementation of Autorun."""
442445
cdef object _store
443446
cdef object _selector
444447
cdef object _comparator

redux/autorun.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
"""Redux autorun module."""
22
from __future__ import annotations
33

4+
from typing import TYPE_CHECKING
5+
46
from .main import _USE_CYTHON
57

6-
if _USE_CYTHON:
8+
if TYPE_CHECKING:
9+
from ._autorun_py import Autorun
10+
elif _USE_CYTHON:
711
try:
812
from ._store_core import Autorun
913
except ImportError:
1014
from ._autorun_py import Autorun
1115
else:
1216
from ._autorun_py import Autorun
17+
18+
__all__ = ('Autorun',)

redux/combine_reducers.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1+
"""Redux combine_reducers module."""
12
from __future__ import annotations
23

3-
from typing import TYPE_CHECKING, TypeVar
4+
from typing import TYPE_CHECKING
45

5-
from .basic_types import (
6-
BaseCombineReducerState,
7-
)
6+
from .main import _USE_CYTHON
87

98
if TYPE_CHECKING:
10-
from ._combine_reducers_py import combine_reducers as combine_reducers_py
11-
12-
13-
CombineReducerState = TypeVar(
14-
'CombineReducerState',
15-
bound=BaseCombineReducerState,
16-
)
17-
18-
19-
try:
20-
from ._combine_reducers import combine_reducers as combine_reducers_cy
21-
22-
combine_reducers = combine_reducers_cy
23-
except ImportError:
249
from ._combine_reducers_py import combine_reducers
10+
elif _USE_CYTHON:
11+
try:
12+
from ._combine_reducers import combine_reducers
13+
except ImportError:
14+
from ._combine_reducers_py import combine_reducers
15+
else:
16+
from ._combine_reducers_py import combine_reducers
17+
18+
__all__ = ('combine_reducers',)

redux/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
from __future__ import annotations
44

55
import os
6+
from typing import TYPE_CHECKING
67

78
# Re-export basic types for compatibility with legacy imports
8-
from redux.basic_types import *
9+
from redux.basic_types import * # noqa: F403
910
_FORCE_PYTHON = os.environ.get('REDUX_FORCE_PYTHON', '0') == '1'
1011

11-
if not _FORCE_PYTHON:
12+
if TYPE_CHECKING:
13+
from redux._store_py import Store
14+
elif not _FORCE_PYTHON:
1215
try:
1316
from redux._store_core import Store
1417
_USE_CYTHON = True

0 commit comments

Comments
 (0)