Skip to content

Commit c7870bd

Browse files
committed
fix: minor type and linter adjustments.
1 parent 415d03a commit c7870bd

33 files changed

+665
-89
lines changed

benchmarks/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# ruff: noqa: D104
21
"""Benchmark package for python-redux."""

benchmarks/bench_autorun.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11

2+
from dataclasses import field, replace
3+
24
import pytest
3-
from redux.main import Store
4-
from redux.basic_types import BaseAction, StoreOptions
5-
from dataclasses import replace, field
65
from immutable import Immutable
76

7+
from redux.basic_types import BaseAction, StoreOptions
8+
from redux.main import Store
9+
10+
811
class State(Immutable):
912
value: int
1013
nested: dict = field(default_factory=dict)
@@ -23,49 +26,48 @@ def reducer(state, action):
2326
def store():
2427
return Store(reducer, options=StoreOptions(auto_init=True))
2528

26-
def test_autorun_creation(benchmark, store):
29+
def test_autorun_creation(benchmark, store) -> None:
2730
"""Benchmark creating autoruns."""
28-
29-
def run():
31+
32+
def run() -> None:
3033
@store.autorun(lambda s: s.value)
31-
def _(val):
34+
def _(val) -> None:
3235
pass
3336

3437
benchmark(run)
3538

36-
def test_autorun_reactivity(benchmark, store):
39+
def test_autorun_reactivity(benchmark, store) -> None:
3740
"""Benchmark autorun reaction overhead."""
38-
41+
3942
@store.autorun(lambda s: s.value)
40-
def _(val):
43+
def _(val) -> None:
4144
pass
42-
43-
def run():
45+
46+
def run() -> None:
4447
store.dispatch(IncrementAction())
4548

4649
benchmark(run)
4750

48-
def test_autorun_complex_selector(benchmark, store):
51+
def test_autorun_complex_selector(benchmark, store) -> None:
4952
"""Benchmark autorun with complex selector."""
50-
53+
5154
@store.autorun(lambda s: s.value * 2 + (s.nested.get('a', 0) or 0))
52-
def _(val):
55+
def _(val) -> None:
5356
pass
5457

55-
def run():
58+
def run() -> None:
5659
store.dispatch(IncrementAction())
5760

5861
benchmark(run)
5962

60-
def test_autorun_many_subscribers(benchmark, store):
63+
def test_autorun_many_subscribers(benchmark, store) -> None:
6164
"""Benchmark notification of many autoruns."""
62-
6365
for _ in range(100):
6466
@store.autorun(lambda s: s.value)
65-
def _(val):
67+
def _(val) -> None:
6668
pass
6769

68-
def run():
70+
def run() -> None:
6971
store.dispatch(IncrementAction())
7072

7173
benchmark(run)
Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11

22
from __future__ import annotations
3-
import uuid
3+
44
from typing import Any
5+
56
import pytest
7+
68
from redux import (
79
BaseAction,
8-
BaseEvent,
9-
CompleteReducerResult,
1010
InitAction,
1111
combine_reducers,
1212
)
1313
from redux.basic_types import Immutable
1414

15+
1516
class State(Immutable):
1617
value: int
1718

@@ -29,46 +30,46 @@ def create_reducers(count: int):
2930
return {f'r{i}': counter_reducer for i in range(count)}
3031

3132
@pytest.mark.benchmark(group='combine_reducers_creation')
32-
def test_creation(benchmark):
33+
def test_creation(benchmark) -> None:
3334
reducers = create_reducers(10)
34-
35-
def run():
35+
36+
def run() -> None:
3637
combine_reducers(State, **reducers)
37-
38+
3839
benchmark(run)
3940

4041
@pytest.mark.benchmark(group='combine_reducers_dispatch')
41-
def test_dispatch_10_reducers(benchmark):
42+
def test_dispatch_10_reducers(benchmark) -> None:
4243
reducers = create_reducers(10)
4344
reducer, _ = combine_reducers(State, **reducers)
4445
state = reducer(None, InitAction()).state
4546
action = IncrementAction()
46-
47-
def run():
47+
48+
def run() -> None:
4849
reducer(state, action)
49-
50+
5051
benchmark(run)
5152

5253
@pytest.mark.benchmark(group='combine_reducers_dispatch')
53-
def test_dispatch_50_reducers(benchmark):
54+
def test_dispatch_50_reducers(benchmark) -> None:
5455
reducers = create_reducers(50)
5556
reducer, _ = combine_reducers(State, **reducers)
5657
state = reducer(None, InitAction()).state
5758
action = IncrementAction()
58-
59-
def run():
59+
60+
def run() -> None:
6061
reducer(state, action)
61-
62+
6263
benchmark(run)
6364

6465
@pytest.mark.benchmark(group='combine_reducers_dispatch')
65-
def test_dispatch_100_reducers(benchmark):
66+
def test_dispatch_100_reducers(benchmark) -> None:
6667
reducers = create_reducers(100)
6768
reducer, _ = combine_reducers(State, **reducers)
6869
state = reducer(None, InitAction()).state
6970
action = IncrementAction()
70-
71-
def run():
71+
72+
def run() -> None:
7273
reducer(state, action)
73-
74+
7475
benchmark(run)

benchmarks/bench_dispatch.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ruff: noqa: D100, D101, D102, D103, D104, D107
1+
# ruff: noqa: D102
22
"""Benchmarks for python-redux Store operations."""
33

44
from __future__ import annotations
@@ -126,7 +126,6 @@ def run() -> None:
126126

127127
def test_dispatch_batch(benchmark, store: BenchStore) -> None:
128128
"""Benchmark batch dispatch (list of actions)."""
129-
130129
actions = [IncrementAction() for _ in range(100)]
131130

132131
def run() -> None:
@@ -212,7 +211,6 @@ def run_benchmark() -> None:
212211
for _ in range(50000):
213212
store.dispatch(IncrementAction())
214213

215-
print(f'Final state value: {store.state.value if store.state else None}')
216214
store.dispatch(FinishAction())
217215

218216

demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ruff: noqa: D100, D101, D102, D103, D104, D107, A003, T201
1+
# ruff: noqa: D100, D101, D103, T201
22
from __future__ import annotations
33

44
import time

profile_optimization.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import cProfile
22
import pstats
3-
from redux.basic_types import BaseAction, StoreOptions
3+
4+
from redux.basic_types import BaseAction
45
from redux.main import Store
56

7+
68
class IncrementAction(BaseAction):
79
pass
810

@@ -19,12 +21,11 @@ def reducer(state, action):
1921
for l in listeners:
2022
store._subscribe(l)
2123

22-
def run_benchmark():
24+
def run_benchmark() -> None:
2325
for _ in range(100):
2426
store.dispatch(IncrementAction())
2527

2628
# Profile
27-
print("Running profiling...")
2829
cProfile.run('run_benchmark()', 'logs/profile_subscribers.prof')
2930

3031
# Print stats

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ sanity = ["typecheck", "lint", "test"]
6767

6868
[tool.ruff]
6969
target-version = 'py311'
70+
extend-exclude = ["*.pyi"]
7071

7172
[tool.ruff.lint]
7273
select = ['ALL']
@@ -81,6 +82,8 @@ multiline-quotes = "double"
8182

8283
[tool.ruff.lint.per-file-ignores]
8384
"tests/*" = ["S101", "PLR0915", "PLR2004"]
85+
"benchmarks/*" = ["S101", "ANN", "D100", "D101", "D103", "D205", "D212", "D400", "D415", "PLR2004", "ARG001"]
86+
"profile_optimization.py" = ["ANN", "D100", "D101", "D103", "ARG001", "ARG005", "E741", "SLF001"]
8487

8588
[tool.ruff.format]
8689
quote-style = 'single'
@@ -90,6 +93,7 @@ profile = "black"
9093

9194
[tool.pyright]
9295
exclude = ['typings', '.venv']
96+
extraPaths = ["/opt/homebrew/lib/python3.11/site-packages"]
9397
filterwarnings = 'error'
9498

9599
[tool.pytest.ini_options]

0 commit comments

Comments
 (0)