-
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 #1362
base: master
Are you sure you want to change the base?
Solution #1362
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.
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.
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.
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: |
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.
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 |
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.
Similar to the previous comment, ensure that the arguments used as keys in the cache_storage dictionary are hashable to avoid runtime errors.
No description provided.