Skip to content

Resolução do exercício por Anderson Reichardt#2871

Open
AnderRei wants to merge 2 commits into
mate-academy:masterfrom
AnderRei:develop
Open

Resolução do exercício por Anderson Reichardt#2871
AnderRei wants to merge 2 commits into
mate-academy:masterfrom
AnderRei:develop

Conversation

@AnderRei

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am requesting changes because there are still checklist violations in your type annotations and one required style fix that need to be addressed before this solution is considered complete. Your __init__ currently uses km: int, but the task and tests require supporting floats (e.g., Distance(12.5)), so you should widen this to km: int | float to correctly reflect allowed inputs [CHECKLIST ITEM #1]. Likewise, __mul__ and __truediv__ are annotated with other: int, while the tests multiply and divide by floats (e.g., 5.88, 3.3), so these parameters must be typed as other: int | float and continue to reject Distance instances [CHECKLIST ITEM #1 / Support correct types].

Several methods in app/main.py use string-based union annotations such as "Distance | int", which the checklist marks as a bad pattern; replace these with modern unions like other: Distance | int | float (no quotes) across all affected magic methods [CHECKLIST ITEM #1]. In __iadd__, there is an unnecessary else after the if isinstance(other, Distance): branch; to follow the checklist rule on avoiding unnecessary else, handle the Distance case in the if, then directly handle the numeric case afterwards without else, and return self once at the end. Functionally, your arithmetic, comparisons, and string representations are all very close to perfect, so once you fix the annotations and simplify that __iadd__ branch, your solution will fully meet the task and checklist requirements—nice work so far, you’re almost there.


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

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread app/main.py Outdated
class Distance:
# Write your code here
pass
def __init__(self, km: int) -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item Type Annotations #1: your parameter is annotated as km: int, but the tests and description require supporting floats (e.g., Distance(12.5)), so km should be typed to accept both int and float (e.g., km: int | float).

Comment thread app/main.py Outdated
def __repr__(self) -> str:
return f"Distance(km={self.km})"

def __add__(self, other: "Distance | int") -> "Distance":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item Type Annotations #1: using the string annotation "Distance | int" is considered a bad example; you should use proper union types like Distance | int | float (and drop the quotes) so the method matches the checklist’s good examples.

Comment thread app/main.py Outdated
def __iadd__(self, other: "Distance | int") -> "Distance":
if isinstance(other, Distance):
self.km += other.km
else:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checklist item Avoid unnecessary else statements #1: after handling the Distance case, you can directly handle the numeric case without an else; removing else here will follow the recommended pattern and keep the code simpler.

Comment thread app/main.py Outdated

return self

def __mul__(self, other: int) -> "Distance":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item Support correct types #1 and Type Annotations #1: __mul__ currently only accepts other: int, but tests multiply by floats (e.g. 5.88), and the checklist requires correct type support. Update the annotation to other: int | float and keep rejecting Distance instances.

Comment thread app/main.py Outdated
def __mul__(self, other: int) -> "Distance":
return Distance(self.km * other)

def __truediv__(self, other: int) -> "Distance":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item Support correct types #1 and Type Annotations #1: __truediv__ is annotated with other: int, but tests divide by floats (e.g. 3.3). It should accept int | float while still not accepting Distance instances.

Comment thread app/main.py Outdated
value = other.km if isinstance(other, Distance) else other
return self.km < value

def __gt__(self, other: "Distance | int") -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This uses a string-based union annotation "Distance | int", which matches the checklist’s bad examples. According to Type Annotations #1, you should use proper union types like Distance | int | float (without quotes).

Comment thread app/main.py Outdated
value = other.km if isinstance(other, Distance) else other
return self.km > value

def __eq__(self, other: "Distance | int") -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This uses a string-based union annotation "Distance | int", which the checklist marks as a bad example; update to a proper union type (e.g., Distance | int | float) to comply with Type Annotations #1.

Comment thread app/main.py Outdated
value = other.km if isinstance(other, Distance) else other
return self.km == value

def __le__(self, other: "Distance | int") -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This uses a string-based union annotation "Distance | int". Per checklist item Type Annotations #1, you should use modern union annotations like Distance | int | float without quotes.

Comment thread app/main.py Outdated
value = other.km if isinstance(other, Distance) else other
return self.km <= value

def __ge__(self, other: "Distance | int") -> bool:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This uses a string-based union annotation "Distance | int", which is listed as a bad pattern in the checklist. To meet Type Annotations #1, change it to a proper union such as other: Distance | int | float.

Comment thread tests/test_main.py
@pytest.mark.parametrize(
'kilometers,output',
"kilometers,output",
[

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item "Avoid unnecessary else statements": after the if isinstance(other, Distance): branch, you can update self.km for the non-Distance case without using else, then return self once at the end.

@AnderRei AnderRei left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

exercício corrigido.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am approving your solution because it now fully matches the task requirements and behaves correctly across all tested scenarios. Your Distance class implements all the required magic methods, and they correctly handle both Distance instances and numeric values for arithmetic and comparisons. Multiplication and division are properly restricted to int | float operands, and division results are rounded to two decimal places as specified. You also addressed the earlier checklist points by updating type annotations to modern union syntax, supporting both int and float where required, and simplifying __iadd__ to avoid unnecessary control flow. Overall, the implementation is clean, consistent, and should pass all the provided tests. Nice work incorporating the previous feedback into a polished final solution.


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

Footnotes

  1. Rate AI review example

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