Skip to content

The solution#2179

Open
dianahorban477-bot wants to merge 5 commits intomate-academy:masterfrom
dianahorban477-bot:master
Open

The solution#2179
dianahorban477-bot wants to merge 5 commits intomate-academy:masterfrom
dianahorban477-bot:master

Conversation

@dianahorban477-bot
Copy link
Copy Markdown

No description provided.

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

You've set up the decorator structure correctly with a wrapper function, which is a great start. However, the implementation of the caching logic needs to be revised as it doesn't currently meet the core requirements.

Here are the main issues to address:

  1. The decorated function is never called. The func parameter is not being executed inside your wrapper, so no results are ever calculated.
  2. Results are not stored or returned. The cache doesn't store the function's output, and the wrapper incorrectly returns itself instead of the result.
  3. Inefficient cache data structure. A list is inefficient for lookups. A dict would be much better for mapping arguments to results.
  4. Incorrect cache check. The condition if args or kwargs in cash: doesn't correctly check if a specific set of arguments has been seen before.

Additionally, the print messages for 'Calculating' and 'Getting from cache' are swapped. Please review the logic to ensure you check the cache first, and only calculate (and store) the result if it's not found.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread app/main.py Outdated
Comment thread app/main.py Outdated
Comment thread app/main.py Outdated
Comment on lines +7 to +11
if args or kwargs in cash:
print ("Calculating new result")
else:
cash.append((args, kwargs))
print ("Getting from cache")
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 block doesn't correctly implement the caching logic. Here's a summary of the issues:

  1. The if condition does not correctly check if the arguments have been seen before.
  2. The print messages for 'Calculating' and 'Getting from cache' are swapped.
  3. The decorated function func is never actually called.
  4. The function's result is neither stored in the cache nor returned.

The correct logic should be:

  • Check if the arguments are in the cache.
  • If yes: print Getting from cache and return the stored value.
  • If no: print Calculating new result, call the original function, store its result in the cache, and then return that result.

Comment thread app/main.py Outdated
else:
cash.append((args, kwargs))
print ("Getting from cache")
return wrapper
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 wrapper function should not return itself. It must return the result of the decorated function, which is either newly calculated or retrieved from the cache.

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

Excellent work on this revision! I am approving your solution as you've successfully addressed all the feedback from the previous review. The cache decorator is now implemented perfectly: it correctly stores and retrieves results, handles multiple decorated functions independently, and manages different argument types as required. The code is clean, efficient, and fully meets all task requirements. Great job!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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