-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 #1406
base: master
Are you sure you want to change the base?
Solution #1406
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this pull request! 😊 Your implementation of the caching decorator is mostly correct and meets many of the task requirements. However, there's a critical issue that needs to be addressed before we can approve the changes. The use of mutable arguments as keys in the dictionary can lead to runtime errors, as mutable types like lists or dictionaries are not hashable and will raise a TypeError
. To fix this, ensure that args
contains only immutable types, such as tuples of integers or strings. Once this issue is resolved, your code will be in great shape! Keep up the great work, and I look forward to your updated submission. 🚀
✨ 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Summary
Great job on implementing the caching decorator! 🎉 Your code effectively meets the task requirements by ensuring that only immutable arguments are used, utilizing a dictionary for caching, and correctly handling multiple functions with their own storage. The output messages are also correctly implemented.
However, there's a critical issue to address: the current implementation catches a TypeError
when arguments are not hashable and raises a ValueError
. While this works, it would be more robust to convert mutable arguments to immutable ones before using them as keys. This can prevent runtime errors and improve the reliability of your code.
Please review the comments and consider these improvements for future projects. This decision is made to help you move forward with your learning journey. Keep up the great work and continue to learn from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
app/main.py
Outdated
key = tuple(args) | ||
except TypeError as e: | ||
raise ValueError(f"All arguments must be hashable: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation catches a TypeError
if any argument is not hashable and raises a ValueError
. While this handles the error, it would be better to ensure that only immutable types are used as keys. Consider converting mutable arguments to immutable ones, such as using a tuple of tuples for lists or dictionaries, to avoid this issue.
No description provided.