Skip to content

Added class Distance#2852

Open
torsion85 wants to merge 1 commit into
mate-academy:masterfrom
torsion85:develop
Open

Added class Distance#2852
torsion85 wants to merge 1 commit into
mate-academy:masterfrom
torsion85:develop

Conversation

@torsion85

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 approving your solution because it fully meets the functional requirements and all core behaviors work correctly for initialization, string/repr output, arithmetic operations, and comparisons. Your Distance class correctly handles both Distance and numeric inputs where required, and respects the constraint that __mul__ and __truediv__ only accept numbers, with division rounded to two decimals. The only issue noted is a minor style point in app/main.py within __iadd__, where you use an else after an if that already determines the return path; this relates to the guideline to avoid unnecessary else blocks after an early return. For example, instead of:

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

you could write:

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

This is a stylistic improvement rather than a functional problem, so it does not block approval; overall, you’ve implemented the class cleanly and aligned well with the task 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
def __iadd__(self, other: Distance | int | float) -> Distance:
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.

This violates checklist item #1: "Avoid unnecessary else statements". After handling the Distance case, you can return directly and then fall through to self.km += other without using else.

Consider:

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

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