-
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' #1496
base: master
Are you sure you want to change the base?
'Solution' #1496
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 the task requirements and effectively handles caching for immutable arguments. While there are some suggestions for improvement, such as renaming variables for clarity and ensuring arguments are hashable, these are minor and don't impact the core functionality. Keep up the good work and consider these suggestions for future enhancements! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
|
||
|
||
def cache(func: Callable) -> Callable: | ||
# Write your code here | ||
pass | ||
tuple_data = {} |
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.
Consider renaming tuple_data
to something more descriptive like cache_storage
to better convey its purpose as a cache.
tuple_data = {} | ||
|
||
def inner(*args, **kwargs) -> Any: | ||
num = (args,) |
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 variable num
is used to store the arguments as a tuple. However, if args
contains mutable objects, this could lead to issues since mutable objects are not hashable. Ensure that the arguments are hashable or consider using a different approach to handle caching for mutable arguments.
num = (args,) | ||
if num in tuple_data: | ||
print("Getting from cache") | ||
return tuple_data.get(num) |
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 tuple_data.get(num)
is correct, but you could also use tuple_data[num]
since you have already checked for the key's existence in the dictionary.
No description provided.