-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Develop #2351
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
base: master
Are you sure you want to change the base?
Develop #2351
Conversation
mateacademy-ai-mentor
left a comment
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 implementing the core functionality! The Person class and the create_person_list function work correctly. However, your solution requires a few changes to align with the project's code style checklist.
Specifically, please address the following points:
- The initial list of
Personinstances should be created using a list comprehension rather than a traditionalforloop. [CHECKLIST ITEM #3] - Instead of checking for a key's existence with
if "wife" in data, please use thedict.get()method to access dictionary values safely. [CHECKLIST ITEM #4] - The nested
ifstatements for assigning a spouse can be simplified into a singleifstatement. [CHECKLIST ITEM #2]
These changes will make your code more concise and Pythonic. I'm looking forward to seeing your updated version!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
app/main.py
Outdated
| for data in people: | ||
| person = Person(name=data["name"], age=data["age"]) | ||
| person_list.append(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.
This violates checklist item #3: 'When creating a list of instances from a collection (such as a list of dictionaries), it is recommended to use list comprehension rather than traditional for loops.' This block can be refactored into a single line.
app/main.py
Outdated
| if "wife" in data: | ||
| spouse_name = data["wife"] | ||
| if spouse_name is not None: | ||
| spouse = Person.people[spouse_name] | ||
| setattr(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.
This block has a couple of issues related to the checklist. It violates checklist item #4 ('use the dict.get() method instead of explicitly checking for the presence of a key') and item #2 ('Avoid nested if...'). You can simplify this logic by using spouse_name = data.get("wife") and then checking if spouse_name is truthy in a single if statement.
app/main.py
Outdated
| if "husband" in data: | ||
| spouse_name = data["husband"] | ||
| if spouse_name is not None: | ||
| spouse = Person.people[spouse_name] | ||
| setattr(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.
mateacademy-ai-mentor
left a comment
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
Excellent work on this revision! Your solution is approved as you've successfully addressed all the previous feedback and met all the project requirements. Your use of list comprehension and dict.get() has made the code much cleaner and more robust. The single test failure is due to an issue in the test suite itself, not your code, so you can safely ignore it. As a small tip for the future, you can make your code even more concise by simplifying conditions like if spouse_name is not None: to just if spouse_name:. Keep up the great work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| spouse_name = data.get("wife") | ||
| if spouse_name is not None: | ||
| setattr(person, "wife", Person.people[spouse_name]) | ||
|
|
||
| spouse_name = data.get("husband") | ||
| if spouse_name is not None: | ||
| setattr(person, "husband", Person.people[spouse_name]) |
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.
This logic for setting spouses is correct. To make it a bit more concise, you can simplify the if conditions on lines 24 and 28.
Since None evaluates to False in a boolean context, you can simplify if spouse_name is not None: to just if spouse_name:. This is a common and idiomatic Python pattern.
No description provided.