-
Notifications
You must be signed in to change notification settings - Fork 2k
Result #2312
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?
Result #2312
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
Excellent work on the Distance class! The implementation correctly handles all the required arithmetic and comparison operations, which is the core of the task.
I am requesting a couple of changes to align your code with the project's checklist requirements.
- Type Annotations: The type hint for the
otherparameter in your magic methods isAny. Please make it more specific, such asDistance | int | float, as required by the type annotation guidelines. - Unnecessary
elseblocks: In methods like__truediv__and the comparison methods, you can remove theelseblock when theifblock contains areturn. The code inside theelsecan simply be unindented.
These changes are important for code clarity and adherence to the project's standards. Once they are made, your solution will be perfect!
✨ 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
| def __repr__(self) -> str: | ||
| return f"Distance(km={self.km})" | ||
|
|
||
| def __add__(self, other: Any) -> Distance: |
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 the type annotation guidelines in the checklist. The other parameter should have a more specific type than Any, such as Distance | int | float. Please update the type hints for all magic methods to reflect the actual types they support.
app/main.py
Outdated
| if isinstance(other, (int, float)): | ||
| new_km = self.km * other | ||
| return self.__class__(new_km) | ||
| else: |
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 #1 ('Avoid unnecessary else statements'). When an if block contains a return statement, the else block is redundant. You can remove the else and unindent return NotImplemented. This applies to __truediv__ and all comparison methods as well.
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 on incorporating the feedback from the last review! Your code is looking much cleaner, especially with the removal of the unnecessary else blocks. However, a small but important change is needed before this can be approved. The type annotations for the other parameter in __mul__ and __truediv__ are not quite right. According to the project requirements, these methods should only accept numeric types. Please update the type hint in both methods to be int | float. This will align the code with the checklist requirement that "__truediv__ and __mul__ should not accept a Distance instance as an argument." Once that's fixed, your solution will be perfect. Keep up the great work!
✨ 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
| return NotImplemented | ||
| return self | ||
|
|
||
| def __mul__(self, other: Distance | int | float) -> Distance: |
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 type annotation for the other parameter isn't quite right here. According to the requirements, this method should only accept numeric types, not another Distance instance.
This violates checklist item #1 under 'Support correct types': "__truediv__ and __mul__ should not accept Distance instance as argument." Please adjust the type hint to int | float.
app/main.py
Outdated
| return self.__class__(new_km) | ||
| return NotImplemented | ||
|
|
||
| def __truediv__(self, other: Distance | int | float) -> Distance: |
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.
Similar to __mul__, the type annotation for the other parameter here should only include numeric types.
This violates checklist item #1 under 'Support correct types': "__truediv__ and __mul__ should not accept Distance instance as argument." The type hint should be int | float.
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 submission! You've done a great job addressing the previous feedback on type annotations, and your code now correctly meets all the functional requirements. I am approving this solution to help you keep moving forward, but there's a small stylistic improvement I'd like you to consider for future reference.
In your __add__ and __iadd__ methods, you can make the code a bit cleaner and more consistent with your other magic methods. By returning the result directly inside the if and elif blocks, you can remove the final else block. This change would better align with the 'Avoid unnecessary else statements' guideline. This is just a minor point of style, and overall, your logic is solid. Keep up the fantastic work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| def __repr__(self) -> str: | ||
| return f"Distance(km={self.km})" | ||
|
|
||
| def __add__(self, other: Distance | int | float) -> Distance: |
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 method can be simplified to align with the style of the other magic methods in this class (like __mul__ or __lt__). By returning directly from within the if and elif blocks, you can remove the else block and the final return statement. This change would better follow the 'Avoid unnecessary else statements' guideline from the checklist.
| return NotImplemented | ||
| return self.__class__(new_km) | ||
|
|
||
| def __iadd__(self, other: Distance | int | float) -> Distance: |
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.
Similar to the __add__ method, this implementation can be refactored for consistency and simplicity. Returning self directly inside the if and elif blocks would allow you to remove the else block and make the code more aligned with the 'Make Code Easier' checklist item.
No description provided.