@@ -5,14 +5,9 @@ even more structured data from source code.
5
5
6
6
The available parsers are:
7
7
8
- - ` google ` , to parse Google-style docstrings,
9
- see [ Napoleon's documentation] ( https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html )
10
- - ` numpy ` , to parse Numpydoc docstrings,
11
- see [ Numpydoc's documentation] ( https://numpydoc.readthedocs.io/en/latest/format.html )
12
- - ` sphinx ` , to parse Sphinx-style docstrings,
13
- see [ Sphinx's documentation] ( https://sphinx-rtd-tutorial.readthedocs.io/en/latest/docstrings.html )
14
-
15
- ## Syntax
8
+ - ` google ` , to parse Google-style docstrings, see [ Napoleon's documentation] [ napoleon ]
9
+ - ` numpy ` , to parse Numpydoc docstrings, see [ Numpydoc's documentation] [ numpydoc ]
10
+ - ` sphinx ` , to parse Sphinx-style docstrings, see [ Sphinx's documentation] [ sphinx ]
16
11
17
12
Most of the time, the syntax specified in the aforementioned docs is supported.
18
13
In some cases, the original syntax is not supported, or is supported but with subtle differences.
@@ -23,7 +18,11 @@ used in docstrings: it's retrieved as regular text.
23
18
Tooling making use of Griffe can then choose to render
24
19
the text as if it is Markdown, or AsciiDoc, or reStructuredText, etc..
25
20
26
- ### Google-style
21
+ ## Google-style
22
+
23
+ Google-style docstrings, see [ Napoleon's documentation] [ napoleon ] .
24
+
25
+ ### Syntax {#google-syntax}
27
26
28
27
Sections are written like this:
29
28
@@ -115,7 +114,26 @@ def foo(a, b):
115
114
"""
116
115
```
117
116
118
- #### Parser options
117
+ ### Admonitions {#google-admonitions}
118
+
119
+ When a section identifier does not match one of the [ supported sections] ( #google-sections ) ,
120
+ the section is parsed as an "admonition" (or "callout").
121
+
122
+ Identifiers are case-insensitive, however singular and plural forms are distinct.
123
+ For example, ` Note: ` is not the same as ` Notes: ` .
124
+
125
+ In particular, ` Examples ` is parsed as the [ Examples section] ( #google-section-examples ) ,
126
+ while ` Example ` is parsed as an admonition whose kind is ` example ` .
127
+
128
+ The kind is obtained by lower-casing the identifier and replacing spaces with dashes.
129
+ For example, an admonition whose identifier is ` See also: ` will have a kind equal to ` see-also ` .
130
+
131
+ Custom section titles are preserved in admonitions:
132
+ ` Tip: Check this out: ` is parsed as a ` tip ` admonition with ` Check this out: ` as title.
133
+
134
+ It is up to any downstream documentation renderer to make use of these kinds and titles.
135
+
136
+ ### Parser options {#google-options}
119
137
120
138
The parser accepts a few options:
121
139
@@ -134,7 +152,11 @@ The parser accepts a few options:
134
152
and should not be visible in your docs. Default: true.
135
153
- ` warn_unknown_params ` : Warn about parameters documented in docstrings that do not appear in the signature. Default: true.
136
154
137
- #### Attributes
155
+ ### Sections {#google-sections}
156
+
157
+ The following sections are supported.
158
+
159
+ #### Attributes {#google-section-attributes}
138
160
139
161
- Multiple items allowed
140
162
@@ -186,7 +208,7 @@ For example, a type of `list[str]` will be parsed just as if it was an actual Py
186
208
You can therefore use complex types (available in the current scope) in docstrings,
187
209
for example ` Optional[Union[int, Tuple[float, float]]] ` .
188
210
189
- #### Functions/Methods
211
+ #### Functions/Methods {#google-section-functions}
190
212
191
213
- Multiple items allowed
192
214
@@ -239,7 +261,7 @@ Functions:
239
261
The signatures do not have to match the real ones:
240
262
you can shorten them to only show the important parameters.
241
263
242
- #### Classes
264
+ #### Classes {#google-section-classes}
243
265
244
266
- Multiple items allowed
245
267
@@ -292,7 +314,7 @@ Functions:
292
314
The signatures do not have to match the real ones:
293
315
you can shorten them to only show the important initialization parameters.
294
316
295
- #### Modules
317
+ #### Modules {#google-section-modules}
296
318
297
319
- Multiple items allowed
298
320
@@ -315,7 +337,7 @@ Modules:
315
337
"""
316
338
```
317
339
318
- #### Deprecated
340
+ #### Deprecated {#google-section-deprecated}
319
341
320
342
Deprecated sections allow to document a deprecation that happened at a particular version.
321
343
They can be used in every docstring.
@@ -330,7 +352,7 @@ Deprecated:
330
352
foo: int = 0
331
353
```
332
354
333
- #### Examples
355
+ #### Examples {#google-section-examples}
334
356
335
357
Examples sections allow to add examples of Python code without the use of markup code blocks.
336
358
They are a mix of prose and interactive console snippets.
@@ -358,7 +380,7 @@ WARNING: **Not the same as *Example* sections.**
358
380
* Example* (singular) sections are parsed as admonitions.
359
381
Console code blocks will only be understood in * Examples* (plural) sections.
360
382
361
- #### Parameters
383
+ #### Parameters {#google-section-parameters}
362
384
363
385
- Aliases: Args, Arguments, Params
364
386
- Multiple items allowed
@@ -412,7 +434,7 @@ For example, a type of `list[str]` will be parsed just as if it was an actual Py
412
434
You can therefore use complex types (available in the current scope) in docstrings,
413
435
for example ` Optional[Union[int, Tuple[float, float]]] ` .
414
436
415
- #### Other Parameters
437
+ #### Other Parameters {#google-section-other-parameters}
416
438
417
439
- Aliases: Keyword Args, Keyword Arguments, Other Args, Other Arguments, Other Params
418
440
- Multiple items allowed
@@ -458,7 +480,7 @@ def foo(a, b):
458
480
TIP: ** Types in docstrings are resolved using the docstrings' parent scope.**
459
481
See the same tip for parameters.
460
482
461
- #### Raises
483
+ #### Raises {#google-section-raises}
462
484
463
485
- Aliases: Exceptions
464
486
- Multiple items allowed
@@ -486,7 +508,7 @@ You can document custom exception, using the names available in the current scop
486
508
for example ` my_exceptions.MyCustomException ` or ` MyCustomException ` directly,
487
509
depending on what you imported/defined in the current module.
488
510
489
- #### Warns
511
+ #### Warns {#google-section-warns}
490
512
491
513
- Aliases: Warnings
492
514
- Multiple items allowed
@@ -513,7 +535,7 @@ You can document custom warnings, using the names available in the current scope
513
535
for example ` my_warnings.MyCustomWarning ` or ` MyCustomWarning ` directly,
514
536
depending on what you imported/defined in the current module.
515
537
516
- #### Yields
538
+ #### Yields {#google-section-yields}
517
539
518
540
- Multiple items allowed
519
541
@@ -573,7 +595,7 @@ Yields:
573
595
TIP: ** Types in docstrings are resolved using the docstrings' parent scope.**
574
596
See previous tips for types in docstrings.
575
597
576
- #### Receives
598
+ #### Receives {#google-section-receives}
577
599
578
600
- Multiple items allowed
579
601
@@ -655,7 +677,7 @@ Receives:
655
677
TIP: ** Types in docstrings are resolved using the docstrings' parent scope.**
656
678
See previous tips for types in docstrings.
657
679
658
- #### Returns
680
+ #### Returns {#google-section-returns}
659
681
660
682
- Multiple items allowed
661
683
@@ -739,7 +761,11 @@ Setting it to false will disallow specifying a name.
739
761
TIP: ** Types in docstrings are resolved using the docstrings' function scope.**
740
762
See previous tips for types in docstrings.
741
763
742
- ### Numpydoc-style
764
+ ## Numpydoc-style
765
+
766
+ Numpydoc docstrings, see [ Numpydoc's documentation] [ numpydoc ]
767
+
768
+ ### Syntax {#numpydoc-syntax}
743
769
744
770
Sections are written like this:
745
771
@@ -821,7 +847,22 @@ several syntaxes are supported:
821
847
"""
822
848
```
823
849
824
- # ### Parser options
850
+ # ## Admonitions {#numpydoc-admonitions}
851
+
852
+ When a section identifier does not match one of the [supported sections](# numpydoc-sections),
853
+ the section is parsed as an " admonition" (or " callout" ).
854
+
855
+ Identifiers are case- insensitive, however singular and plural forms are distinct,
856
+ except for notes and warnings.
857
+ In particular, `Examples` is parsed as the [Examples section](# numpydoc-section-examples),
858
+ while `Example` is parsed as an admonition whose kind is `example` .
859
+
860
+ The kind is obtained by lower- casing the identifier and replacing spaces with dashes.
861
+ For example, an admonition whose identifer is `See also` will have a kind equal to `see- also` .
862
+
863
+ It is up to any downstream documentation renderer to make use of these kinds.
864
+
865
+ # ## Parser options {#numpydoc-options}
825
866
826
867
The parser accepts a few options:
827
868
@@ -833,7 +874,11 @@ The parser accepts a few options:
833
874
and should not be visible in your docs. Default: true.
834
875
- `warn_unknown_params` : Warn about parameters documented in docstrings that do not appear in the signature. Default: true.
835
876
836
- # ### Attributes
877
+ # ## Sections {#numpydoc-sections}
878
+
879
+ The following sections are supported.
880
+
881
+ # ### Attributes {#numpydoc-section-attributes}
837
882
838
883
- Multiple items allowed
839
884
@@ -894,7 +939,7 @@ For example, a type of `list[str]` will be parsed just as if it was an actual Py
894
939
You can therefore use complex types (available in the current scope) in docstrings,
895
940
for example `Optional[Union[int , Tuple[float , float ]]]` .
896
941
897
- #### Functions/Methods
942
+ # ### Functions/Methods {#numpydoc-section-functions}
898
943
899
944
- Multiple items allowed
900
945
@@ -956,7 +1001,7 @@ bar(baz=1)
956
1001
The signatures do not have to match the real ones:
957
1002
you can shorten them to only show the important parameters.
958
1003
959
- #### Classes
1004
+ # ### Classes {#numpydoc-section-classes}
960
1005
961
1006
- Multiple items allowed
962
1007
@@ -1018,7 +1063,7 @@ Bar(baz=1)
1018
1063
The signatures do not have to match the real ones:
1019
1064
you can shorten them to only show the important initialization parameters.
1020
1065
1021
- #### Modules
1066
+ # ### Modules {#numpydoc-section-modules}
1022
1067
1023
1068
- Multiple items allowed
1024
1069
@@ -1044,7 +1089,7 @@ bar
1044
1089
"""
1045
1090
```
1046
1091
1047
- #### Deprecated
1092
+ # ### Deprecated {#numpydoc-section-deprecated}
1048
1093
1049
1094
Deprecated sections allow to document a deprecation that happened at a particular version.
1050
1095
They can be used in every docstring.
@@ -1061,7 +1106,7 @@ Deprecated
1061
1106
foo: int = 0
1062
1107
```
1063
1108
1064
- #### Examples
1109
+ # ### Examples {#numpydoc-section-examples}
1065
1110
1066
1111
Examples sections allow to add examples of Python code without the use of markup code blocks.
1067
1112
They are a mix of prose and interactive console snippets.
@@ -1086,7 +1131,7 @@ Blank lines delimit prose vs. console blocks.
1086
1131
"""
1087
1132
```
1088
1133
1089
- #### Parameters
1134
+ # ### Parameters {#numpydoc-section-parameters}
1090
1135
1091
1136
- Aliases: Args, Arguments, Params
1092
1137
- Multiple items allowed
@@ -1149,7 +1194,7 @@ For example, a type of `list[str]` will be parsed just as if it was an actual Py
1149
1194
You can therefore use complex types (available in the current scope) in docstrings,
1150
1195
for example `Optional[Union[int , Tuple[float , float ]]]` .
1151
1196
1152
- #### Other Parameters
1197
+ # ### Other Parameters {#numpydoc-section-other-parameters}
1153
1198
1154
1199
- Aliases: Keyword Args, Keyword Arguments, Other Args, Other Arguments, Other Params
1155
1200
- Multiple items allowed
@@ -1181,7 +1226,7 @@ def foo(a, b, **kwargs):
1181
1226
TIP : ** Types in docstrings are resolved using the docstrings' parent scope.**
1182
1227
See the same tip for parameters.
1183
1228
1184
- #### Raises
1229
+ # ### Raises {#numpydoc-section-raises}
1185
1230
1186
1231
- Aliases: Exceptions
1187
1232
- Multiple items allowed
@@ -1213,9 +1258,8 @@ You can document custom exception, using the names available in the current scop
1213
1258
for example `my_exceptions.MyCustomException` or `MyCustomException` directly,
1214
1259
depending on what you imported/ defined in the current module.
1215
1260
1216
- #### Warns
1261
+ # ### Warns {#numpydoc-section-warns}
1217
1262
1218
- - Aliases: Warnings
1219
1263
- Multiple items allowed
1220
1264
1221
1265
Warns sections allow to document warnings emitted by the following code.
@@ -1242,7 +1286,7 @@ You can document custom warnings, using the names available in the current scope
1242
1286
for example `my_warnings.MyCustomWarning` or `MyCustomWarning` directly,
1243
1287
depending on what you imported/ defined in the current module.
1244
1288
1245
- #### Yields
1289
+ # ### Yields {#numpydoc-section-yields}
1246
1290
1247
1291
- Multiple items allowed
1248
1292
@@ -1310,7 +1354,7 @@ t : int
1310
1354
TIP : ** Types in docstrings are resolved using the docstrings' parent scope.**
1311
1355
See previous tips for types in docstrings.
1312
1356
1313
- #### Receives
1357
+ # ### Receives {#numpydoc-section-receives}
1314
1358
1315
1359
- Multiple items allowed
1316
1360
@@ -1401,7 +1445,7 @@ flag : int
1401
1445
TIP : ** Types in docstrings are resolved using the docstrings' parent scope.**
1402
1446
See previous tips for types in docstrings.
1403
1447
1404
- #### Returns
1448
+ # ### Returns {#numpydoc-section-returns}
1405
1449
1406
1450
- Multiple items allowed
1407
1451
@@ -1568,3 +1612,7 @@ Returns | ✅ | ✅ | [❌][issue-xref-sphinx-returns]
1568
1612
[merge_init]: https:// mkdocstrings.github.io/ python/ usage/ configuration/ docstrings/ # merge_init_into_class
1569
1613
[doctest flags]: https:// docs.python.org/ 3 / library/ doctest.html# option-flags
1570
1614
[doctest]: https:// docs.python.org/ 3 / library/ doctest.html# module-doctest
1615
+
1616
+ [napoleon]: https:// sphinxcontrib- napoleon.readthedocs.io/ en/ latest/ example_google.html
1617
+ [numpydoc]: https:// numpydoc.readthedocs.io/ en/ latest/ format .html
1618
+ [sphinx]: https:// sphinx- rtd- tutorial.readthedocs.io/ en/ latest/ docstrings.html
0 commit comments