1
1
---
2
- title : 🚧 Examples
2
+ title : Common issues and examples
3
3
jupyter :
4
4
kernelspec :
5
5
display_name : Python 3 (ipykernel)
6
6
language : python
7
7
name : python3
8
8
---
9
9
10
- ``` {python}
11
- from quartodoc import MdRenderer, preview
10
+ This page provides examples for commonly encountered situations (and some funky ones).
11
+
12
+ See the [ numpydoc sections guide] [ numpydoc ] for more information and examples.
13
+
14
+ [ numpydoc ] : https://numpydoc.readthedocs.io/en/latest/format.html#sections
15
+
16
+ ## Examples: using code blocks
17
+
18
+ Often, the Examples section of docstrings contain code examples.
19
+
20
+ The Examples section supports two formats for code examples:
21
+
22
+ * ** doctest syntax** - code starts with ` >>> ` .
23
+ * ** markdown syntax** - surrounding code with three backticks (```` ``` ```` )
24
+ * ** quarto syntax** - similar to markdown syntax (e.g. ```` ```{python} ```` ), but will execute code in the docs.
25
+
26
+ Below is an example including each.
27
+
12
28
13
- renderer = MdRenderer()
14
29
```
30
+ Examples
31
+ --------
32
+
33
+ doctest syntax:
34
+
35
+ >>> 1 + 1
36
+ 2
37
+
38
+ markdown syntax:
39
+
40
+ ```python
41
+ 1 + 1
42
+ ```
43
+
44
+ quarto syntax:
45
+ note that the "\" should be removed.
46
+
47
+ ```\{python}
48
+ 1 + 1
49
+ ```
50
+ ```
51
+
52
+
53
+ ## Examples, etc..: the "s" matters
54
+
55
+ The numpydoc spec pluralizes section most names.
56
+ If you leave off the "s", then they may be misparsed.
57
+
58
+ For example, the docstring below erroneously has a "Return" section:
59
+
60
+ ```
61
+ Return
62
+ ------
63
+
64
+ some_name: int
65
+ a description of the return result
66
+ ```
67
+
68
+ In this case, the section won't be parsed, but written directly into the doc page.
69
+ This means that "Return" would show up as a level 2 header.
70
+
71
+ Here is a list of pluralized section names:
72
+
73
+ * Parameters
74
+ * Returns
75
+ * Yields
76
+ * Receives
77
+ * Other Parameters
78
+ * Raises
79
+ * Warns
80
+ * Warnings
81
+ * Notes
82
+ * References
83
+ * Examples
15
84
16
85
## Returns: using type annotation
17
86
@@ -36,6 +105,4 @@ def f() -> int:
36
105
A number
37
106
"""
38
107
39
- ```
40
-
41
- TODO: need to load as a griffe object somehow.
108
+ ```
0 commit comments