-
Notifications
You must be signed in to change notification settings - Fork 2k
created class Distance, implemented all major operation(+-*/><>=<===) #2299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this 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 implementing the Distance class! The core logic for arithmetic and comparisons is mostly correct. However, there is a critical issue in your error handling that needs to be fixed. In the __truediv__ method, you are returning ZeroDivisionError instead of raising it. This is a functional bug because it won't stop execution as an exception should. Please change this to raise ZeroDivisionError("Cannot divide by zero") and update the method's return type hint accordingly.
Additionally, please address a few checklist violations:
- The type hints for the
otherparameter in__mul__and__truediv__should not accept aDistanceinstance. - To improve your type annotations, add
from __future__ import annotationsto the top of the file and remove the quotes from"Distance".
Once these changes are made, 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
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]
If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.
app/main.py
Outdated
| def __truediv__(self, other: Union[int, float, "Distance"])\ | ||
| -> Union["Distance", type(ZeroDivisionError)]: | ||
| if not isinstance(other, (int, float)): | ||
| return NotImplemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the NotImplemented return in all methods, as the methods return None by default. Here is an example of how you can simplify the code:
def truediv(self, other: int | float) -> Distance | None:
if isinstance(other, (int, float)) and other != 0:
return Distance(round(self.km / other, 2)) . Simplify logic in other methods please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done it, but i cant see any changes here on git hub. need ur help pls^^
| if isinstance(other, (int, float)): | ||
| return Distance(self.km * other) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this check here, your function anyway takes only int and float types, according to your type annotations
app/main.py
Outdated
| def __le__(self, other: Union[int, float, Distance]) -> bool: | ||
| other_km = self._get_km_value(other) | ||
| return self.km <= other_km | ||
|
|
||
| def __ge__(self, other: Union[int, float, Distance]) -> bool: | ||
| other_km = self._get_km_value(other) | ||
| return self.km >= other_km |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to rewrite these two methods in one line each. Use previously created magic methods
Hint: <= is the same as not >
DonDmytron
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

No description provided.