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

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

Solution #1259

wants to merge 4 commits into from

Conversation

SchOleh
Copy link

@SchOleh SchOleh commented Oct 10, 2024

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.

You've done a great job here, but there are just a few things that need tweaking. Remember to avoid using mutable default arguments to prevent unexpected behaviour. Also, try to split up complex logical expressions for better readability. Keep up the good work! 😊

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

app/main.py Outdated
) -> None:
self.name = name
self.weight = weight
self.coords = coords if coords is not None else [0, 0]

Choose a reason for hiding this comment

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

The use of a mutable default argument in a function or method can lead to unexpected behaviour. In Python, default arguments are evaluated once when the function is defined, not each time the function is called. This means that if you use a mutable default argument and mutate it, you will mutate that object for all future calls to the function as well. Here, you should avoid using a mutable default argument (coords: list = None) and instead use a sentinel to denote that no argument was provided. The sentinel (in this case None) should then be handled inside the function or method.

self,
name: str,
weight: int,
coords: list = None

Choose a reason for hiding this comment

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

This is a repeat of the previous comment. Mutable default arguments can lead to unexpected behaviour. Instead, use a sentinel (like None) to denote that no argument was provided and handle this inside the function or method.

weight: int,
max_load_weight: int,
current_load: None,
coords: list = None

Choose a reason for hiding this comment

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

The current_load parameter is set to None which is not a type. It would be better to use Optional[Cargo] from the typing module to denote that current_load can be either a Cargo instance or None.

app/main.py Outdated
self.current_load = current_load

def hook_load(self, cargo: Cargo) -> None:
if self.current_load is None and cargo.weight <= self.max_load_weight:

Choose a reason for hiding this comment

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

This line contains a lot of logic. It might be good to split it up for readability. First, check if self.current_load is None, then if cargo.weight is less than or equal to self.max_load_weight. This is a code style issue.

self.current_load = cargo

def unhook_load(self) -> None:
self.current_load = None

Choose a reason for hiding this comment

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

This method sets self.current_load to None regardless of whether there's a load or not. It might be a good idea to first check if there's a load to unhook. If there isn't, you could either do nothing or raise an exception. This is a code quality issue.

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.

Hey there! 👋 You're doing a great job, but there's a few things that need to be addressed. Make sure your unhook_load method returns the unhooked cargo and check if current_load is None before hooking a new one in hook_load method. Also, don't forget to validate if current_load is an instance of Cargo class. Keep up the good work! 😊

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

current_load: Cargo,
coords: list = None
) -> None:
super().__init__(name, weight, coords)

Choose a reason for hiding this comment

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

You're not checking if the current_load parameter is an instance of Cargo class. It's important to validate the input to avoid potential errors in the future.

app/main.py Outdated
Comment on lines 70 to 75
def hook_load(self, cargo: Cargo) -> None:
if self.current_load is None:
if cargo.weight <= self.max_load_weight:
self.current_load = cargo

def unhook_load(self) -> None:

Choose a reason for hiding this comment

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

Your hook_load method allows to hook the cargo even if there is already one. You should add a condition to check if current_load is None before hooking a new one.

self.current_load = cargo

def unhook_load(self) -> None:
self.current_load = None

Choose a reason for hiding this comment

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

The unhook_load method sets current_load to None, but it doesn't return the unhooked load. It might be useful to return the unhooked cargo so that you can use it later.

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 overall! There are a few issues to be addressed, though. The handling for the case when the cargo weight is greater than the max load weight needs improvement. It would be better to raise an exception or print a message to let the user know that the cargo is too heavy. Also, the unhook_load method should return the current_load before setting it to None to avoid losing the current load. Lastly, avoid using mutable default arguments to prevent unexpected behavior. Keep up the good work and always strive to improve. 🚀

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

self.name = name
self.weight = weight
if coords is None:
coords = [0, 0]

Choose a reason for hiding this comment

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

It's not recommended to use mutable default arguments in Python. It can lead to unexpected behavior. Instead, use None and then assign the default value inside the function.

coords: list = None
) -> None:
if coords is None:
coords = [0, 0, 0]

Choose a reason for hiding this comment

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

Same issue as before, avoid using mutable default arguments. Use None and then assign the default value inside the function.

self.current_load = cargo

def unhook_load(self) -> Cargo:
self.current_load = None

Choose a reason for hiding this comment

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

The unhook_load method should return the current_load before setting it to None. Otherwise, the current load is lost and cannot be accessed after it's unhooked.

def hook_load(self, cargo: Cargo) -> None:
if self.current_load is None:
if cargo.weight <= self.max_load_weight:
self.current_load = cargo

Choose a reason for hiding this comment

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

There's no handling for the case when the cargo weight is greater than the max load weight. It would be better to raise an exception or print a message to let the user know that the cargo is too heavy.

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