File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -131,12 +131,13 @@ def cache_info(self) -> dict[str, Any]:
131
131
"hits" : self .hits ,
132
132
"misses" : self .misses ,
133
133
"capacity" : self .capacity ,
134
- "size" : self .size
134
+ "size" : self .size ,
135
135
}
136
136
137
137
138
138
def lru_cache (maxsize : int = 128 ) -> Callable [[Callable [P , R ]], Callable [P , R ]]:
139
139
"""LRU Cache decorator"""
140
+
140
141
def decorator (func : Callable [P , R ]) -> Callable [P , R ]:
141
142
cache = LRUCache (maxsize )
142
143
@@ -146,8 +147,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
146
147
key = (args , tuple (sorted (kwargs .items ())))
147
148
148
149
# Try to get cached result
149
- cached = cache .get (key )
150
- if cached is not None :
150
+ if (cached := cache .get (key )) is not None :
151
151
return cast (R , cached )
152
152
153
153
# Compute and cache result
@@ -164,4 +164,5 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
164
164
165
165
if __name__ == "__main__" :
166
166
import doctest
167
+
167
168
doctest .testmod ()
You can’t perform that action at this time.
0 commit comments