Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LLkaia committed Oct 25, 2024
1 parent e8301f9 commit c4b6d30
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +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 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`.
- `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 @@ -47,14 +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 robot's load capacity.
`current_load` purpose is to store `Cargo` instance, and it can be None by default.
If `Cargo` object was passed to function, use method `hook_load` to check if it can be hooked.
- `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 two conditions are True: `current_load` is set
to `None` and `cargo.weight` not greater than`max_load_weight`
of the drone, otherwise, do nothing.
- has `unhook_load` method, that set `current_load` to None without any additional logic.
`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
41 changes: 36 additions & 5 deletions checklist.md
Original file line number Diff line number Diff line change
@@ -1,16 +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:
```
2. If a variable can be `None`, you need to specify it in the annotation.

**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. Remember, if you want to check if a variable is set to `None` and assign a default value to it,
you can use the ternary operator: `variable = other if other else 0`.
Or even simpler: `variable = other or 0`. Simple is better than complex.

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 c4b6d30

Please sign in to comment.