-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 #1779
base: master
Are you sure you want to change the base?
Solution #1779
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! 🎉 The functionality is solid and meets the task requirements. There are a few minor improvements you could consider, such as handling division by zero to prevent runtime errors and refining type hints for clarity and consistency. Keep up the excellent work and continue refining your skills! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
def __repr__(self) -> str: | ||
return f"Distance(km={self.km})" | ||
|
||
def __add__(self, other: "int| float | Distance") -> "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 hint for the other
parameter should be int | float | Distance
instead of the string format. This will ensure proper type checking and is consistent with the rest of the code.
return Distance(self.km + other.km) | ||
return Distance(self.km + other) | ||
|
||
def __iadd__(self, other: "int| float | Distance") -> "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 hint for the other
parameter should be int | float | Distance
instead of the string format. This will ensure proper type checking and is consistent with the rest of the code.
self.km += other | ||
return self | ||
|
||
def __mul__(self, other: int | float) -> "Distance | None": |
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 hint Distance | None
is misleading because the method does not return None
in any case. Consider removing None
from the type hint.
if isinstance(other, (int, float)): | ||
return Distance(self.km * other) | ||
|
||
def __truediv__(self, other: int | float) -> "Distance | None": |
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 hint Distance | None
is misleading because the method does not return None
in any case. Consider removing None
from the type hint.
return Distance(self.km * other) | ||
|
||
def __truediv__(self, other: int | float) -> "Distance | None": | ||
if isinstance(other, (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.
Consider adding a check to handle division by zero to prevent runtime errors.
No description provided.