-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 #1594
base: master
Are you sure you want to change the base?
Solution #1594
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.
Thank you for your hard work on this pull request! 😊 While your code meets most of the task requirements, there are a couple of critical issues that need to be addressed before we can approve it:
-
Handling Non-Existent Spouses: The current implementation assumes that the 'wife' and 'husband' keys will always have valid corresponding entries in the
people
dictionary. This could lead to aKeyError
if a specified spouse does not exist. Please add a check to ensure that the spouse exists in thepeople
dictionary before assigning them. -
Unique Identification for People: Using a class variable
people
to store instances by name can cause problems if names are not unique. Consider using a unique identifier or implementing a strategy to handle potential name collisions to ensure the integrity of your data.
By addressing these issues, your code will be more robust and reliable. Keep up the great work, and I look forward to seeing your improvements! 🚀
✨ 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.
@@ -1,8 +1,26 @@ | |||
class Person: | |||
# write your code here | |||
pass | |||
people = {} |
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 a class variable people
to store instances by name can lead to issues if names are not unique. Consider using a unique identifier or handling potential name collisions.
app/main.py
Outdated
if "wife" in person_data and person_data.get("wife"): | ||
person.wife = Person.people[person_data.get("wife")] | ||
if "husband" in person_data and person_data.get("husband"): | ||
person.husband = Person.people[person_data.get("husband")] |
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 code assumes that the 'wife' and 'husband' keys, if present, will always have valid corresponding entries in the people
dictionary. This could lead to a KeyError
if the specified spouse does not exist. Consider adding a check to ensure the spouse exists in the people
dictionary before assigning.
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 submission! Your implementation of the Person
class and the create_person_list
function is a great start. However, there are a few critical issues that need attention to ensure the robustness and reliability of your code:
-
Handling Non-Existent Spouses: Your code assumes that the 'wife' and 'husband' keys will always have valid corresponding entries in the
people
dictionary. This could lead to aKeyError
if a specified spouse does not exist. To prevent this, consider using thedict.get()
method to safely access the spouse from thepeople
dictionary. -
Unique Identification for People: While the task description specifies that all names are different, using names as keys in the
people
dictionary can still be risky if this assumption doesn't hold in all scenarios. Consider implementing a strategy to handle potential name collisions or using unique identifiers.
Despite these issues, I am approving your pull request to help you move forward with your learning. Please review the comments and address these issues in future iterations to improve your code's robustness and functionality. 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! ✨
app/main.py
Outdated
person_object = Person.people[person["name"]] | ||
if "wife" in person: | ||
if person["wife"]: | ||
wife = Person.people[person["wife"]] |
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.
Issue: The code assumes that the 'wife' exists in the Person.people
dictionary. This can lead to a KeyError
if the specified wife does not exist.
Suggestion: Add a check to ensure that the wife exists in the Person.people
dictionary before assigning them.
app/main.py
Outdated
person_object.wife = wife | ||
elif "husband" in person: | ||
if person["husband"]: | ||
husband = Person.people[person["husband"]] |
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.
Issue: The code assumes that the 'husband' exists in the Person.people
dictionary. This can lead to a KeyError
if the specified husband does not exist.
Suggestion: Add a check to ensure that the husband exists in the Person.people
dictionary before assigning them.
@@ -1,8 +1,26 @@ | |||
class Person: | |||
# write your code here | |||
pass | |||
people = {} |
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.
Issue: Using names as keys in the people
dictionary can cause issues if names are not unique.
Suggestion: Consider using a unique identifier for each person or implement a strategy to handle potential name collisions.
app/main.py
Outdated
for person in people: | ||
person_object = Person.people[person["name"]] | ||
if "wife" in person: | ||
if person["wife"]: | ||
wife = Person.people[person["wife"]] |
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.
Please simplify this condition by using only method .get(). This level of nesting is not good solution.
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! 😎
No description provided.