Skip to content

Implement Distance class#2874

Open
anaelizabethmatecademy1973-byte wants to merge 7 commits into
mate-academy:masterfrom
anaelizabethmatecademy1973-byte:master
Open

Implement Distance class#2874
anaelizabethmatecademy1973-byte wants to merge 7 commits into
mate-academy:masterfrom
anaelizabethmatecademy1973-byte:master

Conversation

@anaelizabethmatecademy1973-byte

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread app/main.py Outdated
def __repr__(self):
return f"Distance(km={self.km})"

def __add__(self, other):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing type annotations. Add from __future__ import annotations at top and add annotations like def __add__(self, other: 'Distance | int | float') -> 'Distance':

Comment thread app/main.py Outdated
self.km += other
return self

def __mul__(self, other):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing type annotations. Add: def __mul__(self, other: int | float) -> Distance:

Comment thread app/main.py Outdated
return NotImplemented
return Distance(self.km * other)

def __truediv__(self, other):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing type annotations. Add: def __truediv__(self, other: int | float) -> Distance:

Comment thread app/main.py Outdated
return NotImplemented
return Distance(round(self.km / other, 2))

def __eq__(self, other):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread app/main.py Outdated
@@ -1,3 +1,60 @@
from typing import Any

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread app/main.py Outdated
def __repr__(self) -> str:
return f"Distance(km={self.km})"

def __add__(self, other: Any) -> "Distance":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread app/main.py Outdated
return Distance(self.km + other.km)
return Distance(self.km + other)

def __iadd__(self, other: Any) -> "Distance":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use proper type annotation: other: Distance | int | float instead of Any (CHECKLIST ITEM #1 example).

Comment thread app/main.py Outdated
Comment on lines +21 to +22
self.km += other.km
else:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread app/main.py Outdated
self.km += other
return self

def __mul__(self, other: Any) -> "Distance":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use proper type annotation: other: int | float only (NOT including Distance) per CHECKLIST ITEM #4. Distance should not be accepted as argument.

Comment thread app/main.py Outdated
return NotImplemented
return Distance(round(self.km / other, 2))

def __eq__(self, other: Any) -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use proper type annotations like other: Distance | int | float instead of Any (CHECKLIST ITEM #1).

Comment thread app/main.py Outdated
return self.km == other.km
return self.km == other

def __lt__(self, other: Any) -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use proper type annotations like other: Distance | int | float instead of Any (CHECKLIST ITEM #1).

Comment thread app/main.py Outdated
return self.km < other.km
return self.km < other

def __le__(self, other: Any) -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use proper type annotations like other: Distance | int | float instead of Any (CHECKLIST ITEM #1).

Comment thread app/main.py Outdated
return self.km <= other.km
return self.km <= other

def __gt__(self, other: Any) -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use proper type annotations like other: Distance | int | float instead of Any (CHECKLIST ITEM #1).

Comment thread app/main.py Outdated
return self.km > other.km
return self.km > other

def __ge__(self, other: Any) -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use proper type annotations like other: Distance | int | float instead of Any (CHECKLIST ITEM #1).

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Footnotes

  1. Rate AI review example

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