Skip to content

Solution#2268

Open
BogdanDemidkin2000 wants to merge 1 commit into
mate-academy:masterfrom
BogdanDemidkin2000:develop
Open

Solution#2268
BogdanDemidkin2000 wants to merge 1 commit into
mate-academy:masterfrom
BogdanDemidkin2000:develop

Conversation

@BogdanDemidkin2000
Copy link
Copy Markdown

Solution

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

Comment thread app/main.py
def wrapper(*args, **kwargs) -> Callable:
key = (args, tuple(kwargs.items()))

if len(storage) == 0:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread app/main.py
Comment on lines +11 to +14
if len(storage) == 0:
storage[key] = func(*args, **kwargs)
print("Calculating new result")
return storage[key]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread app/main.py

storage = {}

def wrapper(*args, **kwargs) -> Callable:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tests/test_main.py
@@ -9,7 +9,7 @@
def test_cache_single_function():
@cache
def long_time_func(a, b, c):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary check for empty storage. The if key in storage condition already handles both empty and non-empty cases correctly, making this condition redundant.

Comment thread tests/test_main.py
Comment on lines +12 to 13
return (a**b**c) % (a * c)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants