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

wife/husband #1604

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

wife/husband #1604

wants to merge 4 commits into from

Conversation

Bleit1
Copy link

@Bleit1 Bleit1 commented Dec 3, 2024

No description provided.

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.


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:

  1. Initialization of Attributes: The Person class currently does not initialize the wife and husband attributes. This could lead to AttributeError when these attributes are accessed. Please ensure these attributes are initialized in the class constructor to prevent potential runtime errors.

  2. Use of dict.get() Method: It's recommended to use the dict.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 = {}

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

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]

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

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

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

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

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.

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.

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.

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.

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:

  1. Initialization of Attributes: Initially, the Person class did not initialize the wife and husband attributes, which could lead to AttributeError. It's crucial to initialize these attributes in the constructor, for example, by setting self.wife = None and self.husband = None. This has been addressed in your final solution, which is excellent!

  2. Use of dict.get() Method: You correctly used the dict.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:

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.

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