-
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 #1351
base: master
Are you sure you want to change the base?
solution #1351
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.
LGTM
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 use of mutable types as dictionary keys is a critical issue that can lead to runtime errors. Please ensure that only immutable types are used as keys, or convert mutable arguments to a hashable type before caching. Keep up the good work, and once this issue is resolved, your code 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.
func_cache = {} | ||
|
||
def wrapper(*args) -> Any: | ||
if args in func_cache: |
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 types like lists or dictionaries as keys in a dictionary will raise a TypeError because they are not hashable. Consider using only immutable types like tuples as keys, or converting the arguments to a hashable type before using them as keys.
else: | ||
print("Calculating new result") | ||
result = func(*args) | ||
func_cache[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.
Ensure that the arguments used as keys in the dictionary are immutable. If the function can receive mutable arguments, consider converting them to a hashable type before storing them in the cache.
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 implementing the caching decorator function! 🎉 However, there's a critical issue with using mutable types as dictionary keys. Please review the comments and address this by converting args
to a hashable type, like a tuple of tuples. This will help you avoid similar problems 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! ✨
func_cache = {} | ||
|
||
def wrapper(*args) -> Any: | ||
if args in func_cache: |
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 args
as a dictionary key can lead to issues if args
contains mutable types like lists. Consider converting args
to a hashable type, such as a tuple of tuples, to ensure it can be used as a dictionary key.
No description provided.