Skip to content

Commit 7ce998b

Browse files
Fix some RUF012 per file ignores (#11399)
* updating DIRECTORY.md * Fix some RUF012 per file ignores * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix * Fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix * Improve * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Improve * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: MaximSmolskiy <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 23eb174 commit 7ce998b

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

other/lfu_cache.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,6 @@ class LFUCache(Generic[T, U]):
196196
CacheInfo(hits=196, misses=100, capacity=100, current_size=100)
197197
"""
198198

199-
# class variable to map the decorator functions to their respective instance
200-
decorator_function_to_instance_map: dict[Callable[[T], U], LFUCache[T, U]] = {}
201-
202199
def __init__(self, capacity: int):
203200
self.list: DoubleLinkedList[T, U] = DoubleLinkedList()
204201
self.capacity = capacity
@@ -291,18 +288,23 @@ def decorator(
291288
"""
292289

293290
def cache_decorator_inner(func: Callable[[T], U]) -> Callable[..., U]:
291+
# variable to map the decorator functions to their respective instance
292+
decorator_function_to_instance_map: dict[
293+
Callable[[T], U], LFUCache[T, U]
294+
] = {}
295+
294296
def cache_decorator_wrapper(*args: T) -> U:
295-
if func not in cls.decorator_function_to_instance_map:
296-
cls.decorator_function_to_instance_map[func] = LFUCache(size)
297+
if func not in decorator_function_to_instance_map:
298+
decorator_function_to_instance_map[func] = LFUCache(size)
297299

298-
result = cls.decorator_function_to_instance_map[func].get(args[0])
300+
result = decorator_function_to_instance_map[func].get(args[0])
299301
if result is None:
300302
result = func(*args)
301-
cls.decorator_function_to_instance_map[func].put(args[0], result)
303+
decorator_function_to_instance_map[func].put(args[0], result)
302304
return result
303305

304306
def cache_info() -> LFUCache[T, U]:
305-
return cls.decorator_function_to_instance_map[func]
307+
return decorator_function_to_instance_map[func]
306308

307309
setattr(cache_decorator_wrapper, "cache_info", cache_info) # noqa: B010
308310

other/lru_cache.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ class LRUCache(Generic[T, U]):
209209
CacheInfo(hits=194, misses=99, capacity=100, current size=99)
210210
"""
211211

212-
# class variable to map the decorator functions to their respective instance
213-
decorator_function_to_instance_map: dict[Callable[[T], U], LRUCache[T, U]] = {}
214-
215212
def __init__(self, capacity: int):
216213
self.list: DoubleLinkedList[T, U] = DoubleLinkedList()
217214
self.capacity = capacity
@@ -308,18 +305,23 @@ def decorator(
308305
"""
309306

310307
def cache_decorator_inner(func: Callable[[T], U]) -> Callable[..., U]:
308+
# variable to map the decorator functions to their respective instance
309+
decorator_function_to_instance_map: dict[
310+
Callable[[T], U], LRUCache[T, U]
311+
] = {}
312+
311313
def cache_decorator_wrapper(*args: T) -> U:
312-
if func not in cls.decorator_function_to_instance_map:
313-
cls.decorator_function_to_instance_map[func] = LRUCache(size)
314+
if func not in decorator_function_to_instance_map:
315+
decorator_function_to_instance_map[func] = LRUCache(size)
314316

315-
result = cls.decorator_function_to_instance_map[func].get(args[0])
317+
result = decorator_function_to_instance_map[func].get(args[0])
316318
if result is None:
317319
result = func(*args)
318-
cls.decorator_function_to_instance_map[func].put(args[0], result)
320+
decorator_function_to_instance_map[func].put(args[0], result)
319321
return result
320322

321323
def cache_info() -> LRUCache[T, U]:
322-
return cls.decorator_function_to_instance_map[func]
324+
return decorator_function_to_instance_map[func]
323325

324326
setattr(cache_decorator_wrapper, "cache_info", cache_info) # noqa: B010
325327

pyproject.toml

-3
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ lint.per-file-ignores."machine_learning/sequential_minimum_optimization.py" = [
135135
lint.per-file-ignores."matrix/sherman_morrison.py" = [
136136
"SIM103",
137137
]
138-
lint.per-file-ignores."other/l*u_cache.py" = [
139-
"RUF012",
140-
]
141138
lint.per-file-ignores."physics/newtons_second_law_of_motion.py" = [
142139
"BLE001",
143140
]

0 commit comments

Comments
 (0)