Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Solution #1779

wants to merge 1 commit into from

Conversation

pewlay
Copy link

@pewlay pewlay commented Feb 20, 2025

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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":

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":

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":

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":

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)):

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants