Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

solution #1351

wants to merge 3 commits into from

Conversation

serhiik05
Copy link

No description provided.

Copy link

@spa7id spa7id left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

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

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.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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:

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants