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 #1694

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

taraspavlovskyi
Copy link

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.

Thank you for your hard work on this Pull Request! 😊 While you've made a great effort, there are a few critical issues that need to be addressed to ensure the code meets the task requirements and functions correctly:

  1. Type Annotations and Handling: The type annotations for several methods (__add__, __iadd__, __mul__, __truediv__, and comparison methods) are incorrect. These methods should accept either a Distance object or a numeric type (int or float). The current implementation assumes other is always a Distance object, which can lead to runtime errors and does not align with the task requirements.

  2. Magic Methods Implementation: The __mul__ and __truediv__ methods should be able to handle both Distance objects and numeric types. The current implementation only supports numeric types, which contradicts the type annotations.

  3. Comparison Methods: The comparison methods (__lt__, __gt__, __eq__, __le__, __ge__) should also handle both Distance objects and numeric types. The current implementation assumes other is a numeric type, which contradicts the type annotations.

  4. Code Style: There are unnecessary else statements in the __add__ and __iadd__ methods. While this is a minor issue, it's important to follow best practices for cleaner and more maintainable code.

Please address these issues to ensure the class functions correctly and safely. Keep up the great work, and don't hesitate to reach out if you need any help! 🌟

✨ 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
Comment on lines 27 to 28
def __mul__(self, other: Distance) -> Distance:
return Distance(self.km * other)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __mul__ method should check if other is a Distance instance or a numeric type. The current implementation assumes other is a numeric type, which contradicts the type annotation.

app/main.py Outdated
Comment on lines 30 to 31
def __truediv__(self, other: Distance) -> Distance:
return Distance(round(self.km / other, 2))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __truediv__ method should check if other is a Distance instance or a numeric type. The current implementation assumes other is a numeric type, which contradicts the type annotation.

app/main.py Outdated
Comment on lines 33 to 34
def __lt__(self, other: Distance) -> bool:
return self.km < other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __lt__ method should check if other is a Distance instance. The current implementation assumes other is a numeric type, which contradicts the type annotation.

app/main.py Outdated
Comment on lines 36 to 37
def __gt__(self, other: Distance) -> bool:
return self.km > other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __gt__ method should check if other is a Distance instance. The current implementation assumes other is a numeric type, which contradicts the type annotation.

app/main.py Outdated
Comment on lines 39 to 40
def __eq__(self, other: Distance) -> bool:
return self.km == other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __eq__ method should check if other is a Distance instance. The current implementation assumes other is a numeric type, which contradicts the type annotation.

app/main.py Outdated
Comment on lines 42 to 43
def __le__(self, other: Distance) -> bool:
return self.km <= other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __le__ method should check if other is a Distance instance. The current implementation assumes other is a numeric type, which contradicts the type annotation.

app/main.py Outdated
Comment on lines 45 to 46
def __ge__(self, other: Distance) -> bool:
return self.km >= other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __ge__ method should check if other is a Distance instance. The current implementation assumes other is a numeric type, which contradicts the type annotation.

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 effort on improving the Distance class implementation! 🎉 While there are a few critical issues that need attention, such as ensuring the __mul__ and __truediv__ methods handle both Distance objects and numeric types, and updating the comparison methods to consider Distance objects, your progress is commendable. Remember to refine your type annotations and clean up unnecessary else statements for better code style. Addressing these points will enhance the functionality and safety of your code. Keep up the excellent work, and use this opportunity to learn and grow! 🌟

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Comment on lines +26 to +27
def __mul__(self, other: Distance | float) -> Distance:
return Distance(self.km * other)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __mul__ method should handle both Distance objects and numeric types. Currently, it only supports numeric types. You need to add logic to handle the case where other is a Distance object.

Comment on lines +29 to +30
def __truediv__(self, other: Distance | float) -> Distance:
return Distance(round(self.km / other, 2))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __truediv__ method should handle both Distance objects and numeric types. Currently, it only supports numeric types. You need to add logic to handle the case where other is a Distance object.

Comment on lines +32 to +33
def __lt__(self, other: Distance | float) -> bool:
return self.km < other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __lt__ method assumes other is always a numeric type. You need to add logic to handle the case where other is a Distance object.

Comment on lines +35 to +36
def __gt__(self, other: Distance | float) -> bool:
return self.km > other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __gt__ method assumes other is always a numeric type. You need to add logic to handle the case where other is a Distance object.

Comment on lines +38 to +39
def __eq__(self, other: Distance | float) -> bool:
return self.km == other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __eq__ method assumes other is always a numeric type. You need to add logic to handle the case where other is a Distance object.

Comment on lines +41 to +42
def __le__(self, other: Distance | float) -> bool:
return self.km <= other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __le__ method assumes other is always a numeric type. You need to add logic to handle the case where other is a Distance object.

Comment on lines +44 to +45
def __ge__(self, other: Distance | float) -> bool:
return self.km >= other

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The __ge__ method assumes other is always a numeric type. You need to add logic to handle the case where other is a Distance object.

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.

2 participants