-
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 #1643
base: master
Are you sure you want to change the base?
Solution #1643
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 implementing the Distance
class! Your code is mostly on point and meets the task requirements. However, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Type Annotations for Comparison Methods: The comparison methods (
__lt__
,__gt__
,__eq__
,__le__
,__ge__
) should return abool
, not aDistance
object. This is important for the expected behavior of comparison operations. -
Division by Zero Handling: In the
__truediv__
method, please add a check to handle division by zero. This will prevent runtime errors and ensure your code is robust. -
Handling Non-Numeric Types in
__mul__
: The__mul__
method should returnNotImplemented
whenother
is not anint
orfloat
. This will make your code more flexible and error-resistant.
Once these issues are resolved, your implementation will be in great shape! Keep up the great work, and I'm looking forward to seeing the improvements. 😊
✨ 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
return Distance(round(self.km / other, 2)) | ||
return NotImplemented | ||
|
||
def __lt__(self, other: int) -> "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 return type for the __lt__
method should be bool
, not Distance
. This applies to all comparison methods.
app/main.py
Outdated
return self.km < other.km | ||
return self.km < other | ||
|
||
def __gt__(self, other: int) -> "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 return type for the __gt__
method should be bool
, not Distance
. This applies to all comparison methods.
app/main.py
Outdated
return self.km > other.km | ||
return self.km > other | ||
|
||
def __eq__(self, other: int) -> "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 return type for the __eq__
method should be bool
, not Distance
. This applies to all comparison methods.
app/main.py
Outdated
return self.km == other.km | ||
return self.km == other | ||
|
||
def __le__(self, other: int) -> "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 return type for the __le__
method should be bool
, not Distance
. This applies to all comparison methods.
app/main.py
Outdated
return self.km <= other.km | ||
return self.km <= other | ||
|
||
def __ge__(self, other: int) -> "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 return type for the __ge__
method should be bool
, not Distance
. This applies to all comparison methods.
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: 7]
If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.
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! 🎉 You've made significant progress by correcting the type annotations for the comparison methods and ensuring proper handling of division by zero. However, there are still a few areas that need attention:
- Type Annotations: Ensure that the
other
parameter in the comparison methods (__lt__
,__gt__
,__eq__
,__le__
,__ge__
) is annotated asUnion[Distance, int, float]
to match the types being checked. __truediv__
Method: Includefloat
in the type annotation for theother
parameter, as the method checks for bothint
andfloat
types.
These adjustments will enhance the robustness and clarity of your code. Remember, addressing these issues will not only improve your current implementation but also help you avoid similar problems in the future. 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! ✨
return Distance(self.km * other) | ||
return NotImplemented | ||
|
||
def __truediv__(self, other: int) -> "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 type annotation for the other
parameter in the __truediv__
method should include float
as well, since the method checks for both int
and float
types.
return Distance(round(self.km / other, 2)) | ||
return NotImplemented | ||
|
||
def __lt__(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 type annotation for the other
parameter in the __lt__
method should be Union[Distance, int, float]
to match the types being checked in the method.
return self.km < other.km | ||
return self.km < other | ||
|
||
def __gt__(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 type annotation for the other
parameter in the __gt__
method should be Union[Distance, int, float]
to match the types being checked in the method.
return self.km > other.km | ||
return self.km > other | ||
|
||
def __eq__(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 type annotation for the other
parameter in the __eq__
method should be Union[Distance, int, float]
to match the types being checked in the method.
return self.km == other.km | ||
return self.km == other | ||
|
||
def __le__(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 type annotation for the other
parameter in the __le__
method should be Union[Distance, int, float]
to match the types being checked in the method.
return self.km <= other.km | ||
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 type annotation for the other
parameter in the __ge__
method should be Union[Distance, int, float]
to match the types being checked in the method.
def __repr__(self) -> str: | ||
return f"Distance(km={self.km})" | ||
|
||
def __add__(self, other: Union["Distance", int, float]) -> "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.
def __add__(self, other: Union["Distance", int, float]) -> "Distance": | |
def __add__(self, other: Union[Distance, int, float]) -> "Distance": |
please fix everywhere
No description provided.