Skip to content

Solution#2796

Open
fanfon4 wants to merge 3 commits into
mate-academy:masterfrom
fanfon4:develop
Open

Solution#2796
fanfon4 wants to merge 3 commits into
mate-academy:masterfrom
fanfon4:develop

Conversation

@fanfon4

@fanfon4 fanfon4 commented Jun 8, 2026

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

The implementation is functionally correct with all magic methods working as expected, but there are explicit checklist violations that need addressing. First, [CHECKLIST ITEM #1] violations: remove all unnecessary else statements after isinstance() checks in methods like __add__, __iadd__, __mul__, __truediv__, __lt__, __gt__, __eq__, __le__, and __ge__ — restructure to early returns or direct returns without the else block. Second, [CHECKLIST ITEM #4] violations: the type annotations for __mul__ and __truediv__ incorrectly include Distance in the union type (Distance | float should be int | float), and the isinstance checks with return None contradict the intended behavior — simply remove Distance from the type annotation and the isinstance check entirely. The core functionality is solid, so these are straightforward fixes to align with the coding standards.


✨ 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
Comment on lines +12 to +14
if isinstance(other, Distance):
return Distance(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.

Checklist item #1 violation: Avoid unnecessary else statements. The else here can be removed since the if block returns. Good pattern: if isinstance(...): return ... followed by return ...

Comment thread app/main.py Outdated
Comment on lines +18 to +20
if isinstance(other, Distance):
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.

Checklist item #1 violation: Unnecessary else statement. Can be simplified by removing else.

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

def __mul__(self, other: Distance | float) -> Distance | None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checklist item #4 violation: Type annotation includes Distance but should only be int | float. The isinstance check with return None contradicts proper type handling.

Comment thread app/main.py Outdated
Comment on lines +25 to +26
if isinstance(other, Distance):
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checklist item #1 violation: Unnecessary else statement. Can be simplified.

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

def __truediv__(self, other: Distance | float) -> Distance | None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checklist item #4 violation: Type annotation includes Distance but should only be int | float. Also return None is incorrect - should either raise an error or the type annotation should exclude Distance entirely.

Comment thread app/main.py Outdated
Comment on lines +37 to +39
if isinstance(other, Distance):
return 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.

Checklist item #1 violation: Unnecessary else statement.

Comment thread app/main.py Outdated
Comment on lines +43 to +45
if isinstance(other, Distance):
return 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.

Checklist item #1 violation: Unnecessary else statement.

Comment thread app/main.py Outdated
Comment on lines +49 to +51
if isinstance(other, Distance):
return 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.

Checklist item #1 violation: Unnecessary else statement.

Comment thread app/main.py Outdated
Comment on lines +55 to +57
if isinstance(other, Distance):
return 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.

Checklist item #1 violation: Unnecessary else statement.

Comment thread app/main.py Outdated
Comment on lines +61 to +63
if isinstance(other, Distance):
return 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.

Checklist item #1 violation: Unnecessary else statement.

@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, including arithmetic operations, comparisons, and string representations. The code properly handles Distance and numeric operands across all methods. There are two minor type annotation issues: __mul__ and __truediv__ (lines 23 and 26) include | None in their return types, but neither method ever returns None - these should simply be -> Distance. Additionally, consider adding from __future__ import annotations at the top of the file for better type annotation handling. These are cosmetic improvements rather than functional issues, so your solution meets the requirements.


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

Footnotes

  1. Rate AI review example

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

def __mul__(self, other: int | float) -> Distance | None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Return type annotation includes | None but the method always returns Distance. Change to -> Distance to match the actual behavior.

Comment thread app/main.py Outdated
def __mul__(self, other: int | float) -> Distance | None:
return Distance(self.km * other)

def __truediv__(self, other: int | float) -> Distance | None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Return type annotation includes | None but the method always returns Distance. Change to -> Distance to match the actual behavior.

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