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 #1643

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

Solution #1643

wants to merge 2 commits into from

Conversation

rpk6432
Copy link

@rpk6432 rpk6432 commented Dec 18, 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! 😊 While your implementation meets many of the task requirements, there are a couple of critical issues that need to be addressed before we can approve it:

  1. Class-Level Dictionary Modification: The create_person_list function modifies the class-level dictionary Person.people. This can lead to unintended behavior if the function is called multiple times, as it will accumulate entries from all calls. Consider resetting Person.people at the start of the function or using an instance-level dictionary to avoid this issue.

  2. Potential Overwriting in Person.people: Using names as keys in the Person.people dictionary can cause entries to be overwritten if two people have the same name. To prevent this, consider using unique identifiers for each person instead of names.

Addressing these issues will make your code more robust and prevent potential bugs in the future. 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,23 @@
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.

Using a dictionary with names as keys (Person.people) can lead to issues if two people have the same name, as one entry will overwrite the other. Consider using unique identifiers for each person.

app/main.py Outdated
Comment on lines 10 to 23
def create_person_list(people: list) -> list:
# write your code here
pass
for person in people:
name, age = person["name"], person["age"]
Person(name, age)

for person in people:
name = person["name"]
spouse = person.get("wife") or person.get("husband")
if spouse:
setattr(Person.people[name],
"wife" if "wife" in person else "husband",
Person.people[spouse])

return list(Person.people.values())

Choose a reason for hiding this comment

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

The function create_person_list modifies the class-level dictionary Person.people. If this function is called multiple times, it will accumulate people from all calls, which might not be the intended behavior. Consider resetting Person.people at the start of the function or using an instance-level dictionary.

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 updating the code in app/main.py! 🎉 You've made significant progress in addressing the issues previously mentioned. Here are some key points and suggestions for further improvement:

  1. Class-Level Dictionary Modification: You've correctly reset the Person.people dictionary at the start of the create_person_list function, which is essential to avoid accumulation from multiple calls. However, using names as keys can still lead to overwriting if two people share the same name. Consider using unique identifiers to prevent this issue.

  2. Relationship Assignment: The current implementation assumes that names for 'wife' and 'husband' exist in the Person.people dictionary, which could lead to KeyError exceptions if a name is not found. Ensure these names are validated or handled properly to enhance robustness.

  3. Use of dict.get(): While not critical, using dict.get() for accessing dictionary values can make your code cleaner and more concise. It's something to consider for future improvements.

Overall, your solution meets the task requirements and constraints. The decision to approve this pull request is made to help you move forward with your learning journey. Please review the comments to improve your code further. Addressing these critical issues will enhance the functionality and robustness of your code. Keep up the great work and continue learning from these experiences! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

@@ -1,8 +1,27 @@
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.

Using a class-level dictionary Person.people can lead to issues if multiple instances are created or if the function is called multiple times. Consider using instance-level storage or ensuring unique keys.

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.

Using name as a key in Person.people can cause overwriting if two people have the same name. Consider using a unique identifier for each person.

Comment on lines +19 to +21
if "wife" in person and person["wife"]:
Person.people[name].wife = Person.people[person["wife"]]
Person.people[person["wife"]].husband = Person.people[name]

Choose a reason for hiding this comment

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

Ensure that person['wife'] exists in Person.people before attempting to access it. This will prevent potential KeyError exceptions.

Comment on lines +23 to +25
if "husband" in person and person["husband"]:
Person.people[name].husband = Person.people[person["husband"]]
Person.people[person["husband"]].wife = Person.people[name]

Choose a reason for hiding this comment

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

Ensure that person['husband'] exists in Person.people before attempting to access it. This will prevent potential KeyError exceptions.

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.

2 participants