-
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 #1396
base: master
Are you sure you want to change the base?
solution #1396
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.
Everything looks great. In my opinion your solution is simple and correct )
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 project! 😊 Your implementation of the caching decorator function is on the right track and meets many of the task requirements. However, there's a critical issue that needs to be addressed before we can approve the pull request. The current use of args
as a dictionary key can lead to runtime errors if any of its elements are mutable. This is because mutable elements, like lists, make args
unhashable, causing a TypeError
. To resolve this, consider converting args
to a fully hashable type or ensure that the function only accepts immutable arguments. Once this issue is fixed, your code will be much more robust and ready for approval. Keep up the great work! 🚀
✨ 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
Outdated
storage = {} | ||
|
||
def wrapper(*args: list) -> Any: | ||
if args in 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 args
directly as a dictionary key can lead to issues because args
is a tuple, which is hashable, but if any of its elements are mutable (like lists), it will cause a TypeError
. Consider converting args
to a hashable type that only contains immutable elements, or ensure that the function only accepts immutable arguments.
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 function! 🎉 Your solution meets the task requirements and constraints effectively. Here are some key points and suggestions for improvement:
-
Immutable Arguments: You've designed the decorator to work with functions that take immutable arguments, which is a crucial requirement. However, there's a critical issue with using
args
directly as part of the dictionary key. If any elements inargs
are mutable, it can lead to runtime errors since mutable elements makeargs
unhashable. To fix this, consider convertingargs
to a fully hashable type, such as a tuple, to ensure that the key is always hashable. -
Correct Functionality: The caching mechanism works as expected, checking if the result for given arguments is already cached and printing appropriate messages. This aligns well with the task requirements.
-
Handling Multiple Functions: You've implemented a separate
storage
dictionary for each decorated function, which ensures that the cache operates correctly with multiple functions simultaneously. -
Code Style and Cleanliness: Your code follows good practices with descriptive variable names and consistent style. It's clean and free of unnecessary comments or print statements.
While the implementation is solid, addressing the issue with mutable arguments will make your code more robust. This decision to approve is made to help you move forward with your learning. Please review the comments and improve your code accordingly. 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! ✨
storage = {} | ||
|
||
def wrapper(*args: Any, **kwargs: Any) -> Any: | ||
key = (args, tuple(sorted(kwargs.items()))) |
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
directly as part of the dictionary key can lead to runtime errors if any of its elements are mutable. Consider converting args
to a fully hashable type, such as a tuple, to ensure that the key is always hashable.
No description provided.