-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Solution #1710
base: master
Are you sure you want to change the base?
Solution #1710
Conversation
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.
Thank you for your hard work on the Distance
class! 🚀 While your implementation is mostly correct, there are a few critical issues that need to be addressed to fully meet the task requirements:
-
Comparison Methods: The
__ge__
,__le__
,__eq__
,__gt__
, and__lt__
methods should be able to handle comparisons with bothDistance
objects and numeric types. Currently, they only handle numeric types. Please update these methods to include checks forDistance
objects. -
__iadd__
Return Type: The return type for the__iadd__
method should beDistance
, not(int, float)
. This method should return the modified instance ofDistance
.
Once these issues are resolved, your code will be in great shape! Keep up the excellent work and don't hesitate to reach out if you need further assistance. 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
app/main.py
Outdated
elif isinstance(other, (int, float)): | ||
return Distance(self.km + other) | ||
|
||
def __iadd__(self, other: (int, float)) -> (int, float): |
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.
The return type of the __iadd__
method should be Distance
, not (int, float)
. According to the task description, this method should return the modified instance of Distance
.
def __truediv__(self, other: (int, float)) -> "Distance": | ||
return Distance(round(self.km / other, 2)) | ||
|
||
def __lt__(self, other: (int, float)) -> bool: |
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.
The __lt__
method should be able to compare with both Distance
objects and numeric types. Currently, it only compares with numeric types. You should add a check to handle Distance
objects as well.
app/main.py
Outdated
def __lt__(self, other: (int, float)) -> bool: | ||
return self.km < other | ||
|
||
def __gt__(self, other: (int, float)) -> bool: |
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.
The __gt__
method should be able to compare with both Distance
objects and numeric types. Currently, it only compares with numeric types. You should add a check to handle Distance
objects as well.
app/main.py
Outdated
def __gt__(self, other: (int, float)) -> bool: | ||
return self.km > other | ||
|
||
def __eq__(self, other: (int, float)) -> bool: |
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.
The __eq__
method should be able to compare with both Distance
objects and numeric types. Currently, it only compares with numeric types. You should add a check to handle Distance
objects as well.
app/main.py
Outdated
def __eq__(self, other: (int, float)) -> bool: | ||
return self.km == other | ||
|
||
def __le__(self, other: (int, float)) -> bool: |
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.
The __le__
method should be able to compare with both Distance
objects and numeric types. Currently, it only compares with numeric types. You should add a check to handle Distance
objects as well.
app/main.py
Outdated
def __le__(self, other: (int, float)) -> bool: | ||
return self.km <= other | ||
|
||
def __ge__(self, other: int) -> bool: |
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.
The __ge__
method should be able to compare with both Distance
objects and numeric types. Currently, it only compares with numeric types. You should add a check to handle Distance
objects as well.
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.
Great job on improving the Distance
class implementation! 🎉 The comparison methods now correctly handle both Distance
objects and numeric types, which is a significant enhancement. However, there's a minor inconsistency with the parameter type hint in the __ge__
method. It should be aligned with the other comparison methods to allow both Distance
objects and numeric types.
Your __iadd__
method is spot on, returning the modified instance as required. Overall, your code meets the task requirements and constraints, and all necessary files are present.
Remember, addressing the type hint issue will further polish your code. Keep up the great work and continue learning from these experiences. Your efforts are paying off, and you're on the right track! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
app/main.py
Outdated
elif isinstance(other, (int, float)): | ||
return self.km <= other | ||
|
||
def __ge__(self, other: int) -> bool: |
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.
The parameter type hint for the __ge__
method is inconsistent with the other comparison methods. It should allow both Distance
objects and numeric types, similar to the other methods.
No description provided.