Skip to content

Fix some RUF012 per file ignores #11399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c03f16d
updating DIRECTORY.md
MaximSmolskiy May 1, 2024
1e66d4b
Merge branch 'TheAlgorithms:master' into master
MaximSmolskiy May 6, 2024
eea84ed
Fix some RUF012 per file ignores
MaximSmolskiy May 7, 2024
dc2d49c
Merge branch 'master' into fix-some-RUF012-per-file-ignores
MaximSmolskiy May 10, 2024
2c6a49a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 10, 2024
2a9b649
Fix
MaximSmolskiy May 10, 2024
432474a
Fix
MaximSmolskiy May 11, 2024
54cb87f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 11, 2024
4b560a4
Merge branch 'master' of https://github.com/MaximSmolskiy/Python
MaximSmolskiy Jun 16, 2024
b2e30e7
Merge branch 'master' of https://github.com/MaximSmolskiy/Python
MaximSmolskiy Jun 16, 2024
e6790b5
Merge branch 'master' of https://github.com/MaximSmolskiy/Python
MaximSmolskiy Aug 25, 2024
44e7ba4
Merge branch 'master' of https://github.com/MaximSmolskiy/Python
MaximSmolskiy Aug 25, 2024
804a8b7
Merge branch 'master' of https://github.com/MaximSmolskiy/Python
MaximSmolskiy Dec 22, 2024
2701dcd
Merge branch 'master' into fix-some-RUF012-per-file-ignores
MaximSmolskiy Dec 22, 2024
a12d419
Fix
MaximSmolskiy Dec 22, 2024
02dbed5
Improve
MaximSmolskiy Dec 22, 2024
61ec902
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 22, 2024
98c0f97
Improve
MaximSmolskiy Dec 22, 2024
06d0130
Merge branch 'fix-some-RUF012-per-file-ignores' of https://github.com…
MaximSmolskiy Dec 22, 2024
d97fe7a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 22, 2024
331a68c
Merge branch 'master' into fix-some-RUF012-per-file-ignores
MaximSmolskiy Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions other/lfu_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ class LFUCache(Generic[T, U]):
CacheInfo(hits=196, misses=100, capacity=100, current_size=100)
"""

# class variable to map the decorator functions to their respective instance
decorator_function_to_instance_map: dict[Callable[[T], U], LFUCache[T, U]] = {}

def __init__(self, capacity: int):
self.list: DoubleLinkedList[T, U] = DoubleLinkedList()
self.capacity = capacity
Expand Down Expand Up @@ -291,18 +288,23 @@ def decorator(
"""

def cache_decorator_inner(func: Callable[[T], U]) -> Callable[..., U]:
# variable to map the decorator functions to their respective instance
decorator_function_to_instance_map: dict[
Callable[[T], U], LFUCache[T, U]
] = {}

def cache_decorator_wrapper(*args: T) -> U:
if func not in cls.decorator_function_to_instance_map:
cls.decorator_function_to_instance_map[func] = LFUCache(size)
if func not in decorator_function_to_instance_map:
decorator_function_to_instance_map[func] = LFUCache(size)

result = cls.decorator_function_to_instance_map[func].get(args[0])
result = decorator_function_to_instance_map[func].get(args[0])
if result is None:
result = func(*args)
cls.decorator_function_to_instance_map[func].put(args[0], result)
decorator_function_to_instance_map[func].put(args[0], result)
return result

def cache_info() -> LFUCache[T, U]:
return cls.decorator_function_to_instance_map[func]
return decorator_function_to_instance_map[func]

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

Expand Down
18 changes: 10 additions & 8 deletions other/lru_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ class LRUCache(Generic[T, U]):
CacheInfo(hits=194, misses=99, capacity=100, current size=99)
"""

# class variable to map the decorator functions to their respective instance
decorator_function_to_instance_map: dict[Callable[[T], U], LRUCache[T, U]] = {}

def __init__(self, capacity: int):
self.list: DoubleLinkedList[T, U] = DoubleLinkedList()
self.capacity = capacity
Expand Down Expand Up @@ -308,18 +305,23 @@ def decorator(
"""

def cache_decorator_inner(func: Callable[[T], U]) -> Callable[..., U]:
# variable to map the decorator functions to their respective instance
decorator_function_to_instance_map: dict[
Callable[[T], U], LRUCache[T, U]
] = {}

def cache_decorator_wrapper(*args: T) -> U:
if func not in cls.decorator_function_to_instance_map:
cls.decorator_function_to_instance_map[func] = LRUCache(size)
if func not in decorator_function_to_instance_map:
decorator_function_to_instance_map[func] = LRUCache(size)

result = cls.decorator_function_to_instance_map[func].get(args[0])
result = decorator_function_to_instance_map[func].get(args[0])
if result is None:
result = func(*args)
cls.decorator_function_to_instance_map[func].put(args[0], result)
decorator_function_to_instance_map[func].put(args[0], result)
return result

def cache_info() -> LRUCache[T, U]:
return cls.decorator_function_to_instance_map[func]
return decorator_function_to_instance_map[func]

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

Expand Down
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ lint.per-file-ignores."machine_learning/sequential_minimum_optimization.py" = [
lint.per-file-ignores."matrix/sherman_morrison.py" = [
"SIM103",
]
lint.per-file-ignores."other/l*u_cache.py" = [
"RUF012",
]
lint.per-file-ignores."physics/newtons_second_law_of_motion.py" = [
"BLE001",
]
Expand Down
Loading