Debian Codegraph @

docs/usage/configuration/docstrings.md

raw
1 # Docstrings options
2
3 [](){#option-docstring_style}
4 ## `docstring_style`
5
6 - **:octicons-package-24: Type [`str`][] :material-equal: `"google"`{ title="default value" }**
7 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
8
9 The docstring style to expect when parsing docstrings.
10
11 Possible values:
12
13 - `"google"`: see [Google style](../docstrings/google.md).
14 - `"numpy"`: see [Numpy style](../docstrings/numpy.md).
15 - `"sphinx"`: see [Sphinx style](../docstrings/sphinx.md).
16 - `None` (`null` or `~` in YAML): no style at all, parse as regular text.
17
18 ```yaml title="in mkdocs.yml (global configuration)"
19 plugins:
20 - mkdocstrings:
21 handlers:
22 python:
23 options:
24 docstring_style: google
25 ```
26
27 ```md title="or in docs/some_page.md (local configuration)"
28 ::: path.to.module
29 options:
30 docstring_style: numpy
31 ```
32
33 WARNING: **The style is applied to the specified object only, not its members.** Local `docstring_style` options (in `:::` instructions) will only be applied to the specified object, and not its members. Instead of changing the style when rendering, we strongly recommend to *set the right style as early as possible*, for example by using the [auto-style](https://mkdocstrings.github.io/griffe/reference/docstrings/#auto-style) (sponsors only), or with a custom Griffe extension
34
35
36 /// admonition | Preview
37 type: preview
38
39 Every style gets rendered the same way.
40 Here are some docstring examples.
41
42 //// tab | Google
43 ```python
44 def greet(name: str) -> str:
45 """Greet someone.
46
47 Parameters:
48 name: The name of the person to greet.
49
50 Returns:
51 A greeting message.
52 """
53 return f"Hello {name}!"
54 ```
55 ////
56
57 //// tab | Numpy
58 ```python
59 def greet(name: str) -> str:
60 """Greet someone.
61
62 Parameters
63 ----------
64 name
65 The name of the person to greet.
66
67 Returns
68 -------
69 A greeting message.
70 """
71 return f"Hello {name}!"
72 ```
73 ////
74
75 //// tab | Sphinx
76 ```python
77 def greet(name: str) -> str:
78 """Greet someone.
79
80 :param name: The name of the person to greet.
81 :return: A greeting message.
82 """
83 return f"Hello {name}!"
84 ```
85 ////
86 ///
87
88 [](){#option-docstring_options}
89 ## `docstring_options`
90
91 - **:octicons-package-24: Type [`dict`][] :material-equal: `{}`{ title="default value" }**
92 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
93
94 The options for the docstring parser.
95
96 - [Google-style options](https://mkdocstrings.github.io/griffe/docstrings/#parser-options){ .external }
97 - [Numpydoc-style options](https://mkdocstrings.github.io/griffe/docstrings/#parser-options_1){ .external }
98
99 The Sphinx style does not offer any option.
100
101 ```yaml title="in mkdocs.yml (global configuration)"
102 plugins:
103 - mkdocstrings:
104 handlers:
105 python:
106 options:
107 docstring_options:
108 ignore_init_summary: false
109 trim_doctest_flags: true
110 ```
111
112 ```md title="or in docs/some_page.md (local configuration)"
113 ::: path.to.module
114 options:
115 docstring_options:
116 ignore_init_summary: true
117 trim_doctest_flags: false
118 ```
119
120 ```python
121 class PrintOK:
122 """Class docstring."""
123
124 def __init__(self):
125 """Initialize the instance.
126
127 Examples:
128 >>> PrintOK() # doctest: +NORMALIZE_WHITESPACE
129 ok
130 """
131 print("ok")
132 ```
133
134 /// admonition | Preview
135 type: preview
136
137 //// tab | Ignore init summary, trim doctest flags
138 <h2><code>PrintOK</code></h2>
139 <p>Class docstring.</p>
140 <h3><code>__init__</code></h3>
141 <p>Examples:</p>
142
143 ```pycon
144 >>> PrintOK()
145 ok
146 ```
147 ////
148
149 //// tab | Keep init summary and doctest flags
150 <h2><code>PrintOK</code></h2>
151 <p>Class docstring.</p>
152 <h3><code>__init__</code></h3>
153 <p>Initialize the instance.</p>
154 <p>Examples:</p>
155
156 ```pycon
157 >>> PrintOK() # doctest: +NORMALIZE_WHITESPACE
158 ok
159 ```
160 ////
161 ///
162
163 [](){#option-docstring_section_style}
164 ## `docstring_section_style`
165
166 - **:octicons-package-24: Type [`str`][] :material-equal: `"table"`{ title="default value" }**
167 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
168
169 The style used to render docstring sections.
170
171 A section is a block of text that has a special meaning in a docstring.
172 There are sections for documenting attributes of an object,
173 parameters of a function, exceptions raised by a function,
174 the return value of a function, etc.
175
176 Sections are parsed as structured data and can therefore be rendered
177 in different ways. Possible values:
178
179 - `"table"`: a simple table, usually with type, name and description columns
180 - `"list"`: a simple list, akin to what you get with the [ReadTheDocs Sphinx theme]{ .external }
181 - `"spacy"`: a poor implementation of the amazing tables in [Spacy's documentation]{ .external }
182
183 ```yaml title="in mkdocs.yml (global configuration)"
184 plugins:
185 - mkdocstrings:
186 handlers:
187 python:
188 options:
189 docstring_section_style: table
190 ```
191
192 ```md title="or in docs/some_page.md (local configuration)"
193 ::: path.to.module
194 options:
195 docstring_section_style: list
196 ```
197
198 /// admonition | Preview
199 type: preview
200
201 //// tab | Table
202 Tables work well when you have lots of items with short names, type annotations, descriptions, etc..
203 With longer strings, the columns risk getting squished horizontally.
204 In that case, the Spacy tables can help.
205
206 **Parameters:**
207
208 **Type** | **Name** | **Description** | **Default**
209 ---------- | ----------- | ------------------------ | -----------
210 [`int`][] | `threshold` | Threshold for something. | *required*
211 [`bool`][] | `flag` | Enable something. | `False`
212
213 **Other Parameters:**
214
215 **Type** | **Name** | **Description** | **Default**
216 ---------- | ----------- | ------------------------ | -----------
217 <code><autoref identifier="list" optional>list</autoref>\[<autoref identifier="int" optional>int</autoref> \| <autoref identifier="float" optional>float</autoref>\]</code> | `gravity_forces` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | *required*
218 <code><autoref identifier="VacuumType" optional>VacuumType</autoref> \| <autoref identifier="typing.Literal" optional>Literal</autoref>\["regular"\]</code> | `vacuum_type` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | `VacuumType.PLASMA`
219 ////
220
221 //// tab | List
222 Lists work well whatever the length of names, type annotations, descriptions, etc.
223
224 **Parameters:**
225
226 - `threshold` ([`int`][]) &mdash; Threshold for something.
227 - `flag` ([`bool`][]) &mdash; Enable something.
228
229 **Other Parameters:**
230
231 - `gravity_forces` (<code><autoref identifier="list" optional>list</autoref>\[<autoref identifier="int" optional>int</autoref> \| <autoref identifier="float" optional>float</autoref>\]</code>) &mdash; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
232 - `vacuum_type` (<code><autoref identifier="VacuumType" optional>VacuumType</autoref> \| <autoref identifier="typing.Literal" optional>Literal</autoref>\["regular"\]</code>) &mdash; Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
233 ////
234
235 //// tab | Spacy
236 Spacy tables work better than regular tables with longer names, type annotations, descriptions, etc.,
237 by reserving more horizontal space on the second column.
238
239 **Parameters:**
240
241 **Name** | **Description**
242 ----------- | ---------------
243 `threshold` | <span style="display: inline-block; min-width: 400px;">Threshold for something.</span><br>**TYPE:** [`int`][] <span style="float: right;"><b>DEFAULT:</b> <i>required</i></span>
244 `flag` | <span style="display: inline-block; min-width: 400px;">Enable something.</span><br>**TYPE:** [`bool`][] <span style="float: right;"><b>DEFAULT:</b> <code>False</code></span>
245
246 **Other Parameters:**
247
248 **Name** | **Description**
249 ----------- | ---------------
250 `gravity_forces` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>**TYPE:** <code><autoref identifier="list" optional>list</autoref>\[<autoref identifier="int" optional>int</autoref> \| <autoref identifier="float" optional>float</autoref>\]</code> <span style="float: right;"><b>DEFAULT:</b> <i>required</i></span>
251 `vacuum_type` | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br>**TYPE:**<code><autoref identifier="VacuumType" optional>VacuumType</autoref> \| <autoref identifier="typing.Literal" optional>Literal</autoref>\["regular"\]</code> <span style="float: right;"><b>DEFAULT:</b> <code>VacuumType.PLASMA</code></span>
252 ////
253 ///
254
255 [](){#option-merge_init_into_class}
256 ## `merge_init_into_class`
257
258 - **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }**
259 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
260
261 Whether to merge the `__init__` method into the class' signature and docstring.
262
263 By default, only the class name is rendered in headings.
264 When merging, the `__init__` method parameters are added after the class name,
265 like a signature, and the `__init__` method docstring is appended to the class' docstring.
266 This option is well used in combination with the `ignore_init_summary` [docstring option][docstring_options],
267 to discard the first line of the `__init__` docstring which is not often useful.
268
269 ```yaml title="in mkdocs.yml (global configuration)"
270 plugins:
271 - mkdocstrings:
272 handlers:
273 python:
274 options:
275 docstring_options:
276 ignore_init_summary: false
277 merge_init_into_class: false
278 ```
279
280 ```md title="or in docs/some_page.md (local configuration)"
281 ::: path.to.module
282 options:
283 docstring_options:
284 ignore_init_summary: true
285 merge_init_into_class: true
286 ```
287
288 ```python
289 class Thing:
290 """A class for things."""
291
292 def __init__(self, value: int = 0):
293 """Initialize a thing.
294
295 Parameters:
296 value: The thing's value.
297 """
298 self.value = value
299 ```
300
301 /// admonition | Preview
302 type: preview
303
304 //// tab | Merged, summary discarded
305 <h2><code>Thing(value=0)</code></h2>
306 <p>Class docstring.</p>
307 <p><b>Parameters:</b></p>
308
309 **Type** | **Name** | **Description** | **Default**
310 --------- | -------- | ------------------ | -----------
311 [`int`][] | `value` | The thing's value. | `0`
312 ////
313
314 //// tab | Unmerged, summary kept
315 <h2><code>Thing</code></h2>
316 <p>Class docstring.</p>
317 <h3><code>__init__(value=0)</code></h3>
318 <p>Initialize a thing.</p>
319 <p><b>Parameters:</b></p>
320
321 **Type** | **Name** | **Description** | **Default**
322 --------- | -------- | ------------------ | -----------
323 [`int`][] | `value` | The thing's value. | `0`
324 ////
325 ///
326
327 [](){#option-relative_crossrefs}
328 ## `relative_crossrefs`
329
330 - **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }**
331 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
332
333 Whether to enable the relative-crossref syntax.
334
335 The relative-crossref syntax lets you reference the current object or its parent by prefixing a crossref identifier with dots. For example, to cross-reference the current object's `name` member, you can write `[link to name attribute][.name]`. The "current object" is the object containing the docstring being rendered.
336
337
338 ```yaml title="in mkdocs.yml (global configuration)"
339 plugins:
340 - mkdocstrings:
341 handlers:
342 python:
343 options:
344 relative_crossrefs: false
345 ```
346
347 ```md title="or in docs/some_page.md (local configuration)"
348 ::: path.to.module
349 options:
350 relative_crossrefs: true
351 ```
352
353 /// admonition | Examples
354 type: preview
355
356 ```python title="pkg/module.py"
357 """Summary.
358
359 - Link to [`module`][.].
360 - Link to [`module_attribute`][.module_attribute].
361 - Link to [`Class`][.Class].
362 - Link to [`class_attribute`][.Class.class_attribute].
363 - Link to [`instance_attribute`][.Class.instance_attribute].
364 - Link to [`method`][.Class.method].
365 """
366
367 module_attribute = 0
368 """Summary.
369
370 - Link to [`module`][..].
371 - Link to [`module_attribute`][.].
372 - Link to [`Class`][..Class].
373 - Link to [`class_attribute`][..Class.class_attribute].
374 - Link to [`instance_attribute`][..Class.instance_attribute].
375 - Link to [`method`][..Class.method].
376 """
377
378 class Class:
379 """Summary.
380
381 - Link to [`module`][..].
382 - Link to [`module_attribute`][..module_attribute].
383 - Link to [`Class`][.].
384 - Link to [`class_attribute`][.class_attribute].
385 - Link to [`instance_attribute`][.instance_attribute].
386 - Link to [`method`][.method].
387 """
388
389 class_attribute = 0
390 """Summary.
391
392 - Link to [`module`][...].
393 - Link to [`module_attribute`][...module_attribute].
394 - Link to [`Class`][..].
395 - Link to [`class_attribute`][.].
396 - Link to [`instance_attribute`][..instance_attribute].
397 - Link to [`method`][..method].
398 """
399
400 def __init__(self):
401 """Summary.
402
403 - Link to [`module`][...].
404 - Link to [`module_attribute`][...module_attribute].
405 - Link to [`Class`][..].
406 - Link to [`class_attribute`][..class_attribute].
407 - Link to [`instance_attribute`][..instance_attribute].
408 - Link to [`method`][..method].
409 """
410 self.instance_attribute = 0
411 """Summary.
412
413 - Link to [`module`][...].
414 - Link to [`module_attribute`][...module_attribute].
415 - Link to [`Class`][..].
416 - Link to [`class_attribute`][..class_attribute].
417 - Link to [`instance_attribute`][.].
418 - Link to [`method`][..method].
419 """
420
421 def method(self):
422 """Summary.
423
424 - Link to [`module`][...].
425 - Link to [`module_attribute`][...module_attribute].
426 - Link to [`Class`][..].
427 - Link to [`class_attribute`][..class_attribute].
428 - Link to [`instance_attribute`][..instance_attribute].
429 - Link to [`method`][.].
430 """
431 ```
432
433 ///
434
435 INFO: **There is an alternative, third-party Python handler that handles relative references: [mkdocstrings-python-xref](https://github.com/analog-garage/mkdocstrings-python-xref).**
436
437 [](){#option-scoped_crossrefs}
438 ## `scoped_crossrefs`
439
440 - **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }**
441 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
442
443 Whether to enable scoped cross-references.
444
445 With scoped cross-references, you can write identifiers as if you wanted to access them from the current object's scope. The scoping rules do not exactly match Python's: you can reference members and siblings too, without prefixing with `self.` or `cls.`.
446
447 The following order is applied when resolving a name in a given scope:
448
449 1. member of the current object
450 2. parent class
451 3. repeat 1-2 within parent's scope
452
453 In practice, it means that the name is first looked up in members, then it is compared against the parent name (only if it's a class), then it is looked up in siblings. It continues climbing up the object tree until there's no parent, in which case it raises a name resolution error.
454
455 Cross-referencing an imported object will directly link to this object if the objects inventory of the project it comes from was [loaded][inventories]. You won't be able to cross-reference it within your own documentation with scoped references, if you happen to be rendering this external object too. In that case, you can use an absolute reference or a [relative][relative_crossrefs] one instead.
456
457 Another limitation is that you won't be able to reference an external package if its name can be resolved in the current object's scope.
458
459 ```yaml title="in mkdocs.yml (global configuration)"
460 plugins:
461 - mkdocstrings:
462 handlers:
463 python:
464 options:
465 scoped_crossrefs: false
466 ```
467
468 ```md title="or in docs/some_page.md (local configuration)"
469 ::: path.to.module
470 options:
471 scoped_crossrefs: true
472 ```
473
474 /// admonition | Examples
475 type: preview
476
477 ```python title="pkg/module.py"
478 """Summary.
479
480 - Link to [`module_attribute`][module_attribute].
481 - Link to [`Class`][Class].
482 - Link to [`class_attribute`][Class.class_attribute].
483 - Link to [`instance_attribute`][Class.instance_attribute].
484 - Link to [`method`][Class.method].
485 """
486
487 module_attribute = 0
488 """Summary.
489
490 - Link to [`Class`][Class].
491 - Link to [`class_attribute`][Class.class_attribute].
492 - Link to [`instance_attribute`][Class.instance_attribute].
493 - Link to [`method`][Class.method].
494 """
495
496 class Class:
497 """Summary.
498
499 - Link to [`module_attribute`][module_attribute].
500 - Link to [`class_attribute`][class_attribute].
501 - Link to [`instance_attribute`][instance_attribute].
502 - Link to [`method`][method].
503 """
504
505 class_attribute = 0
506 """Summary.
507
508 - Link to [`module_attribute`][module_attribute].
509 - Link to [`Class`][Class].
510 - Link to [`instance_attribute`][instance_attribute].
511 - Link to [`method`][method].
512 """
513
514 def __init__(self):
515 """Summary.
516
517 - Link to [`module_attribute`][module_attribute].
518 - Link to [`Class`][Class].
519 - Link to [`class_attribute`][class_attribute].
520 - Link to [`instance_attribute`][instance_attribute].
521 - Link to [`method`][method].
522 """
523 self.instance_attribute = 0
524 """Summary.
525
526 - Link to [`module_attribute`][module_attribute].
527 - Link to [`Class`][Class].
528 - Link to [`class_attribute`][class_attribute].
529 - Link to [`method`][method].
530 """
531
532 def method(self):
533 """Summary.
534
535 - Link to [`module_attribute`][module_attribute].
536 - Link to [`Class`][Class].
537 - Link to [`class_attribute`][class_attribute].
538 - Link to [`instance_attribute`][instance_attribute].
539 """
540 ```
541
542 ///
543
544 [](){#option-show_if_no_docstring}
545 ## `show_if_no_docstring`
546
547 - **:octicons-package-24: Type [`bool`][] :material-equal: `False`{ title="default value" }**
548 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
549
550 Show the object heading even if it has no docstring or children with docstrings.
551
552 Without an explicit list of [`members`][], members are selected based on [`filters`][],
553 and then filtered again to keep only those with docstrings. Checking if a member has a docstring
554 is done recursively: if at least one of its direct or indirect members (lower in the tree)
555 has a docstring, the member is rendered. If the member does not have a docstring,
556 and none of its members have a docstring, it is excluded.
557
558 With this option you can tell the Python handler to skip the docstring check.
559
560 ```yaml title="in mkdocs.yml (global configuration)"
561 plugins:
562 - mkdocstrings:
563 handlers:
564 python:
565 options:
566 show_if_no_docstring: false
567 ```
568
569 ```md title="or in docs/some_page.md (local configuration)"
570 ::: path.to.module
571 options:
572 show_if_no_docstring: true
573 ```
574
575 ```python
576 def function_without_docstring():
577 ...
578
579
580 def function_with_docstring():
581 """Hello."""
582
583
584 class ClassWithoutDocstring:
585 def method_without_docstring(self):
586 ...
587
588 def method_with_docstring(self):
589 """Hello."""
590 ```
591
592 /// admonition | Preview
593 type: preview
594
595 //// tab | Show
596 <h2><code>function_without_docstring</code></h2>
597 <h2><code>function_with_docstring</code></h2>
598 <p>Hello.</p>
599 <h2><code>ClassWithoutDocstring</code></h2>
600 <h3><code>method_without_docstring</code></h3>
601 <h3><code>method_with_docstring</code></h3>
602 <p>Hello.</p>
603 ////
604
605 //// tab | Don't show
606 <h2><code>function_with_docstring</code></h2>
607 <p>Hello.</p>
608 <h2><code>ClassWithoutDocstring</code></h2>
609 <h3><code>method_with_docstring</code></h3>
610 <p>Hello.</p>
611 ////
612 ///
613
614 [](){#option-show_docstring_attributes}
615 ## `show_docstring_attributes`
616
617 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
618 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
619
620 Whether to render the "Attributes" section of docstrings.
621
622 ```yaml title="in mkdocs.yml (global configuration)"
623 plugins:
624 - mkdocstrings:
625 handlers:
626 python:
627 options:
628 show_docstring_attributes: true
629 ```
630
631 ```md title="or in docs/some_page.md (local configuration)"
632 ::: path.to.module
633 options:
634 show_docstring_attributes: false
635 ```
636
637 ```python
638 class Class:
639 """Summary.
640
641 Attributes:
642 attr: Some attribute.
643 """
644
645 attr: int = 1
646 ```
647
648 /// admonition | Preview
649 type: preview
650
651 //// tab | With attributes
652 <h2><code>Class</code></h2>
653 <p>Summary.</p>
654 <p><b>Attributes:</b></p>
655
656 **Type** | **Name** | **Description**
657 --------- | -------- | ---------------
658 [`int`][] | `attr` | Some attribute.
659 ////
660
661 //// tab | Without attributes
662 <h2><code>Class</code></h2>
663 <p>Summary.</p>
664 ////
665 ///
666
667 [](){#option-show_docstring_functions}
668 ## `show_docstring_functions`
669
670 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
671 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
672
673 Whether to render the "Functions" or "Methods" section of docstrings.
674
675 ```yaml title="in mkdocs.yml (global configuration)"
676 plugins:
677 - mkdocstrings:
678 handlers:
679 python:
680 options:
681 show_docstring_functions: true
682 ```
683
684 ```md title="or in docs/some_page.md (local configuration)"
685 ::: path.to.module
686 options:
687 show_docstring_functions: false
688 ```
689
690 ```python
691 """Summary.
692
693 Functions:
694 foo: Some function.
695 """
696
697
698 def foo():
699 ...
700
701
702 class Class:
703 """Summary.
704
705 Methods:
706 bar: Some method.
707 """
708
709 def bar(self):
710 ...
711 ```
712
713 /// admonition | Preview
714 type: preview
715
716 //// tab | With functions
717 <h2>module</h2>
718 <p>Summary.</p>
719 <p><b>Functions:</b></p>
720
721 **Name** | **Description**
722 -------- | ---------------
723 `foo` | Some function.
724
725 <h3><code>Class</code></h3>
726 <p>Summary.</p>
727 <p><b>Methods:</b></p>
728
729 **Name** | **Description**
730 -------- | ---------------
731 `bar` | Some method.
732 ////
733
734 //// tab | Without functions
735 <h2>module</h2>
736 <p>Summary.</p>
737 <h3><code>Class</code></h3>
738 <p>Summary.</p>
739 ////
740 ///
741
742 [](){#option-show_docstring_classes}
743 ## `show_docstring_classes`
744
745 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
746 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
747
748 Whether to render the "Classes" section of docstrings.
749
750 ```yaml title="in mkdocs.yml (global configuration)"
751 plugins:
752 - mkdocstrings:
753 handlers:
754 python:
755 options:
756 show_docstring_classes: true
757 ```
758
759 ```md title="or in docs/some_page.md (local configuration)"
760 ::: path.to.module
761 options:
762 show_docstring_classes: false
763 ```
764
765 ```python
766 """Summary.
767
768 Classes:
769 Class: Some class.
770 """
771
772
773 class Class:
774 """Summary."""
775 ```
776
777 /// admonition | Preview
778 type: preview
779
780 //// tab | With classes
781 <h2>module</h2>
782 <p>Summary.</p>
783 <p><b>Classes:</b></p>
784
785 **Name** | **Description**
786 -------- | ---------------
787 `Class` | Some class.
788
789 <h3><code>Class</code></h3>
790 <p>Summary.</p>
791 ////
792
793 //// tab | Without classes
794 <h2>module</h2>
795 <p>Summary.</p>
796 <h3><code>Class</code></h3>
797 <p>Summary.</p>
798 ////
799 ///
800
801 [](){#option-show_docstring_type_aliases}
802 ## `show_docstring_type_aliases`
803
804 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
805
806 Whether to render the "Type Aliases" section of docstrings.
807
808 ```yaml title="in mkdocs.yml (global configuration)"
809 plugins:
810 - mkdocstrings:
811 handlers:
812 python:
813 options:
814 show_docstring_type_aliases: true
815 ```
816
817 ```md title="or in docs/some_page.md (local configuration)"
818 ::: path.to.module
819 options:
820 show_docstring_type_aliases: false
821 ```
822
823 ```python
824 """Summary.
825
826 Type Aliases:
827 TypeAlias: Some type alias.
828 """
829
830
831 type TypeAlias = int
832 """Summary."""
833 ```
834
835 /// admonition | Preview
836 type: preview
837
838 //// tab | With type_aliases
839 <h2>module</h2>
840 <p>Summary.</p>
841 <p><b>Type Aliases:</b></p>
842
843 **Name** | **Description**
844 ------------ | ----------------
845 `TypeAlias` | Some type alias.
846
847 <h3><code>TypeAlias</code></h3>
848 <p>Summary.</p>
849 ////
850
851 //// tab | Without classes
852 <h2>module</h2>
853 <p>Summary.</p>
854 <h3><code>TypeAlias</code></h3>
855 <p>Summary.</p>
856 ////
857 ///
858
859 [](){#option-show_docstring_modules}
860 ## `show_docstring_modules`
861
862 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
863 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
864
865 Whether to render the "Modules" section of docstrings.
866
867 ```yaml title="in mkdocs.yml (global configuration)"
868 plugins:
869 - mkdocstrings:
870 handlers:
871 python:
872 options:
873 show_docstring_modules: true
874 ```
875
876 ```md title="or in docs/some_page.md (local configuration)"
877 ::: path.to.module
878 options:
879 show_docstring_modules: false
880 ```
881
882 ```tree
883 module/
884 __init__.py
885 submodule.py
886 ```
887
888 ```python title="module/__init__.py"
889 """Summary.
890
891 Modules:
892 submodule: Some module.
893 """
894 ```
895
896 /// admonition | Preview
897 type: preview
898
899 //// tab | With modules
900 <h2>module</h2>
901 <p>Summary.</p>
902 <p><b>Modules:</b></p>
903
904 **Name** | **Description**
905 ----------- | ---------------
906 `submodule` | Some module.
907
908 ////
909
910 //// tab | Without modules
911 <h2>module</h2>
912 <p>Summary.</p>
913 ////
914 ///
915
916 [](){#option-show_docstring_description}
917 ## `show_docstring_description`
918
919 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
920 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
921
922 Whether to render the textual blocks (including admonitions) of docstrings.
923
924 ```yaml title="in mkdocs.yml (global configuration)"
925 plugins:
926 - mkdocstrings:
927 handlers:
928 python:
929 options:
930 show_docstring_description: true
931 ```
932
933 ```md title="or in docs/some_page.md (local configuration)"
934 ::: path.to.module
935 options:
936 show_docstring_description: false
937 ```
938
939 ```python
940 class Class:
941 """Summary.
942
943 Long description.
944
945 Warning: Deprecated
946 Stop using this class.
947
948 Attributes:
949 attr: Some attribute.
950 """
951
952 attr: int = 1
953 ```
954
955 /// admonition | Preview
956 type: preview
957
958 //// tab | With description blocks
959 <h2><code>Class</code></h2>
960 <p>Summary.</p>
961 <p>Long description.</p>
962 <details class="warning" open><summary>Deprecated</summary><p>Stop using this class.</p></details>
963 <p><b>Attributes:</b></p>
964
965 **Type** | **Name** | **Description**
966 --------- | -------- | ---------------
967 [`int`][] | `attr` | Some attribute.
968 ////
969
970 //// tab | Without description blocks
971 <h2><code>Class</code></h2>
972 <p><b>Attributes:</b></p>
973
974 **Type** | **Name** | **Description**
975 --------- | -------- | ---------------
976 [`int`][] | `attr` | Some attribute.
977 ////
978 ///
979
980 [](){#option-show_docstring_examples}
981 ## `show_docstring_examples`
982
983 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
984 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
985
986 Whether to render the "Examples" section of docstrings.
987
988 ```yaml title="in mkdocs.yml (global configuration)"
989 plugins:
990 - mkdocstrings:
991 handlers:
992 python:
993 options:
994 show_docstring_examples: true
995 ```
996
997 ```md title="or in docs/some_page.md (local configuration)"
998 ::: path.to.module
999 options:
1000 show_docstring_examples: false
1001 ```
1002
1003 ```python
1004 def print_hello():
1005 """Print hello.
1006
1007 Examples:
1008 >>> print("hello")
1009 hello
1010 """
1011 print("hello")
1012 ```
1013
1014 /// admonition | Preview
1015 type: preview
1016
1017 //// tab | With examples
1018 <h2><code>print_hello</code></h2>
1019 <p>Print hello.</p>
1020 <p><b>Examples:</b></p>
1021
1022 ```pycon
1023 >>> print("hello")
1024 hello
1025 ```
1026 ////
1027
1028 //// tab | Without examples
1029 <h2><code>print_hello</code></h2>
1030 <p>Print hello.</p>
1031 ////
1032 ///
1033
1034 [](){#option-show_docstring_other_parameters}
1035 ## `show_docstring_other_parameters`
1036
1037 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
1038 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
1039
1040 Whether to render the "Other Parameters" section of docstrings.
1041
1042 ```yaml title="in mkdocs.yml (global configuration)"
1043 plugins:
1044 - mkdocstrings:
1045 handlers:
1046 python:
1047 options:
1048 show_docstring_other_parameters: true
1049 ```
1050
1051 ```md title="or in docs/some_page.md (local configuration)"
1052 ::: path.to.module
1053 options:
1054 show_docstring_other_parameters: false
1055 ```
1056
1057 ```python
1058 def do_something(**kwargs):
1059 """Do something.
1060
1061 Other parameters:
1062 whatever (int): Some integer.
1063 """
1064 ```
1065
1066 /// admonition | Preview
1067 type: preview
1068
1069 //// tab | With other parameters
1070 <h2><code>do_something</code></h2>
1071 <p>Do something.</p>
1072 <p><b>Other parameters:</b></p>
1073
1074 **Type** | **Name** | **Description**
1075 --------- | ---------- | ---------------
1076 [`int`][] | `whatever` | Some integer.
1077 ////
1078
1079 //// tab | Without other parameters
1080 <h2><code>do_something</code></h2>
1081 <p>Do something.</p>
1082 ////
1083 ///
1084
1085 [](){#option-show_docstring_parameters}
1086 ## `show_docstring_parameters`
1087
1088 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
1089 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
1090
1091 Whether to render the "Parameters" section of docstrings.
1092
1093 ```yaml title="in mkdocs.yml (global configuration)"
1094 plugins:
1095 - mkdocstrings:
1096 handlers:
1097 python:
1098 options:
1099 show_docstring_parameters: true
1100 ```
1101
1102 ```md title="or in docs/some_page.md (local configuration)"
1103 ::: path.to.module
1104 options:
1105 show_docstring_parameters: false
1106 ```
1107
1108 ```python
1109 def do_something(whatever: int = 0):
1110 """Do something.
1111
1112 Parameters:
1113 whatever: Some integer.
1114 """
1115 ```
1116
1117 /// admonition | Preview
1118 type: preview
1119
1120 //// tab | With parameters
1121 <h2><code>do_something</code></h2>
1122 <p>Do something.</p>
1123 <p><b>Parameters:</b></p>
1124
1125 **Type** | **Name** | **Description** | **Default**
1126 --------- | ---------- | --------------- | -----------
1127 [`int`][] | `whatever` | Some integer. | `0`
1128 ////
1129
1130 //// tab | Without parameters
1131 <h2><code>do_something</code></h2>
1132 <p>Do something.</p>
1133 ////
1134 ///
1135
1136 [](){#option-show_docstring_raises}
1137 ## `show_docstring_raises`
1138
1139 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
1140 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
1141
1142 Whether to render the "Raises" section of docstrings.
1143
1144 ```yaml title="in mkdocs.yml (global configuration)"
1145 plugins:
1146 - mkdocstrings:
1147 handlers:
1148 python:
1149 options:
1150 show_docstring_raises: true
1151 ```
1152
1153 ```md title="or in docs/some_page.md (local configuration)"
1154 ::: path.to.module
1155 options:
1156 show_docstring_raises: false
1157 ```
1158
1159 ```python
1160 def raise_runtime_error():
1161 """Raise a runtime error.
1162
1163 Raises:
1164 RuntimeError: Not good.
1165 """
1166 raise RuntimeError
1167 ```
1168
1169 /// admonition | Preview
1170 type: preview
1171
1172 //// tab | With exceptions
1173 <h2><code>raise_runtime_error</code></h2>
1174 <p>Raise a runtime error.</p>
1175 <p><b>Raises:</b></p>
1176
1177 **Type** | **Description**
1178 ------------------ | ---------------
1179 [`RuntimeError`][] | Not good.
1180 ////
1181
1182 //// tab | Without exceptions
1183 <h2><code>raise_runtime_error</code></h2>
1184 <p>Raise a runtime error.</p>
1185 ////
1186 ///
1187
1188 [](){#option-show_docstring_receives}
1189 ## `show_docstring_receives`
1190
1191 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
1192 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
1193
1194 Whether to render the "Receives" section of docstrings.
1195
1196 ```yaml title="in mkdocs.yml (global configuration)"
1197 plugins:
1198 - mkdocstrings:
1199 handlers:
1200 python:
1201 options:
1202 show_docstring_receives: true
1203 ```
1204
1205 ```md title="or in docs/some_page.md (local configuration)"
1206 ::: path.to.module
1207 options:
1208 show_docstring_receives: false
1209 ```
1210
1211 ```python
1212 def iter_skip(
1213 iterable: Iterable[T],
1214 initial_skip: int = 0,
1215 ) -> Generator[T, int, None]:
1216 """Iterate and skip elements.
1217
1218 Receives:
1219 skip: Number of elements to skip.
1220 """
1221 skip = initial_skip
1222 for element in iterable:
1223 if skip or 0 > 0:
1224 skip -= 1
1225 else:
1226 skip = yield element
1227 ```
1228
1229 /// admonition | Preview
1230 type: preview
1231
1232 //// tab | With received values
1233 <h2><code>iter_skip</code></h2>
1234 <p>Iterate and skip elements.</p>
1235 <p><b>Receives:</b></p>
1236
1237 **Type** | **Description**
1238 --------- | ---------------
1239 [`int`][] | Number of elements to skip.
1240 ////
1241
1242 //// tab | Without received values
1243 <h2><code>iter_skip</code></h2>
1244 <p>Iterate and skip elements.</p>
1245 ////
1246 ///
1247
1248 [](){#option-show_docstring_returns}
1249 ## `show_docstring_returns`
1250
1251 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
1252 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
1253
1254 Whether to render the "Returns" section of docstrings.
1255
1256 ```yaml title="in mkdocs.yml (global configuration)"
1257 plugins:
1258 - mkdocstrings:
1259 handlers:
1260 python:
1261 options:
1262 show_docstring_returns: true
1263 ```
1264
1265 ```md title="or in docs/some_page.md (local configuration)"
1266 ::: path.to.module
1267 options:
1268 show_docstring_returns: false
1269 ```
1270
1271 ```python
1272 def rand() -> int:
1273 """Return a random number.
1274
1275 Returns:
1276 A random number.
1277 """
1278 return random.randint(0, 1000)
1279 ```
1280
1281 /// admonition | Preview
1282 type: preview
1283
1284 //// tab | With return value
1285 <h2><code>rand</code></h2>
1286 <p>Return a random number.</p>
1287 <p><b>Returns:</b></p>
1288
1289 **Type** | **Description**
1290 --------- | ---------------
1291 [`int`][] | A random number.
1292 ////
1293
1294 //// tab | Without return value
1295 <h2><code>rand</code></h2>
1296 <p>Return a random number.</p>
1297 ////
1298 ///
1299
1300 [](){#option-show_docstring_type_parameters}
1301 ## `show_docstring_type_parameters`
1302
1303 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
1304 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
1305
1306 Whether to render the "Type Parameters" section of docstrings.
1307
1308 ```yaml title="in mkdocs.yml (global configuration)"
1309 plugins:
1310 - mkdocstrings:
1311 handlers:
1312 python:
1313 options:
1314 show_docstring_type_parameters: true
1315 ```
1316
1317 ```md title="or in docs/some_page.md (local configuration)"
1318 ::: path.to.module
1319 options:
1320 show_docstring_type_parameters: false
1321 ```
1322
1323 ```python
1324 class AClass[X: (int, str) = str]:
1325 """Represents something.
1326
1327 Type Parameters:
1328 X: Something.
1329 """
1330 ```
1331
1332 /// admonition | Preview
1333 type: preview
1334
1335 //// tab | With parameters
1336 <h2><code>AClass</code></h2>
1337 <p>Represents something.</p>
1338 <p><b>Type Parameters:</b></p>
1339
1340 **Name** | **Bound or Constraints** | **Description** | **Default**
1341 ---------- | ------------------------ | --------------- | -----------
1342 `whatever` | `(int, str)` | Something. | `str`
1343 ////
1344
1345 //// tab | Without parameters
1346 <h2><code>AClass</code></h2>
1347 <p>Represents something.</p>
1348 ////
1349 ///
1350
1351 [](){#option-show_docstring_warns}
1352 ## `show_docstring_warns`
1353
1354 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
1355 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
1356
1357 Whether to render the "Warns" section of docstrings.
1358
1359 ```yaml title="in mkdocs.yml (global configuration)"
1360 plugins:
1361 - mkdocstrings:
1362 handlers:
1363 python:
1364 options:
1365 show_docstring_warns: true
1366 ```
1367
1368 ```md title="or in docs/some_page.md (local configuration)"
1369 ::: path.to.module
1370 options:
1371 show_docstring_warns: false
1372 ```
1373
1374 ```python
1375 def warn():
1376 """Warn user.
1377
1378 Warns:
1379 UserWarning: When this is inappropriate.
1380 """
1381 warnings.warn(UserWarning("This is inappropriate"))
1382 ```
1383
1384 /// admonition | Preview
1385 type: preview
1386
1387 //// tab | With warnings
1388 <h2><code>warn</code></h2>
1389 <p>Warn user.</p>
1390 <p><b>Warns:</b></p>
1391
1392 **Type** | **Description**
1393 ----------------- | ---------------
1394 [`UserWarning`][] | When this is inappropriate.
1395 ////
1396
1397 //// tab | Without warnings
1398 <h2><code>warn</code></h2>
1399 <p>Warn user.</p>
1400 ////
1401 ///
1402
1403 [](){#option-show_docstring_yields}
1404 ## `show_docstring_yields`
1405
1406 - **:octicons-package-24: Type [`bool`][] :material-equal: `True`{ title="default value" }**
1407 <!-- - **:octicons-project-template-24: Template :material-null:** (N/A) -->
1408
1409 Whether to render the "Yields" section of docstrings.
1410
1411 ```yaml title="in mkdocs.yml (global configuration)"
1412 plugins:
1413 - mkdocstrings:
1414 handlers:
1415 python:
1416 options:
1417 show_docstring_yields: true
1418 ```
1419
1420 ```md title="or in docs/some_page.md (local configuration)"
1421 ::: path.to.module
1422 options:
1423 show_docstring_yields: false
1424 ```
1425
1426 ```python
1427 def iter_skip(
1428 iterable: Iterable[T],
1429 initial_skip: int = 0,
1430 ) -> Generator[T, int, None]:
1431 """Iterate and skip elements.
1432
1433 Yields:
1434 Elements of the iterable.
1435 """
1436 skip = initial_skip
1437 for element in iterable:
1438 if skip or 0 > 0:
1439 skip -= 1
1440 else:
1441 skip = yield element
1442 ```
1443
1444 /// admonition | Preview
1445 type: preview
1446
1447 //// tab | With yielded values
1448 <h2><code>iter_skip</code></h2>
1449 <p>Iterate and skip elements.</p>
1450 <p><b>Yields:</b></p>
1451
1452 **Type** | **Description**
1453 --------- | ---------------
1454 `T` | Elements of the iterable.
1455 ////
1456
1457 //// tab | Without yielded values
1458 <h2><code>iter_skip</code></h2>
1459 <p>Iterate and skip elements.</p>
1460 ////
1461 ///