-
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 #1469
base: master
Are you sure you want to change the base?
Solution #1469
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.
Great job on implementing the caching decorator! 🎉 Your code meets all the task requirements and constraints effectively. The caching mechanism works well, storing and retrieving results as expected. Just a small note: ensure that both positional and keyword arguments are checked for immutability to prevent any potential issues. Keep up the excellent work! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
if any(isinstance(arg, (list, dict, set)) for arg in args): | ||
raise ValueError("All arguments must be immutable") |
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 check for immutability only covers the positional arguments (args
). You should also check the keyword arguments (kwargs
) to ensure they are immutable. Consider iterating over kwargs.values()
as well.
def wrapper(*args, **kwargs) -> Callable: | ||
if any(isinstance(arg, (list, dict, set)) for arg in args): | ||
raise ValueError("All arguments must be immutable") | ||
key = (func, args, frozenset(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 frozenset
to convert kwargs.items()
into an immutable type is correct, but ensure that all values in kwargs
are hashable. If any value is a mutable type, it will raise an error.
No description provided.