|
| 1 | +"""This is the docstring for the example.py module. Modules names should |
| 2 | +have short, all-lowercase names. The module name may have underscores if |
| 3 | +this improves readability. |
| 4 | +
|
| 5 | +Every module should have a docstring at the very top of the file. The |
| 6 | +module's docstring may extend over multiple lines. If your docstring does |
| 7 | +extend over multiple lines, the closing three quotation marks must be on |
| 8 | +a line by itself, preferably preceded by a blank line. |
| 9 | +
|
| 10 | +""" |
| 11 | + |
| 12 | +# Example source file from the official "numpydoc docstring guide" |
| 13 | +# documentation (with the modification of commenting out all the original |
| 14 | +# ``import`` lines, plus adding this note and ``Expectation`` code): |
| 15 | +# * As HTML: https://numpydoc.readthedocs.io/en/latest/example.html |
| 16 | +# * Source Python: |
| 17 | +# https://github.com/numpy/numpydoc/blob/master/doc/example.py |
| 18 | + |
| 19 | +# from __future__ import division, absolute_import, print_function |
| 20 | +# |
| 21 | +# import os # standard library imports first |
| 22 | +# |
| 23 | +# Do NOT import using *, e.g. from numpy import * |
| 24 | +# |
| 25 | +# Import the module using |
| 26 | +# |
| 27 | +# import numpy |
| 28 | +# |
| 29 | +# instead or import individual functions as needed, e.g |
| 30 | +# |
| 31 | +# from numpy import array, zeros |
| 32 | +# |
| 33 | +# If you prefer the use of abbreviated module names, we suggest the |
| 34 | +# convention used by NumPy itself:: |
| 35 | +# |
| 36 | +# import numpy as np |
| 37 | +# import matplotlib as mpl |
| 38 | +# import matplotlib.pyplot as plt |
| 39 | +# |
| 40 | +# These abbreviated names are not to be used in docstrings; users must |
| 41 | +# be able to paste and execute docstrings after importing only the |
| 42 | +# numpy module itself, unabbreviated. |
| 43 | + |
| 44 | +import os |
| 45 | +from .expected import Expectation |
| 46 | + |
| 47 | +expectation = Expectation() |
| 48 | +expect = expectation.expect |
| 49 | + |
| 50 | +# module docstring expected violations: |
| 51 | +expectation.expected.add(( |
| 52 | + os.path.normcase(__file__), |
| 53 | + "D205: 1 blank line required between summary line and description " |
| 54 | + "(found 0)")) |
| 55 | +expectation.expected.add(( |
| 56 | + os.path.normcase(__file__), |
| 57 | + "D213: Multi-line docstring summary should start at the second line")) |
| 58 | +expectation.expected.add(( |
| 59 | + os.path.normcase(__file__), |
| 60 | + "D400: First line should end with a period (not 'd')")) |
| 61 | +expectation.expected.add(( |
| 62 | + os.path.normcase(__file__), |
| 63 | + "D404: First word of the docstring should not be `This`")) |
| 64 | +expectation.expected.add(( |
| 65 | + os.path.normcase(__file__), |
| 66 | + "D415: First line should end with a period, question mark, or exclamation " |
| 67 | + "point (not 'd')")) |
| 68 | + |
| 69 | + |
| 70 | +@expect("D213: Multi-line docstring summary should start at the second line", |
| 71 | + arg_count=3) |
| 72 | +@expect("D401: First line should be in imperative mood; try rephrasing " |
| 73 | + "(found 'A')", arg_count=3) |
| 74 | +@expect("D413: Missing blank line after last section ('Examples')", |
| 75 | + arg_count=3) |
| 76 | +def foo(var1, var2, long_var_name='hi'): |
| 77 | + r"""A one-line summary that does not use variable names. |
| 78 | +
|
| 79 | + Several sentences providing an extended description. Refer to |
| 80 | + variables using back-ticks, e.g. `var`. |
| 81 | +
|
| 82 | + Parameters |
| 83 | + ---------- |
| 84 | + var1 : array_like |
| 85 | + Array_like means all those objects -- lists, nested lists, etc. -- |
| 86 | + that can be converted to an array. We can also refer to |
| 87 | + variables like `var1`. |
| 88 | + var2 : int |
| 89 | + The type above can either refer to an actual Python type |
| 90 | + (e.g. ``int``), or describe the type of the variable in more |
| 91 | + detail, e.g. ``(N,) ndarray`` or ``array_like``. |
| 92 | + long_var_name : {'hi', 'ho'}, optional |
| 93 | + Choices in brackets, default first when optional. |
| 94 | +
|
| 95 | + Returns |
| 96 | + ------- |
| 97 | + type |
| 98 | + Explanation of anonymous return value of type ``type``. |
| 99 | + describe : type |
| 100 | + Explanation of return value named `describe`. |
| 101 | + out : type |
| 102 | + Explanation of `out`. |
| 103 | + type_without_description |
| 104 | +
|
| 105 | + Other Parameters |
| 106 | + ---------------- |
| 107 | + only_seldom_used_keywords : type |
| 108 | + Explanation |
| 109 | + common_parameters_listed_above : type |
| 110 | + Explanation |
| 111 | +
|
| 112 | + Raises |
| 113 | + ------ |
| 114 | + BadException |
| 115 | + Because you shouldn't have done that. |
| 116 | +
|
| 117 | + See Also |
| 118 | + -------- |
| 119 | + numpy.array : Relationship (optional). |
| 120 | + numpy.ndarray : Relationship (optional), which could be fairly long, in |
| 121 | + which case the line wraps here. |
| 122 | + numpy.dot, numpy.linalg.norm, numpy.eye |
| 123 | +
|
| 124 | + Notes |
| 125 | + ----- |
| 126 | + Notes about the implementation algorithm (if needed). |
| 127 | +
|
| 128 | + This can have multiple paragraphs. |
| 129 | +
|
| 130 | + You may include some math: |
| 131 | +
|
| 132 | + .. math:: X(e^{j\omega } ) = x(n)e^{ - j\omega n} |
| 133 | +
|
| 134 | + And even use a Greek symbol like :math:`\omega` inline. |
| 135 | +
|
| 136 | + References |
| 137 | + ---------- |
| 138 | + Cite the relevant literature, e.g. [1]_. You may also cite these |
| 139 | + references in the notes section above. |
| 140 | +
|
| 141 | + .. [1] O. McNoleg, "The integration of GIS, remote sensing, |
| 142 | + expert systems and adaptive co-kriging for environmental habitat |
| 143 | + modelling of the Highland Haggis using object-oriented, fuzzy-logic |
| 144 | + and neural-network techniques," Computers & Geosciences, vol. 22, |
| 145 | + pp. 585-588, 1996. |
| 146 | +
|
| 147 | + Examples |
| 148 | + -------- |
| 149 | + These are written in doctest format, and should illustrate how to |
| 150 | + use the function. |
| 151 | +
|
| 152 | + >>> a = [1, 2, 3] |
| 153 | + >>> print([x + 3 for x in a]) |
| 154 | + [4, 5, 6] |
| 155 | + >>> print("a\nb") |
| 156 | + a |
| 157 | + b |
| 158 | + """ |
| 159 | + # After closing class docstring, there should be one blank line to |
| 160 | + # separate following codes (according to PEP257). |
| 161 | + # But for function, method and module, there should be no blank lines |
| 162 | + # after closing the docstring. |
| 163 | + pass |
0 commit comments