Skip to content

Tasks completed#2862

Open
Xaks1 wants to merge 2 commits into
mate-academy:masterfrom
Xaks1:master
Open

Tasks completed#2862
Xaks1 wants to merge 2 commits into
mate-academy:masterfrom
Xaks1:master

Conversation

@Xaks1

@Xaks1 Xaks1 commented Jul 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

I am requesting changes because there are a few checklist violations that count as critical blockers for this task, even though your functional behavior is largely correct. Specifically, several methods in app/main.py use an else after an early return (e.g., __add__, __eq__, __lt__, __gt__, __le__, __ge__), which goes against [CHECKLIST ITEM #1]; you should remove the else and let the second return be the default fallthrough path. In multiple method signatures (e.g., __add__, __mul__, __truediv__, __iadd__), the return type is annotated as the string "Distance" instead of Distance, which violates [CHECKLIST ITEM #2] given that from __future__ import annotations is already in use. Also, __mul__ and __truediv__ currently accept Distance in their parameter types, but per [CHECKLIST ITEM #3] they must only accept numeric values, so change the parameter annotation to int | float and ensure the implementation reflects that constraint.

The core arithmetic and comparison logic looks solid and matches the described behavior for both Distance and numeric inputs, which is great. Once you update the unnecessary else branches, fix the type annotations to use Distance directly, and restrict __mul__/__truediv__ to numeric arguments, your solution will satisfy both the functional requirements and the checklist. Keep going—you’re very close; these are mainly structural and type-annotation refinements that will strengthen your code quality and adherence to the project 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
def __repr__(self) -> str:
return f"Distance(km={self.km})"

def __add__(self, other: int | float | Distance) -> "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.

This violates checklist item #2: "Use proper type annotations for function arguments and return types" because the return type is annotated as a string "Distance" instead of directly using Distance, especially given from __future__ import annotations at the top.

Consider changing the signature to def __add__(self, other: int | float | Distance) -> Distance:.

Comment thread app/main.py Outdated
Comment on lines +15 to +17
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.

This violates checklist item #1: "Avoid unnecessary else statements". You return inside the if branch, so the else is not needed.

Refactor to:

if isinstance(other, Distance):
    return Distance(self.km + other.km)
return Distance(self.km + other)

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

def __mul__(self, other: int | float | Distance) -> "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.

This violates checklist item #3: "__truediv__ and __mul__ should not accept Distance instance as argument". The parameter type currently includes Distance.

Update the annotation to other: int | float so this method only accepts numeric values.

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

def __mul__(self, other: int | float | Distance) -> "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.

This violates checklist item #2: the return type is annotated as "Distance" instead of Distance. With from __future__ import annotations, you should use Distance directly in the annotation.

Also, per checklist item #3, the parameter type should be int | float, not include Distance.

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

def __truediv__(self, other: int | float | Distance) -> "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.

This violates checklist item #3: "__truediv__ and __mul__ should not accept Distance instance as argument". The parameter type currently includes Distance.

Change the signature to def __truediv__(self, other: int | float) -> Distance:.

Comment thread app/main.py Outdated
Comment on lines +48 to +50
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.

This violates checklist item #1: unnecessary else after a return. You can remove else and let the second return be the default path.

Refactor to:

if isinstance(other, Distance):
    return self.km > other.km
return self.km > other

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

def __le__(self, other: int | float | Distance) -> 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.

This violates checklist item #2: the return type is annotated as "Distance" instead of Distance. Replace the string with the class name.

Also, note the extra space before : in else : is not needed, though this is a minor style issue compared to the checklist requirements.

Comment thread app/main.py Outdated
Comment on lines +54 to +56
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.

This violates checklist item #1: you have an unnecessary else after a return in the if branch.

You can write:

if isinstance(other, Distance):
    return self.km <= other.km
return self.km <= other

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

def __ge__(self, other: int | float | Distance) -> 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.

This violates checklist item #2: the return type is annotated as "Distance" instead of Distance. Update to -> Distance for proper type annotations.

Comment thread app/main.py Outdated
Comment on lines +60 to +62
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.

This violates checklist item #1: the else is unnecessary because you already return in the if branch.

Simplify to:

if isinstance(other, Distance):
    return self.km >= other.km
return self.km >= other

@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

I am approving your solution because it fully implements the Distance class as required and behaves correctly for all specified operations. The constructor, __str__, and __repr__ produce the expected formats, and arithmetic methods handle both Distance instances and numeric values correctly, including in-place addition. Your __mul__ and __truediv__ methods are restricted to numeric (int | float) arguments, and division results are properly rounded to two decimal places. All comparison operators work as intended for both Distance-to-Distance and Distance-to-number comparisons, returning accurate boolean results without unnecessary branches after early returns. The use of from __future__ import annotations and direct Distance type annotations matches the checklist and avoids forward-reference issues. Overall, the code is clear, functional, and meets the task’s functional and style requirements—well done.


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

3 participants