Skip to content

Commit db897b7

Browse files
committed
Use functools.cache to satisfy ruff UP033
1 parent a3fc426 commit db897b7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

dynamic_programming/knapsack.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
from __future__ import annotations
1010

1111
from collections.abc import Sequence
12-
from functools import lru_cache
12+
from functools import cache
1313

1414

1515
def mf_knapsack(i: int, wt: Sequence[int], val: Sequence[int], j: int) -> int:
1616
"""
1717
Return the optimal value for the 0/1 knapsack problem using memoization.
1818
19-
This implementation caches subproblems with ``functools.lru_cache`` and avoids
19+
This implementation caches subproblems with ``functools.cache`` and avoids
2020
global mutable state.
2121
2222
>>> mf_knapsack(4, [4, 3, 2, 3], [3, 2, 4, 4], 6)
@@ -38,7 +38,7 @@ def mf_knapsack(i: int, wt: Sequence[int], val: Sequence[int], j: int) -> int:
3838
weights = tuple(wt)
3939
values = tuple(val)
4040

41-
@lru_cache(maxsize=None)
41+
@cache
4242
def solve(item_count: int, capacity: int) -> int:
4343
if item_count == 0 or capacity == 0:
4444
return 0

0 commit comments

Comments
 (0)