Skip to content

Commit 7256033

Browse files
authored
Merge pull request #132 from machow/doc-class-docstring
docs: how to document classes
2 parents 417e479 + 59e7aec commit 7256033

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/get-started/docstring-examples.qmd

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,39 @@ def f():
132132
:::{.callout-note}
133133
Linking to functions documented outside your package must be configured in the [interlinks filter](./interlinks.qmd).
134134
:::
135+
136+
137+
## How do I document a class?
138+
139+
See [this numpydoc page on documenting classes](https://numpydoc.readthedocs.io/en/latest/format.html#documenting-classes).
140+
141+
Below is a simple example of a class docstring.
142+
143+
```python
144+
class MyClass:
145+
"""A great class.
146+
147+
Parameters
148+
----------
149+
a:
150+
Some parameter.
151+
152+
Attributes
153+
----------
154+
x:
155+
An integer
156+
"""
157+
158+
159+
x: int = 1
160+
161+
162+
def __init__(self, a: str):
163+
self.a = a
164+
```
165+
166+
Note these two important pieces:
167+
168+
* Document your `__init__` method parameters on the class docstring.
169+
* You can use an `Attributes` section in your docstring.
170+

0 commit comments

Comments
 (0)