| 1 |
# -*- coding: utf-8 -*- |
| 2 |
"""Test Module for sphinx_rtd_theme.""" |
| 3 |
|
| 4 |
|
| 5 |
class Foo: |
| 6 |
|
| 7 |
"""Docstring for class Foo. |
| 8 |
|
| 9 |
This text tests for the formatting of docstrings generated from output |
| 10 |
``sphinx.ext.autodoc``. Which contain reST, but sphinx nests it in the |
| 11 |
``<dl>``, and ``<dt>`` tags. Also, ``<tt>`` is used for class, method names |
| 12 |
and etc, but those will *always* have the ``.descname`` or |
| 13 |
``.descclassname`` class. |
| 14 |
|
| 15 |
Term |
| 16 |
It is also possible to include definitions inside docstrings. |
| 17 |
They should be styled as a normal definition list. |
| 18 |
|
| 19 |
:Field List: |
| 20 |
It is also possible to include definitions inside docstrings. |
| 21 |
They should be styled as a normal definition list. |
| 22 |
|
| 23 |
.. [1] A footnote contains body elements, consistently indented by at |
| 24 |
least 3 spaces. |
| 25 |
|
| 26 |
.. [Citation] A citation contains body elements, consistently indented by at |
| 27 |
least 3 spaces. |
| 28 |
|
| 29 |
Normal ``<tt>`` (like the <tt> I just wrote here) needs to be shown with |
| 30 |
the same style as anything else with ````this type of markup````. |
| 31 |
|
| 32 |
It's common for programmers to give a code example inside of their |
| 33 |
docstring:: |
| 34 |
|
| 35 |
from test_py_module import Foo |
| 36 |
|
| 37 |
myclass = Foo() |
| 38 |
myclass.dothismethod('with this argument') |
| 39 |
myclass.flush() |
| 40 |
|
| 41 |
print(myclass) |
| 42 |
|
| 43 |
|
| 44 |
Here is a link to :py:meth:`capitalize`. |
| 45 |
Here is a link to :py:meth:`__init__`. |
| 46 |
|
| 47 |
""" |
| 48 |
|
| 49 |
#: Doc comment for class attribute Foo.bar. |
| 50 |
#: It can have multiple lines. |
| 51 |
bar = 1 |
| 52 |
|
| 53 |
flox = 1.5 #: Doc comment for Foo.flox. One line only. |
| 54 |
|
| 55 |
baz = 2 |
| 56 |
"""Docstring for class attribute Foo.baz.""" |
| 57 |
|
| 58 |
def __init__(self, qux, spam=False): |
| 59 |
"""Start the Foo. |
| 60 |
|
| 61 |
:param qux: The first argument to initialize class. |
| 62 |
:type qux: string |
| 63 |
:param spam: Spam me yes or no... |
| 64 |
:type spam: bool |
| 65 |
|
| 66 |
""" |
| 67 |
#: Doc comment for instance attribute qux. |
| 68 |
self.qux = 3 |
| 69 |
|
| 70 |
self.spam = 4 |
| 71 |
"""Docstring for instance attribute spam.""" |
| 72 |
|
| 73 |
def add(self, val1, val2): |
| 74 |
"""Return the added values. |
| 75 |
|
| 76 |
:param val1: First number to add. |
| 77 |
:type val1: int |
| 78 |
:param val2: Second number to add. |
| 79 |
:type val2: int |
| 80 |
:rtype: int |
| 81 |
|
| 82 |
The parameters of this method are described in the parameter list. |
| 83 |
""" |
| 84 |
|
| 85 |
return val1 + val2 |
| 86 |
|
| 87 |
def capitalize(self, myvalue): |
| 88 |
"""Return a string as uppercase. |
| 89 |
|
| 90 |
:param myvalue: String to change |
| 91 |
:type myvalue: string |
| 92 |
:rtype: string |
| 93 |
|
| 94 |
""" |
| 95 |
|
| 96 |
return myvalue.upper() |
| 97 |
|
| 98 |
def another_function(self, a, b, **kwargs): |
| 99 |
""" |
| 100 |
Here is another function. |
| 101 |
|
| 102 |
:param a: The number of green hats you own. |
| 103 |
:type a: int |
| 104 |
|
| 105 |
:param b: The number of non-green hats you own. |
| 106 |
:type b: int |
| 107 |
|
| 108 |
:param kwargs: Additional keyword arguments. Each keyword parameter |
| 109 |
should specify the name of your favorite cuisine. |
| 110 |
The values should be floats, specifying the mean price |
| 111 |
of your favorite dish in that cooking style. |
| 112 |
:type kwargs: float |
| 113 |
|
| 114 |
:returns: A 2-tuple. The first element is the mean price of all dishes |
| 115 |
across cuisines. The second element is the total number of |
| 116 |
hats you own: :math:`a + b`. |
| 117 |
:rtype: tuple |
| 118 |
|
| 119 |
:raises ValueError: When ``a`` is not an integer. |
| 120 |
|
| 121 |
.. versionadded:: 1.0 |
| 122 |
This was added in 1.0 |
| 123 |
.. versionchanged:: 2.0 |
| 124 |
This was changed in 2.0 |
| 125 |
.. deprecated:: 3.0 |
| 126 |
This is deprecated since 3.0 |
| 127 |
""" |
| 128 |
return sum(kwargs.values()) / len(kwargs), a + b |
| 129 |
|
| 130 |
|
| 131 |
def add_numbers(a: int, b: int = 0) -> int: |
| 132 |
"""Add two numbers together |
| 133 |
|
| 134 |
:param a: The first number |
| 135 |
:param b: The second number |
| 136 |
|
| 137 |
Here is some more text. |
| 138 |
""" |
| 139 |
return a + b |
| 140 |
|
| 141 |
|
| 142 |
def subtract_numbers(a: int, b: int = 0) -> int: |
| 143 |
"""Subtract two numbers |
| 144 |
|
| 145 |
:param a: The first number |
| 146 |
:param b: The second number |
| 147 |
""" |
| 148 |
return a - b |