Implement Distance class#2874
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your Distance class implementation is functionally correct and handles all operations properly (arithmetic, comparisons, string representations). However, the code fails checklist compliance because all magic methods are missing required type annotations. The linter is blocking the PR with ANN001 and ANN204 errors for missing parameter and return type annotations on __init__, __add__, __mul__, __truediv__, __eq__, __lt__, __gt__, __le__, __ge__, and other methods. Add from __future__ import annotations at the top of app/main.py, then annotate each magic method like def __add__(self, other: "Distance | int | float") -> "Distance": and ensure __init__ has def __init__(self, km: float) -> None:. Also add a trailing newline to the file (linting error W292). These are explicit checklist requirements that must be satisfied before approval.
✨ 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
| def __repr__(self): | ||
| return f"Distance(km={self.km})" | ||
|
|
||
| def __add__(self, other): |
There was a problem hiding this comment.
Missing type annotations. Add from __future__ import annotations at top and add annotations like def __add__(self, other: 'Distance | int | float') -> 'Distance':
| self.km += other | ||
| return self | ||
|
|
||
| def __mul__(self, other): |
There was a problem hiding this comment.
Missing type annotations. Add: def __mul__(self, other: int | float) -> Distance:
| return NotImplemented | ||
| return Distance(self.km * other) | ||
|
|
||
| def __truediv__(self, other): |
There was a problem hiding this comment.
Missing type annotations. Add: def __truediv__(self, other: int | float) -> Distance:
| return NotImplemented | ||
| return Distance(round(self.km / other, 2)) | ||
|
|
||
| def __eq__(self, other): |
There was a problem hiding this comment.
Missing type annotations for comparison methods. Add annotations to all comparison operators (eq, lt, le, gt, ge) with other: Distance | int | float and -> bool
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation is functionally correct with all magic methods working as expected. However, there are checklist violations that must be addressed: (1) Missing from __future__ import annotations at the top of app/main.py [CHECKLIST ITEM #2] — this is required to avoid potential NameError with forward reference string annotations; (2) All method annotations use Any instead of proper types [CHECKLIST ITEM #1] — use Distance | int | float for __add__, __iadd__, and comparison methods, and use int | float only for __mul__ and __truediv__ [CHECKLIST ITEM #4]; (3) The __iadd__ method has an unnecessary else statement — since the if block returns, the else is redundant, simply continue with self.km += other after the if block [CHECKLIST ITEM #1]; (4) Fix the trailing whitespace on blank lines and add a newline at the end of the file (W292/W293 flake8 errors). These are automated linting failures in your project, so they need to be corrected before the code can be approved.
✨ 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
| @@ -1,3 +1,60 @@ | |||
| from typing import Any | |||
There was a problem hiding this comment.
Missing from __future__ import annotations import at the top of the file (CHECKLIST ITEM #2). This is required to avoid NameError with forward reference string annotations.
| def __repr__(self) -> str: | ||
| return f"Distance(km={self.km})" | ||
|
|
||
| def __add__(self, other: Any) -> "Distance": |
There was a problem hiding this comment.
Use proper type annotation: other: Distance | int | float instead of Any (CHECKLIST ITEM #1 example). Since annotations are correct, explicit isinstance checks are not required.
| return Distance(self.km + other.km) | ||
| return Distance(self.km + other) | ||
|
|
||
| def __iadd__(self, other: Any) -> "Distance": |
There was a problem hiding this comment.
Use proper type annotation: other: Distance | int | float instead of Any (CHECKLIST ITEM #1 example).
| self.km += other.km | ||
| else: |
There was a problem hiding this comment.
Unnecessary else statement - follow the good pattern where the if block returns, then the rest executes (CHECKLIST ITEM #1). Remove the else and keep only self.km += other after the if block.
| self.km += other | ||
| return self | ||
|
|
||
| def __mul__(self, other: Any) -> "Distance": |
There was a problem hiding this comment.
Use proper type annotation: other: int | float only (NOT including Distance) per CHECKLIST ITEM #4. Distance should not be accepted as argument.
| return NotImplemented | ||
| return Distance(round(self.km / other, 2)) | ||
|
|
||
| def __eq__(self, other: Any) -> bool: |
There was a problem hiding this comment.
Use proper type annotations like other: Distance | int | float instead of Any (CHECKLIST ITEM #1).
| return self.km == other.km | ||
| return self.km == other | ||
|
|
||
| def __lt__(self, other: Any) -> bool: |
There was a problem hiding this comment.
Use proper type annotations like other: Distance | int | float instead of Any (CHECKLIST ITEM #1).
| return self.km < other.km | ||
| return self.km < other | ||
|
|
||
| def __le__(self, other: Any) -> bool: |
There was a problem hiding this comment.
Use proper type annotations like other: Distance | int | float instead of Any (CHECKLIST ITEM #1).
| return self.km <= other.km | ||
| return self.km <= other | ||
|
|
||
| def __gt__(self, other: Any) -> bool: |
There was a problem hiding this comment.
Use proper type annotations like other: Distance | int | float instead of Any (CHECKLIST ITEM #1).
| return self.km > other.km | ||
| return self.km > other | ||
|
|
||
| def __ge__(self, other: Any) -> bool: |
There was a problem hiding this comment.
Use proper type annotations like other: Distance | int | float instead of Any (CHECKLIST ITEM #1).
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work! Your Distance class implementation is now complete and fully compliant with all requirements. All magic methods (__add__, __iadd__, __mul__, __truediv__, comparison operators) are correctly implemented with proper type annotations. The from __future__ import annotations import is properly placed, and your type unions (Distance | int | float and int | float) are exactly as specified. Your code is clean, well-structured, and handles all edge cases properly. This demonstrates a solid understanding of Python magic methods and type annotations. Keep up the great work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.