Solution#2268
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The request meets the required criteria for approval.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| def wrapper(*args, **kwargs) -> Callable: | ||
| key = (args, tuple(kwargs.items())) | ||
|
|
||
| if len(storage) == 0: |
There was a problem hiding this comment.
This if len(storage) == 0 check is unnecessary. The if key in storage check on line 16 already handles empty dictionaries correctly. Removing this branch will eliminate duplicated code.
| if len(storage) == 0: | ||
| storage[key] = func(*args, **kwargs) | ||
| print("Calculating new result") | ||
| return storage[key] |
There was a problem hiding this comment.
The code from lines 11-14 is duplicated in lines 19-21. Consider restructuring to avoid repeating the same logic twice - either use early return after checking cache, or always follow the pattern: check cache → calculate if needed → print → return.
|
|
||
| storage = {} | ||
|
|
||
| def wrapper(*args, **kwargs) -> Callable: |
There was a problem hiding this comment.
The return type -> Callable is misleading since this wrapper returns whatever type the decorated function returns, not a Callable. Consider removing this type hint or using a more appropriate generic type.
| @@ -9,7 +9,7 @@ | |||
| def test_cache_single_function(): | |||
| @cache | |||
| def long_time_func(a, b, c): | |||
There was a problem hiding this comment.
Unnecessary check for empty storage. The if key in storage condition already handles both empty and non-empty cases correctly, making this condition redundant.
| return (a**b**c) % (a * c) | ||
|
|
There was a problem hiding this comment.
DRY violation: The code storage[key] = func(*args, **kwargs); return storage[key] is duplicated across multiple branches (lines 12-13, 20-21). Consider restructuring to reduce duplication.
Solution