File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,12 +131,13 @@ def cache_info(self) -> dict[str, Any]:
131131 "hits" : self .hits ,
132132 "misses" : self .misses ,
133133 "capacity" : self .capacity ,
134- "size" : self .size
134+ "size" : self .size ,
135135 }
136136
137137
138138def lru_cache (maxsize : int = 128 ) -> Callable [[Callable [P , R ]], Callable [P , R ]]:
139139 """LRU Cache decorator"""
140+
140141 def decorator (func : Callable [P , R ]) -> Callable [P , R ]:
141142 cache = LRUCache (maxsize )
142143
@@ -146,8 +147,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
146147 key = (args , tuple (sorted (kwargs .items ())))
147148
148149 # 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 :
151151 return cast (R , cached )
152152
153153 # Compute and cache result
@@ -164,4 +164,5 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
164164
165165if __name__ == "__main__" :
166166 import doctest
167+
167168 doctest .testmod ()
You can’t perform that action at this time.
0 commit comments