Skip to content

Commit 8ebfa8b

Browse files
committed
fix bad docstring formatting
1 parent 9c37320 commit 8ebfa8b

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Python/Module5_OddsAndEnds/Writing_Good_Code.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,21 @@ Function and class definitions should be separated by two blank lines:
250250

251251
# Do:
252252
def func_a():
253-
""" I am function a"""
253+
"""I am function a"""
254254
return 1
255255

256256

257257
def func_b(): # separated from func_a by two blank lines
258-
""" I am function b"""
258+
"""I am function b"""
259259
return 2
260260

261261
# Don't:
262262
def func_c():
263-
""" I am function c"""
263+
"""I am function c"""
264264
return 1
265265

266266
def func_d(): # separated from func_c by one blank line
267-
""" I am function d"""
267+
"""I am function d"""
268268
return 2
269269
```
270270

@@ -363,7 +363,7 @@ Type hinting is a syntax that was introduced in Python 3.5 (via [PEP 484](https:
363363
# A function signature that has been annotated with type-hints
364364

365365
def count_vowels(x: str) -> int:
366-
""" Returns the number of vowels contained in `in_string`"""
366+
"""Returns the number of vowels contained in `in_string`"""
367367
vowels = set("aeiouAEIOU")
368368
return sum(1 for char in x if char in vowels)
369369
```
@@ -382,7 +382,7 @@ Let's modify `count_vowels` and add a default-valued argument that permits users
382382
# Type-hinting a default-valued argument
383383

384384
def count_vowels(x: str, include_y: bool = False) -> int:
385-
""" Returns the number of vowels contained in `in_string`"""
385+
"""Returns the number of vowels contained in `in_string`"""
386386
vowels = set("aeiouAEIOU")
387387
if include_y:
388388
vowels.update("yY")
@@ -536,7 +536,7 @@ from typing import Dict, Callable, Optional, List, Tuple, Any
536536
def compute_student_stats(grade_book: Dict[str, List[float]],
537537
stat_function: Callable[[List[float]], Any],
538538
student_list: Optional[List[str]] = None) -> List[Tuple[str, Any]]:
539-
""" Computes custom statistics over student's grades.
539+
"""Computes custom statistics over student's grades.
540540
541541
Parameters
542542
----------
@@ -627,7 +627,7 @@ To be more concrete, let's revisit our `count_vowels` function:
627627

628628
```python
629629
def count_vowels(x: str, include_y: bool = False) -> int:
630-
""" Returns the number of vowels contained in `in_string`"""
630+
"""Returns the number of vowels contained in `in_string`"""
631631
vowels = set("aeiouAEIOU")
632632
if include_y:
633633
vowels.update("yY")
@@ -663,7 +663,7 @@ The `typing` module provides a so-called [abstract base class](https://docs.pyth
663663
from typing import Iterable
664664

665665
def count_vowels(x: Iterable[str], include_y: bool = False) -> int:
666-
""" Returns the number of vowels contained in `in_string`"""
666+
"""Returns the number of vowels contained in `in_string`"""
667667
vowels = set("aeiouAEIOU")
668668
if include_y:
669669
vowels.update("yY")
@@ -684,7 +684,7 @@ Read through the following function and annotate its signature with type-hints.
684684

685685
```python
686686
def get_first_and_last(x):
687-
""" Returns the first and last elements of `x`. `x` is
687+
"""Returns the first and last elements of `x`. `x` is
688688
assumed to be non-empty
689689
"""
690690
return (x[0], x[-1])
@@ -758,7 +758,7 @@ The following function has a docstring that exemplifies all of these sections.
758758

759759
```python
760760
def pairwise_dists(x: np.ndarray, y: np.ndarray) -> np.ndarray:
761-
""" Computes pairwise distances between the rows of ``x`` and ``y``.
761+
"""Computes pairwise distances between the rows of ``x`` and ``y``.
762762
763763
Returns the shape-(M, N) array of Euclidean distances between
764764
the M rows of ``x`` and the N rows of ``y``.
@@ -814,7 +814,7 @@ Here is another example docstring that adheres to the NumPy-style, one without a
814814
def compute_student_stats(grade_book: Dict[str, Iterable[float]],
815815
stat_function: Callable[[Iterable[float]], Any],
816816
student_list: Optional[List[str]] = None) -> List[Tuple[str, Any]]:
817-
""" Computes custom statistics over students' grades.
817+
"""Computes custom statistics over students' grades.
818818
819819
Applies ``stat_func`` over a list of each student's grades,
820820
and accumulates name-stat tuple pairs in a list.
@@ -866,7 +866,7 @@ Let's reproduce the docstrings for `pairwise_dists` and `compute_student_stats`
866866

867867
```python
868868
def pairwise_dists(x: np.ndarray, y: np.ndarray) -> np.ndarray:
869-
""" Computes pairwise distances between the rows of ``x`` and ``y``.
869+
"""Computes pairwise distances between the rows of ``x`` and ``y``.
870870
871871
Returns the shape-(M, N) array of Euclidean distances between
872872
the M rows of ``x`` and the N rows of ``y``.
@@ -885,7 +885,7 @@ def pairwise_dists(x: np.ndarray, y: np.ndarray) -> np.ndarray:
885885
def compute_student_stats(grade_book: Dict[str, Iterable[float]],
886886
stat_function: Callable[[Iterable[float]], Any],
887887
student_list: Optional[List[str]] = None) -> List[Tuple[str, Any]]:
888-
""" Computes custom statistics over students' grades.
888+
"""Computes custom statistics over students' grades.
889889
890890
Applies ``stat_func`` over a list of each student's grades,
891891
and accumulates name-stat tuple pairs in a list.
@@ -960,7 +960,7 @@ The following is a well-annotated version of `get_first_and_last`:
960960
from typing import Sequence, Tuple, Any
961961

962962
def get_first_and_last(x: Sequence[Any]) -> Tuple[Any, Any]:
963-
""" Returns the first and last elements of `x`. `x` is
963+
"""Returns the first and last elements of `x`. `x` is
964964
assumed to be non-empty
965965
"""
966966
return (x[0], x[-1])

0 commit comments

Comments
 (0)