Skip to content

Conversation

@Guillelmina8
Copy link

No description provided.

Copy link

@ohorodnykostap ohorodnykostap left a comment

Choose a reason for hiding this comment

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

looks good.

Copy link

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

Choose a reason for hiding this comment

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

Review Summary

This is a solid start, and the core logic for most of the arithmetic methods is correct. However, some changes are needed before this can be approved.

There's a functional bug in all the comparison methods (e.g., __lt__, __gt__). When you compare two Distance objects, your code tries to compare a number (self.km) with a Distance object (other), which will cause a TypeError. You need to handle the case where other is also a Distance instance by comparing self.km with other.km.

Additionally, the type annotations throughout the class need to be corrected to meet the project's requirements.

  • You should add from __future__ import annotations at the top of the file to avoid using string-based hints like "Distance". [CHECKLIST ITEM #2.2]
  • The type hints for method parameters and return values are often incorrect. For example, in __add__, the other parameter should be typed as Distance | float | int, and the method should always return Distance. [CHECKLIST ITEM #2.1]

Please address these points, and your code will be ready for 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

app/main.py Outdated
@@ -1,3 +1,46 @@
from __future__ import division

Choose a reason for hiding this comment

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

This import is not what is needed for this task. According to checklist item #2.2, you should use from __future__ import annotations to allow forward references in type hints (like using Distance inside the Distance class definition) without needing to use strings.

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

def __add__(self, other: float | int) -> "float | int | Distance":

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.1. The type hint for other is incomplete; it should also accept a Distance object (Distance | float | int). Additionally, the return type should simply be Distance, as the method always returns a Distance instance.

app/main.py Outdated
Comment on lines 17 to 18
else:
return Distance(self.km + other)

Choose a reason for hiding this comment

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

This else block is unnecessary because the preceding if block contains a return statement. This violates checklist item #1.1: 'Avoid unnecessary else statements'. You can remove the else and unindent the return statement.

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

def __iadd__(self, other: float) -> "float | int | Distance":

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.1. The type hint for other is incomplete; it should accept Distance | int | float. The return type hint is also incorrect and should be Distance, as __iadd__ should return self.

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

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

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.1. The type hint for other should be int | float to accept both integers and floats. The return type should be Distance since a new Distance instance is always returned.

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

def __lt__(self, other: "Distance | float | int") -> bool:
return self.km < other

Choose a reason for hiding this comment

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

The logic here is brittle and might not work as expected in all cases. It currently relies on Python's rich comparison dispatching. A more explicit and readable implementation would check if other is a Distance instance and compare self.km with other.km accordingly.

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

def __gt__(self, other: "Distance | float | int") -> bool:
return self.km > other

Choose a reason for hiding this comment

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

The logic here is brittle and might not work as expected in all cases. It currently relies on Python's rich comparison dispatching. A more explicit and readable implementation would check if other is a Distance instance and compare self.km with other.km accordingly.

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

def __eq__(self, other: "Distance | float | int") -> bool:
return self.km == other

Choose a reason for hiding this comment

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

The logic here is brittle and might not work as expected in all cases. It currently relies on Python's rich comparison dispatching. A more explicit and readable implementation would check if other is a Distance instance and compare self.km with other.km accordingly.

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

def __le__(self, other: "Distance | float | int") -> bool:
return self.km <= other

Choose a reason for hiding this comment

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

The logic here is brittle and might not work as expected in all cases. It currently relies on Python's rich comparison dispatching. A more explicit and readable implementation would check if other is a Distance instance and compare self.km with other.km accordingly.

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

def __ge__(self, other: "Distance | float | int") -> bool:
return self.km >= other

Choose a reason for hiding this comment

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

The logic here is brittle and might not work as expected in all cases. It currently relies on Python's rich comparison dispatching. A more explicit and readable implementation would check if other is a Distance instance and compare self.km with other.km accordingly.

Copy link

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

Choose a reason for hiding this comment

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

Review Summary

Great work on this submission! The logic for all the methods is correct, and the type annotations are well-implemented. Your code successfully meets all the functional requirements.

However, a few changes are needed to align with the project's style guidelines. Several methods use an else block immediately after an if block that contains a return. This is redundant and violates a checklist requirement [CHECKLIST ITEM #1.1]. You can simplify this by removing the else statement and un-indenting the code within it.

Additionally, the from __future__ import division import at the top of the file is not necessary for Python 3 and can be removed.

Once these style issues are addressed, your solution will be ready. Keep up the great effort!


✨ 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

app/main.py Outdated
@@ -1,3 +1,62 @@
from __future__ import division

Choose a reason for hiding this comment

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

In Python 3, true division (/) is the default behavior, so this import is no longer necessary and can be removed.

app/main.py Outdated
def __add__(self, other: float | int | Distance) -> Distance:
if isinstance(other, Distance):
return Distance(self.km + other.km)
else:

Choose a reason for hiding this comment

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

This else block is unnecessary. Since the if block above it contains a return, the code inside the else can be unindented and the else: line removed. This violates checklist item #1.1: 'Avoid unnecessary else statements'.

app/main.py Outdated
def __lt__(self, other: Distance | float | int) -> bool:
if isinstance(other, Distance):
return self.km < other.km
else:

Choose a reason for hiding this comment

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

This else is unnecessary because the preceding if block contains a return statement. This violates checklist item #1.1.

app/main.py Outdated
def __gt__(self, other: Distance | float | int) -> bool:
if isinstance(other, Distance):
return self.km > other.km
else:

Choose a reason for hiding this comment

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

This else block can be removed. According to checklist item #1.1, an else is not needed when the if block contains a return.

app/main.py Outdated
def __eq__(self, other: Distance | float | int) -> bool:
if isinstance(other, Distance):
return self.km == other.km
else:

Choose a reason for hiding this comment

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

This else block is unnecessary due to the return in the if block, which violates checklist item #1.1.

app/main.py Outdated
def __le__(self, other: Distance | float | int) -> bool:
if isinstance(other, Distance):
return self.km <= other.km
else:

Choose a reason for hiding this comment

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

As per checklist item #1.1, this else statement can be removed since the if block above it contains a return.

app/main.py Outdated
def __ge__(self, other: Distance | float | int) -> bool:
if isinstance(other, Distance):
return self.km >= other.km
else:

Choose a reason for hiding this comment

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

This else block is redundant because the if block always returns if its condition is met. This violates checklist item #1.1.

Copy link

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

Choose a reason for hiding this comment

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

Review Summary

Excellent work on this submission! You've done a fantastic job addressing all the feedback from the previous review. The code is now much cleaner and more readable, especially with the removal of the redundant else blocks. Your solution fully complies with all project requirements and style guidelines. I am approving your solution, 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.

3 participants