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

implement function "create_person_list" for py-person-class #1659

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

Conversation

ihetay
Copy link

@ihetay ihetay commented Dec 28, 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 efforts on this task! Your code is on the right track, but there are a few critical issues that need to be addressed before it can be approved:

  1. Error Handling for Missing Keys: Your code assumes that certain keys (like "wife" and "husband") exist in the people dictionary. This can lead to KeyError exceptions if the keys are missing. It's important to add error handling to manage these cases gracefully.

  2. Unique Names in Dictionary: The people dictionary uses names as keys, which means each name must be unique. Ensure that all names are unique to prevent overwriting existing entries.

  3. Utilization of person_list: The person_list is populated but not used effectively in the function. Consider how this list can be returned or utilized within your application to enhance functionality.

Addressing these issues will improve the robustness and reliability of your code. Keep up the great work, and I'm confident you'll have this sorted out in no time! 😊

✨ 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.

app/main.py Show resolved Hide resolved
def __init__(self, name: str, age: int) -> None:
self.name = name
self.age = age
Person.people[self.name] = self

Choose a reason for hiding this comment

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

This line adds the Person instance to the people dictionary using the person's name as the key. Ensure that the name is unique, or previous entries will be overwritten.

pass
person_list = []
for person in people:
person_list.append(Person(name=person["name"], age=person["age"]))

Choose a reason for hiding this comment

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

The person_list is being populated with Person instances, but this list is not used later in the function. Consider returning this list or using it in some way.

person_list.append(Person(name=person["name"], age=person["age"]))

for person in people:
current_person = Person.people[person["name"]]

Choose a reason for hiding this comment

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

Accessing Person.people[person['name']] assumes that the person already exists in the dictionary. Ensure that all names in the input list are unique and have been added to the dictionary.

app/main.py Outdated
current_person = Person.people[person["name"]]

if "wife" in person and person["wife"]:
current_person.wife = Person.people[person["wife"]]

Choose a reason for hiding this comment

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

This line assumes that the wife's name exists in the people dictionary. If the name does not exist, this will raise a KeyError. Consider adding error handling for missing keys.

app/main.py Outdated
current_person.wife = Person.people[person["wife"]]

if "husband" in person and person["husband"]:
current_person.husband = Person.people[person["husband"]]

Choose a reason for hiding this comment

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

Similar to the previous comment, this line assumes the husband's name exists in the people dictionary. Add error handling to manage cases where the name is not found.


if "husband" in person and person["husband"]:
current_person.husband = Person.people[person["husband"]]
return person_list

Choose a reason for hiding this comment

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

The person_list is returned, but it is not clear how it is used. Ensure that the function's return value is utilized effectively in the application.

Copy link

@Dimosphen1 Dimosphen1 left a comment

Choose a reason for hiding this comment

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

Several changes were requested

app/main.py Outdated
Comment on lines 7 to 8
if self not in Person.people:
Person.people[self.name] = self

Choose a reason for hiding this comment

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

There is no need to perform this check, assign the value directly

app/main.py Outdated
Comment on lines 19 to 22
if "wife" in person and person["wife"]:
wife_instance = Person.people.get(person["wife"])
if wife_instance:
current_person.wife = wife_instance

Choose a reason for hiding this comment

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

You could avoid using nested if condition (because you've created all instances in the previous loop) and write if condition more efficiently, e.g.

Suggested change
if "wife" in person and person["wife"]:
wife_instance = Person.people.get(person["wife"])
if wife_instance:
current_person.wife = wife_instance
if wife_name := person.get("wife"):
current_person.wife = Person.people[wife_name]

Choose a reason for hiding this comment

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

Rewrite if condition for husband as well

Copy link

@Dimosphen1 Dimosphen1 left a comment

Choose a reason for hiding this comment

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

LGTM, well done! One comment is left for consideration

Comment on lines +29 to +30
# checking for the presence of the key wife or husband and if found,
# assign the value wife or husband to the instance

Choose a reason for hiding this comment

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

There is no need to add such comments in the future since the code is self-descriptive enough

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