-
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 #1711
base: master
Are you sure you want to change the base?
solution #1711
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 this implementation! 😊 There are a few critical issues that need to be addressed to meet the core requirements of the task:
-
Return Type for
__mul__
and__truediv__
: These methods should return a newDistance
instance rather than modifying the existing one. This is crucial as it aligns with the task requirement that these operations should yield a newDistance
object. -
Comparison Methods: The comparison methods (
__lt__
,__gt__
,__eq__
,__le__
,__ge__
) need to handle comparisons with bothDistance
instances and numeric types (int, float). This is essential for the functionality of the class as it ensures flexibility and correctness in comparisons.
Once these issues are resolved, your code will be much closer to meeting the task requirements. Keep up the great 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
def __mul__(self, factor: float) -> float: | ||
self.km *= factor | ||
return self |
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 __mul__
method should return a new Distance
instance instead of modifying self
and returning it. This aligns with the task requirement that the result of multiplication should be a new Distance
object.
app/main.py
Outdated
def __truediv__(self, divisor: float) -> float: | ||
self.km = round(self.km / divisor, 2) | ||
return self |
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 __truediv__
method should return a new Distance
instance instead of modifying self
and returning it. Ensure the result is a new Distance
object as specified in the task description.
app/main.py
Outdated
def __lt__(self, distance: float) -> bool: | ||
return self.km < distance |
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 Distance
objects as well as numeric types. Consider checking if distance
is an instance of Distance
and adjust the comparison accordingly.
app/main.py
Outdated
def __gt__(self, distance: float) -> bool: | ||
return self.km > distance |
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 handle comparisons with both Distance
instances and numeric types. Ensure to check the type of distance
and perform the comparison appropriately.
app/main.py
Outdated
def __eq__(self, distance: float) -> bool: | ||
return self.km == distance |
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 Distance
objects as well as numeric types. Adjust the logic to handle both cases.
app/main.py
Outdated
def __le__(self, distance: float) -> bool: | ||
return self < distance or self == distance |
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 handle comparisons with both Distance
instances and numeric types. Ensure the logic accommodates both scenarios.
app/main.py
Outdated
def __ge__(self, distance: float) -> bool: | ||
return self > distance or self == distance |
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 Distance
objects as well as numeric types. Adjust the logic to handle both cases.
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 effort on implementing the Distance
class with several magic methods! 🎉 While your implementation is mostly correct, there are a couple of critical issues that need attention:
-
Return Type for
__mul__
and__truediv__
: Currently, these methods return afloat
, but they should return a newDistance
instance. This is crucial as the task specifies that these operations should yield a newDistance
object. Ensure the return type annotation is updated toDistance
. -
Comparison Methods: You've done a great job with the comparison methods (
__lt__
,__gt__
,__eq__
,__le__
,__ge__
). They correctly handle comparisons with bothDistance
instances and numeric types, aligning well with the task requirements.
The decision to approve is made to help you move forward with your learning journey. However, please review the comments and address these issues to improve your code. It's important to fix these critical issues to ensure the functionality aligns with the task requirements. Keep up the good work, and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
def __mul__(self, factor: float) -> float: | ||
return Distance(self.km * factor) |
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 __mul__
method should return a new Distance
instance, not a float. The return type annotation should be Distance
instead of float
.
def __truediv__(self, divisor: float) -> float: | ||
return Distance(round(self.km / divisor, 2)) |
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 __truediv__
method should return a new Distance
instance, not a float. The return type annotation should be Distance
instead of float
.
No description provided.