Added a bit so the transition from short to long docstrings flows better

This commit is contained in:
Michael Bryan
2016-06-13 10:07:29 +08:00
parent 3c0b0270ba
commit 10defd73a2
+11 -5
View File
@@ -194,14 +194,20 @@ really obvious cases, such as::
return a + b return a + b
The docstring should describe the function in a way that is easy to understand. The docstring should describe the function in a way that is easy to understand.
Embedding the function's signature in the docstring is unnecessary because it For simple cases like trivial functions and classes, simply embedding the
can easily be obtained using the `inspect` module, and doesn't provide much function's signature (i.e. `add(a, b) -> result`) in the docstring is
additional information. unnecessary. This is because with Python's `inspect` module, it is already
quite easy to find this information if needed, and it is also readily available
by reading the source code.
In larger or more complex projects however, it is often a good idea to give
more information about a function, what it does, any exceptions it may raise,
what it returns, or relevant details about the parameters.
For more detailed documentation of code a popular style is the one used for the For more detailed documentation of code a popular style is the one used for the
Numpy project, often called `Numpy style`_ docstrings. While it can take up a Numpy project, often called `Numpy style`_ docstrings. While it can take up a
few more lines than usual, it allows the developer to include a lot more few more lines the previous example, it allows the developer to include a lot
information about a method, function, or class. :: more information about a method, function, or class. ::
def random_number_generator(arg1, arg2): def random_number_generator(arg1, arg2):
""" """