python-redux 0.25.2__cp314-cp314-win_arm64.whl
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.25.2.dist-info/METADATA +340 -0
- python_redux-0.25.2.dist-info/RECORD +30 -0
- python_redux-0.25.2.dist-info/WHEEL +5 -0
- python_redux-0.25.2.dist-info/licenses/LICENSE +201 -0
- python_redux-0.25.2.dist-info/top_level.txt +1 -0
- redux/__init__.c +5018 -0
- redux/__init__.cp314-win_arm64.pyd +0 -0
- redux/__init__.py +65 -0
- redux/autorun.c +19337 -0
- redux/autorun.cp314-win_arm64.pyd +0 -0
- redux/autorun.py +410 -0
- redux/basic_types.c +19301 -0
- redux/basic_types.cp314-win_arm64.pyd +0 -0
- redux/basic_types.py +514 -0
- redux/combine_reducers.c +11828 -0
- redux/combine_reducers.cp314-win_arm64.pyd +0 -0
- redux/combine_reducers.py +160 -0
- redux/main.c +22250 -0
- redux/main.cp314-win_arm64.pyd +0 -0
- redux/main.py +473 -0
- redux/py.typed +1 -0
- redux/serialization_mixin.c +9331 -0
- redux/serialization_mixin.cp314-win_arm64.pyd +0 -0
- redux/serialization_mixin.py +44 -0
- redux/side_effect_runner.c +13641 -0
- redux/side_effect_runner.cp314-win_arm64.pyd +0 -0
- redux/side_effect_runner.py +87 -0
- redux/utils.c +9301 -0
- redux/utils.cp314-win_arm64.pyd +0 -0
- redux/utils.py +49 -0
|
Binary file
|
redux/utils.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Utility functions for the project."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
from typing import TYPE_CHECKING, Any
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from collections.abc import Callable
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def is_method(func: Callable) -> bool:
|
|
13
|
+
"""Check if the function is a method."""
|
|
14
|
+
signature = inspect.signature(func)
|
|
15
|
+
return (
|
|
16
|
+
len(signature.parameters) > 0
|
|
17
|
+
and next(iter(signature.parameters.values())).name == 'self'
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def signature_without_selector(func: Callable) -> inspect.Signature:
|
|
22
|
+
"""Drop the parameter associated consumed by the with_store/autorun/view wrapper."""
|
|
23
|
+
signature = inspect.signature(func)
|
|
24
|
+
parameters = list(signature.parameters.values())
|
|
25
|
+
self_parameter: list[inspect.Parameter] = []
|
|
26
|
+
if is_method(func):
|
|
27
|
+
self_parameter = [parameters[0]]
|
|
28
|
+
parameters = parameters[1:]
|
|
29
|
+
if parameters and parameters[0].kind in [
|
|
30
|
+
inspect.Parameter.POSITIONAL_ONLY,
|
|
31
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
32
|
+
]:
|
|
33
|
+
parameters = parameters[1:]
|
|
34
|
+
return signature.replace(parameters=self_parameter + parameters)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def call_func(
|
|
38
|
+
func: Callable,
|
|
39
|
+
injecting_args: list,
|
|
40
|
+
*args: tuple,
|
|
41
|
+
**kwargs: dict,
|
|
42
|
+
) -> Any: # noqa: ANN401
|
|
43
|
+
"""Call function `func` respecting whether it is a method or a function."""
|
|
44
|
+
if is_method(func):
|
|
45
|
+
self_ = args[0]
|
|
46
|
+
args_ = args[1:]
|
|
47
|
+
return func(self_, *injecting_args, *args_, **kwargs)
|
|
48
|
+
|
|
49
|
+
return func(*injecting_args, *args, **kwargs)
|