Skip to content
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

Solution #1362

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Solution #1362

wants to merge 2 commits into from

Conversation

Ryu-Tora
Copy link

No description provided.

Copy link

@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.

The code has a critical issue with using mutable types as keys in the cache dictionary, which can lead to runtime errors. It's important to ensure that the arguments used as keys are hashable, such as converting them to tuples. Please address this issue to ensure the caching mechanism works correctly. Keep up the good work, and once this is resolved, your implementation will be much more robust! 😊

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

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

app/main.py Show resolved Hide resolved
app/main.py Show resolved Hide resolved
@Ryu-Tora
Copy link
Author

e779df7

Copy link

@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.

Great job on implementing the caching decorator function! 🎉 While the code is mostly correct, remember to address the critical issue of using mutable arguments as dictionary keys. This will help you avoid runtime errors in the future. Keep up the good work and continue learning from these experiences!

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


@wraps(func)
def wrapper(*args) -> Any:
if args in cache_storage:

Choose a reason for hiding this comment

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

Using mutable arguments like lists or dictionaries as keys in a dictionary will raise a TypeError because they are not hashable. Consider converting arguments to a hashable type, such as a tuple, if they are not already hashable.

else:
print("Calculating new result")
result = func(*args)
cache_storage[args] = result

Choose a reason for hiding this comment

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

Similar to the previous comment, ensure that the arguments used as keys in the cache_storage dictionary are hashable to avoid runtime errors.

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