@@ -119,6 +119,8 @@ The sections of a function's docstring are:
119
119
120
120
"""
121
121
122
+ .. highlight :: rst
123
+
122
124
2. **Deprecation warning **
123
125
124
126
A section (use if applicable) to warn users that the object is deprecated.
@@ -250,13 +252,21 @@ The sections of a function's docstring are:
250
252
Support for the **Yields ** section was added in `numpydoc
251
253
<https://github.com/numpy/numpydoc> `_ version 0.6.
252
254
253
- 7. **Other Parameters **
255
+ 7. **Receives **
256
+
257
+ Explanation of parameters passed to a generator's ``.send() `` method,
258
+ formatted as for Parameters, above. Since, like for Yields and Returns, a
259
+ single object is always passed to the method, this may describe either the
260
+ single parameter, or positional arguments passed as a tuple. If a docstring
261
+ includes Receives it must also include Yields.
262
+
263
+ 8. **Other Parameters **
254
264
255
265
An optional section used to describe infrequently used parameters.
256
266
It should only be used if a function has a large number of keyword
257
267
parameters, to prevent cluttering the **Parameters ** section.
258
268
259
- 8 . **Raises **
269
+ 9 . **Raises **
260
270
261
271
An optional section detailing which errors get raised and under
262
272
what conditions::
@@ -269,55 +279,55 @@ The sections of a function's docstring are:
269
279
This section should be used judiciously, i.e., only for errors
270
280
that are non-obvious or have a large chance of getting raised.
271
281
272
- 9 . **Warns **
282
+ 10 . **Warns **
273
283
274
284
An optional section detailing which warnings get raised and
275
285
under what conditions, formatted similarly to Raises.
276
286
277
- 10 . **Warnings **
287
+ 11 . **Warnings **
278
288
279
- An optional section with cautions to the user in free text/reST.
289
+ An optional section with cautions to the user in free text/reST.
280
290
281
- 11 . **See Also **
291
+ 12 . **See Also **
282
292
283
- An optional section used to refer to related code. This section
284
- can be very useful, but should be used judiciously. The goal is to
285
- direct users to other functions they may not be aware of, or have
286
- easy means of discovering (by looking at the module docstring, for
287
- example). Routines whose docstrings further explain parameters
288
- used by this function are good candidates.
293
+ An optional section used to refer to related code. This section
294
+ can be very useful, but should be used judiciously. The goal is to
295
+ direct users to other functions they may not be aware of, or have
296
+ easy means of discovering (by looking at the module docstring, for
297
+ example). Routines whose docstrings further explain parameters
298
+ used by this function are good candidates.
289
299
290
- As an example, for ``numpy.mean `` we would have::
300
+ As an example, for ``numpy.mean `` we would have::
291
301
292
- See Also
293
- --------
294
- average : Weighted average
302
+ See Also
303
+ --------
304
+ average : Weighted average
295
305
296
- When referring to functions in the same sub-module, no prefix is
297
- needed, and the tree is searched upwards for a match.
306
+ When referring to functions in the same sub-module, no prefix is
307
+ needed, and the tree is searched upwards for a match.
298
308
299
- Prefix functions from other sub-modules appropriately. E.g.,
300
- whilst documenting the ``random `` module, refer to a function in
301
- ``fft `` by
309
+ Prefix functions from other sub-modules appropriately. E.g.,
310
+ whilst documenting the ``random `` module, refer to a function in
311
+ ``fft `` by
302
312
303
- ::
313
+ ::
304
314
305
- fft.fft2 : 2-D fast discrete Fourier transform
315
+ fft.fft2 : 2-D fast discrete Fourier transform
306
316
307
- When referring to an entirely different module::
317
+ When referring to an entirely different module::
308
318
309
- scipy.random.norm : Random variates, PDFs, etc.
319
+ scipy.random.norm : Random variates, PDFs, etc.
310
320
311
- Functions may be listed without descriptions, and this is
312
- preferable if the functionality is clear from the function name::
321
+ Functions may be listed without descriptions, and this is
322
+ preferable if the functionality is clear from the function name::
313
323
314
- See Also
315
- --------
316
- func_a : Function a with its description.
317
- func_b, func_c_, func_d
318
- func_e
324
+ See Also
325
+ --------
326
+ func_a : Function a with its description.
327
+ func_b, func_c_, func_d
328
+ func_e
319
329
320
- 12 . **Notes **
330
+ 13 . **Notes **
321
331
322
332
An optional section that provides additional information about the
323
333
code, possibly including a discussion of the algorithm. This
@@ -362,7 +372,7 @@ The sections of a function's docstring are:
362
372
where filename is a path relative to the reference guide source
363
373
directory.
364
374
365
- 13 . **References **
375
+ 14 . **References **
366
376
367
377
References cited in the **notes ** section may be listed here,
368
378
e.g. if you cited the article below using the text ``[1]_ ``,
@@ -374,7 +384,7 @@ The sections of a function's docstring are:
374
384
and neural-network techniques," Computers & Geosciences, vol. 22,
375
385
pp. 585-588, 1996.
376
386
377
- which renders as
387
+ which renders as [ 1 ]_:
378
388
379
389
.. [1 ] O. McNoleg, "The integration of GIS, remote sensing,
380
390
expert systems and adaptive co-kriging for environmental habitat
@@ -393,7 +403,9 @@ The sections of a function's docstring are:
393
403
docstring, the table markup will be broken by numpydoc processing. See
394
404
`numpydoc issue #130 <https://github.com/numpy/numpydoc/issues/130 >`_
395
405
396
- 14. **Examples **
406
+ .. highlight :: pycon
407
+
408
+ 15. **Examples **
397
409
398
410
An optional section for examples, using the `doctest
399
411
<http://docs.python.org/library/doctest.html> `_ format.
@@ -413,6 +425,14 @@ The sections of a function's docstring are:
413
425
>>> np.add([1, 2], [3, 4])
414
426
array([4, 6])
415
427
428
+ The example code may be split across multiple lines, with each line after
429
+ the first starting with '... '::
430
+
431
+ >>> np.add([[1, 2], [3, 4]],
432
+ ... [[5, 6], [7, 8]])
433
+ array([[ 6, 8],
434
+ [10, 12]])
435
+
416
436
For tests with a result that is random or platform-dependent, mark the
417
437
output as such::
418
438
@@ -456,6 +476,7 @@ The sections of a function's docstring are:
456
476
`matplotlib.sphinxext.plot_directive ` is loaded as a Sphinx extension in
457
477
``conf.py ``.
458
478
479
+ .. highlight :: rst
459
480
460
481
Documenting classes
461
482
-------------------
@@ -493,7 +514,9 @@ In general, it is not necessary to list class methods. Those that are
493
514
not part of the public API have names that start with an underscore.
494
515
In some cases, however, a class may have a great many methods, of
495
516
which only a few are relevant (e.g., subclasses of ndarray). Then, it
496
- becomes useful to have an additional **Methods ** section::
517
+ becomes useful to have an additional **Methods ** section:
518
+
519
+ .. code-block :: python
497
520
498
521
class Photo (ndarray ):
499
522
"""
0 commit comments