Skip to content

Commit

Permalink
Merge pull request #1276 from LLkaia/update/clarify_description
Browse files Browse the repository at this point in the history
  • Loading branch information
sergii-nosachenko authored Oct 25, 2024
2 parents b165b7d + c4b6d30 commit 2cd4f48
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ Let's implement 3 classes with inheritance
- the `__init__` method takes `name`, `weight`, `coords`,
and saves them
- `coords` is list with `x` and `y` coordinates, set to [0, 0] by default.
It is not a good practice to use mutable object as a default parameter,
set it to `None` by default, and use condition.
- `go_forward`, `go_back`, `go_right` and `go_left` methods
take a `step` argument (1 by default) and move the robot by
`step` in the appropriate direction.
Positive Y axis is forward, positive X axis is right.
These functions should not return anything.

- `get_info` method returns a string in the next format `Robot: {name}, Weight: {weight}`
```python
robot = BaseRobot(name="Walle", weight=34, coords=[3, -2])
Expand Down Expand Up @@ -45,10 +45,13 @@ flying_robot.go_up(10)
- takes the same args as `FlyingRobot` and passes them
to the parent's `__init__` method.
- the `__init__` method also takes and stores `max_load_weight` and `current_load`.
- `max_load_weight` purpose is to store the robot's load capacity;
- `current_load` purpose is to store the `Cargo` instance, which can be None by default.
If `Cargo` object was passed to function, use method `hook_load` to check if it can be hooked.
- has `hook_load` method taking `Cargo` object and saves it to
`current_load` if `current_load` is `None` and `cargo.weight` not greater than
`max_load_weight` of the drone
- has `unhook_load` method, that set `current_load` to None
`current_load` if two conditions are True: `current_load` is set to `None` and `cargo.weight` is
not greater than `max_load_weight` of the drone. Otherwise, do nothing.
- has `unhook_load` method, that sets `current_load` to None without any additional logic.
```python
cargo = Cargo(14)
drone = DeliveryDrone(
Expand Down Expand Up @@ -76,3 +79,5 @@ drone = DeliveryDrone(
drone.unhook_load()
# drone.current_load is None
```

### Note: Check your code using this [checklist](checklist.md) before pushing your solution.
47 changes: 47 additions & 0 deletions checklist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Check Your Code Against the Following Points

1. If the function definition line is too long, place each parameter on a new line.

**Good example:**
```python
def long_function_name(
var_one,
var_two,
var_three,
var_four
) -> None:
```

**Bad example:**
```python
def long_function_name(var_one, var_two,
var_three,var_four) -> None:
```

2. If a variable can be `None`, specify it in the annotation.

3. Make sure you're not repeating yourself. If something can be done in the parent class, delegate it there.

4. To check if a variable is set to `None` and assign a default value, use the ternary operator:
`variable = other if other else 0`. Or even simpler: `variable = other or 0`.
Remember, a simple way is better than a complex one.

5. It is not a good practice to use mutable object as a default parameter of function,
set it to `None` by default. But in constructor itself you can use condition, and if `coords` equal to None,
assign [0, 0] to the `coords`.

**Good example:**
```python
def __init__(
default_var: list | None = None
) -> None:
self.default_var = default_var or [0, 0]
```

**Bad example:**
```python
def __init__(
default_var: list = [0, 0]
) -> None:
self.default_var = default_var
```

0 comments on commit 2cd4f48

Please sign in to comment.