-
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
Solutionn #1655
base: master
Are you sure you want to change the base?
Solutionn #1655
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.
Great job on implementing the Distance
class! 🎉 Your code meets all the task requirements and constraints, including the correct use of magic methods and type annotations. Just a small note: when returning NotImplemented
for unsupported operations, ensure that the calling code handles this correctly to prevent any unexpected behavior. Keep up the excellent work! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
return Distance(self.km + other.km) | ||
elif isinstance(other, (int, float)): | ||
return Distance(self.km + other) | ||
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.
Returning NotImplemented
is correct for unsupported operations, but ensure that this behavior is handled properly in the calling code to avoid unexpected results.
def __mul__(self, factor: float) -> Distance: | ||
if isinstance(factor, (int, float)): | ||
return Distance(self.km * factor) | ||
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.
Returning NotImplemented
is appropriate here, but make sure the calling code handles this case to prevent errors.
def __truediv__(self, divisor: float) -> Distance: | ||
if isinstance(divisor, (int, float)) and divisor != 0: | ||
return Distance(round(self.km / divisor, 2)) | ||
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.
Returning NotImplemented
is suitable for unsupported operations. Ensure that the calling code can handle this return value correctly.
return self.km < other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km < other | ||
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.
Returning NotImplemented
is appropriate for unsupported comparisons. Ensure that this is handled in the calling code to avoid issues.
return self.km <= other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km <= other | ||
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.
Returning NotImplemented
is correct for unsupported comparisons. Ensure that this is handled properly in the calling code.
return self.km == other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km == other | ||
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.
Returning NotImplemented
is suitable for unsupported comparisons. Make sure the calling code handles this correctly.
return self.km != other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km != other | ||
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.
Returning NotImplemented
is appropriate for unsupported comparisons. Ensure that this is handled in the calling code.
return self.km > other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km > other | ||
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.
Returning NotImplemented
is correct for unsupported comparisons. Ensure that this is handled properly in the calling code.
return self.km >= other.km | ||
elif isinstance(other, (int, float)): | ||
return self.km >= other | ||
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.
Returning NotImplemented
is suitable for unsupported comparisons. Make sure the calling code handles this correctly.
No description provided.