Skip to content

Commit cb19682

Browse files
Merge pull request #36 from psobolewskiPhD/fomartting
Formatting with ruff and update the docstring in the text
2 parents f80b0ba + 678ddb4 commit cb19682

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

arrays/arrays.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def subtract_arrays(x, y):
1616

1717
def multiply_arrays(x, y):
1818
"""TODO: Write this function."""
19-
2019
pass
2120

2221

arrays/completed/arrays_completed.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
def add_arrays(x, y):
2-
"""
3-
Add two lists element-wise.
2+
"""Add two lists element-wise.
43
54
Parameters
65
----------
@@ -18,6 +17,7 @@ def add_arrays(x, y):
1817
--------
1918
>>> add_arrays([1, 4, 5], [4, 3, 5])
2019
[5, 7, 10]
20+
2121
"""
2222
if not isinstance(x, list) or not isinstance(y, list):
2323
raise TypeError("arguments should be arrays")
@@ -32,8 +32,7 @@ def add_arrays(x, y):
3232

3333

3434
def subtract_arrays(x, y):
35-
"""
36-
Subtract two lists element-wise.
35+
"""Subtract two lists element-wise.
3736
3837
Parameters
3938
----------
@@ -51,6 +50,7 @@ def subtract_arrays(x, y):
5150
--------
5251
>>> subtract_arrays([4, 7, 5], [2, 3, 5])
5352
[2, 4, 0]
53+
5454
"""
5555
if not isinstance(x, list) or not isinstance(y, list):
5656
raise TypeError("arguments should be arrays")
@@ -64,8 +64,7 @@ def subtract_arrays(x, y):
6464

6565

6666
def multiply_arrays(x, y):
67-
"""
68-
Multiply two lists element-wise.
67+
"""Multiply two lists element-wise.
6968
7069
Parameters
7170
----------
@@ -83,6 +82,7 @@ def multiply_arrays(x, y):
8382
--------
8483
>>> multiply_arrays([1, 4, 5], [4, 3, 5])
8584
[4, 12, 25]
85+
8686
"""
8787
if not isinstance(x, list) or not isinstance(y, list):
8888
raise TypeError("arguments should be arrays")
@@ -96,8 +96,7 @@ def multiply_arrays(x, y):
9696

9797

9898
def divide_arrays(x, y):
99-
"""
100-
Divide two lists element-wise.
99+
"""Divide two lists element-wise.
101100
102101
Parameters
103102
----------
@@ -115,6 +114,7 @@ def divide_arrays(x, y):
115114
--------
116115
>>> divide_arrays([6, 4, 5], [4, 2, 5])
117116
[1.5, 2, 1]
117+
118118
"""
119119
if not isinstance(x, list) or not isinstance(y, list):
120120
raise TypeError("arguments should be arrays")

arrays/completed/test_arrays_completed.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_divide_arrays(a, b, expect):
6363
[
6464
([1, 2], [1, 2, 3], ValueError),
6565
(1, "a", TypeError),
66-
]
66+
],
6767
)
6868
def test_add_arrays_errors(a, b, error):
6969
with pytest.raises(error):
@@ -75,7 +75,7 @@ def test_add_arrays_errors(a, b, error):
7575
[
7676
([1, 2], [1, 2, 3], ValueError),
7777
(1, "a", TypeError),
78-
]
78+
],
7979
)
8080
def test_subtract_arrays_errors(a, b, error):
8181
with pytest.raises(error):
@@ -87,7 +87,7 @@ def test_subtract_arrays_errors(a, b, error):
8787
[
8888
([1, 2], [1, 2, 3], ValueError),
8989
(1, "a", TypeError),
90-
]
90+
],
9191
)
9292
def test_multiply_arrays_errors(a, b, error):
9393
with pytest.raises(error):
@@ -100,7 +100,7 @@ def test_multiply_arrays_errors(a, b, error):
100100
([1, 2], [1, 2, 3], ValueError),
101101
(1, "a", TypeError),
102102
([1, 2, 3], [0, 2, 3], ZeroDivisionError),
103-
]
103+
],
104104
)
105105
def test_divide_arrays_errors(a, b, error):
106106
with pytest.raises(error):

docstrings.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
10. Now, put all the information you got together and write docstrings for the functions we have in `arrays.py`! As an example, I am adding an example docstring for `add_arrays()` below:
2424

2525
```python
26-
"""
27-
This function adds together each element of the two passed lists.
26+
def add_arrays(x, y):
27+
"""This function adds together each element of the two passed lists.
2828
2929
Parameters
3030
----------
@@ -42,6 +42,7 @@
4242
--------
4343
>>> add_arrays([1, 4, 5], [4, 3, 5])
4444
[5, 7, 10]
45+
4546
"""
4647
```
4748
Note the underscores and line spacing in the sections; those are part of the `numpy` docstring style!
@@ -57,4 +58,6 @@ My go-to is [`Ruff`](https://docs.astral.sh/ruff/), a fast Python linter (and fo
5758

5859
4. In general, it is a good idea to do a Ruff pass on your code before committing or merging it! Tip: you can also run `ruff check --fix` to automatically fix some of the issues it finds.
5960

60-
5. Finally, you can also use `ruff` as a formatting tool, similar to `black`. You can run `ruff format` on your repository directory to automatically reformat your code to follow PEP 8 guidelines. This is a great way to ensure that your code is consistently formatted and adheres to best practices. This can make it easier to avoid merge conflicts due to formatting/whitespace differences, however **if you are working on a shared codebase, make sure to check the contribution guide before running any autoformatting tools.**
61+
5. You can specify extra rules using `--select`, for example `ruff check --select D` will only check for docstring related issues, while `I` will look at import sorting. You can also ignore specific rules using `--ignore`, for example `ruff check --ignore E501` will ignore line length issues.
62+
63+
6. Finally, you can also use `ruff` as a formatting tool, similar to `black`. You can run `ruff format` on your repository directory to automatically reformat your code to follow PEP 8 guidelines. This is a great way to ensure that your code is consistently formatted and adheres to best practices. This can make it easier to avoid merge conflicts due to formatting/whitespace differences, however **if you are working on a shared codebase, make sure to check the contribution guide before running any autoformatting tools.**

0 commit comments

Comments
 (0)