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