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' #907

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

Conversation

JohnnyWalker010
Copy link

No description provided.

Copy link

@NEkropo1 NEkropo1 left a comment

Choose a reason for hiding this comment

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

Think about changing default python behavior, which we don't want to change, like

3 + None

And refactor your code)

app/main.py Outdated
Comment on lines 17 to 18
elif isinstance(other, (int, float)):
return Distance(self.km + other)
Copy link

Choose a reason for hiding this comment

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

You can simplify the add method by returning the result of the addition directly without separate checks for int, or float. Python will automatically raise a TypeError if the other object is not of a type that supports addition with the types in your method. This simplifies the code and leverages Python's built-in type checking for arithmetic operations.
While your code will do nothing (return None) in case, for example, where we will try to add string to Distance object, which is unexpected behavior.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the explanation!

app/main.py Outdated
Comment on lines 28 to 29
if isinstance(other, Distance):
return None
Copy link

Choose a reason for hiding this comment

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

Why do we need these lines?

Copy link
Author

Choose a reason for hiding this comment

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

Before receiving your comment I misunderstood that Python returns None in such case. Many thanks!

app/main.py Outdated
self.km += other
return self

def __mul__(self, other: (Distance, int, float)) -> (Distance, None):
Copy link

Choose a reason for hiding this comment

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

use Union or |
Since for now this method should return a tuple, according to your annotation.

Copy link
Author

Choose a reason for hiding this comment

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

Done!

Copy link

@NEkropo1 NEkropo1 left a comment

Choose a reason for hiding this comment

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

Apply the principles and logic that you refactored in the last pushes to the entire app.

Copy link

@NEkropo1 NEkropo1 left a comment

Choose a reason for hiding this comment

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

Good job!

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.

3 participants