Added class Distance#2852
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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 selfyou could write:
if isinstance(other, Distance):
self.km += other.km
return self
self.km += other
return selfThis 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
| def __iadd__(self, other: Distance | int | float) -> Distance: | ||
| if isinstance(other, Distance): | ||
| self.km += other.km | ||
| else: |
There was a problem hiding this comment.
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
No description provided.