-
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
wife/husband #1604
base: master
Are you sure you want to change the base?
wife/husband #1604
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! Your implementation of the Person
class and the create_person_list
function is mostly on point, but there are a few critical issues that need to be addressed before we can approve it:
-
Initialization of Attributes: The
Person
class currently does not initialize thewife
andhusband
attributes. This could lead toAttributeError
when these attributes are accessed. Please ensure these attributes are initialized in the class constructor to prevent potential runtime errors. -
Use of
dict.get()
Method: It's recommended to use thedict.get()
method when accessing dictionary values to avoid potential key errors. This will make your code more robust and cleaner.
These changes are important to ensure the functionality and reliability of your code. Once you've made these adjustments, feel free to resubmit your Pull Request. Keep up the great work! 🚀
✨ 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,25 @@ | |||
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.
The people
dictionary is used to store instances of Person
by name. This is a good approach for quick lookups.
def __init__(self, name: str, age: int) -> None: | ||
self.name = name | ||
self.age = age | ||
Person.people[name] = self |
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.
Storing the Person
instance in the people
dictionary by name is correct. Ensure that names are unique to avoid overwriting instances.
|
||
|
||
def create_person_list(people: list) -> list: | ||
# write your code here | ||
pass | ||
person_list = [Person(person["name"], person["age"]) for person in 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.
The list comprehension correctly creates Person
instances from the input list of dictionaries.
if "wife" in person and person["wife"]: | ||
spouse = Person.people.get(person["wife"]) | ||
if spouse: | ||
current_person.wife = spouse |
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 current_person
has a wife
attribute, but this attribute is not initialized in the Person
class. Consider initializing wife
and husband
attributes in the Person
class constructor.
spouse = Person.people.get(person["wife"]) | ||
if spouse: | ||
current_person.wife = spouse | ||
spouse.husband = current_person |
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.
Similarly, the spouse
object assumes a husband
attribute. Ensure these attributes are initialized in the Person
class to avoid potential AttributeError
.
elif "husband" in person and person["husband"]: | ||
spouse = Person.people.get(person["husband"]) | ||
if spouse: | ||
current_person.husband = spouse |
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 same issue as above applies here. Ensure that husband
and wife
attributes are initialized in the Person
class.
spouse = Person.people.get(person["husband"]) | ||
if spouse: | ||
current_person.husband = spouse | ||
spouse.wife = current_person |
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.
Again, ensure that wife
and husband
attributes are initialized in the Person
class to avoid potential AttributeError
.
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.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: 7]
If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.
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.
Review Summary
Great job on implementing the Person
class and the create_person_list
function! 🎉 Your solution is mostly correct and meets the task requirements. Here are some key points and suggestions for improvement:
-
Initialization of Attributes: Initially, the
Person
class did not initialize thewife
andhusband
attributes, which could lead toAttributeError
. It's crucial to initialize these attributes in the constructor, for example, by settingself.wife = None
andself.husband = None
. This has been addressed in your final solution, which is excellent! -
Use of
dict.get()
Method: You correctly used thedict.get()
method to access dictionary values, which is a good practice to avoid potential key errors. This makes your code more robust and cleaner.
Your final implementation effectively resolves the issues mentioned and adheres to the task constraints. While the decision is to APPROVE your pull request to help you move forward with your learning, please ensure to address any critical issues in future projects to avoid similar problems. Keep up the great work and continue to learn from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
pass | ||
people = {} | ||
|
||
def __init__(self, name: str, age: int) -> None: |
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 Person
class constructor should initialize the wife
and husband
attributes to None
to prevent potential AttributeError
when these attributes are accessed later. Consider adding self.wife = None
and self.husband = None
in the constructor.
No description provided.