-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 #1389
base: master
Are you sure you want to change the base?
Solution #1389
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 functions with immutable arguments. While there are some minor points to consider, such as ensuring args
is hashable and correctly checking each element's type, these don't impact the core functionality. Keep up the great work and continue refining your skills! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
result = {} | ||
|
||
def wrapper(*args) -> str: | ||
if isinstance(args, (int, float, bool, str, tuple)): |
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 isinstance
check is incorrect for args
. args
is a tuple, and this check will always return False
. You should iterate over args
and check each element instead.
|
||
def wrapper(*args) -> str: | ||
if isinstance(args, (int, float, bool, str, tuple)): | ||
if args in 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.
Checking args
in result
will not work as expected because args
is a tuple of arguments. You need to ensure that the tuple itself is hashable and can be used as a key in the dictionary.
return result[args] | ||
|
||
new_result = func(*args) | ||
result[args] = new_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 args
is hashable before using it as a key in the dictionary. If args
contains unhashable elements, this will raise a TypeError
.
No description provided.