1414Overview
1515--------
1616
17- .. highlight :: text
17+ Are you tired of writing docstrings that look like this:
1818
19- Are you tired of writing docstrings that look like this::
19+ .. code-block :: rst
2020
2121 :param path: The path of the file to wrap
2222 :type path: str
@@ -30,7 +30,9 @@ Are you tired of writing docstrings that look like this::
3030
3131 `reStructuredText `_ is great, but it creates visually dense, hard to read
3232:pep: `docstrings <287 >`. Compare the jumble above to the same thing rewritten
33- according to the `Google Python Style Guide `_::
33+ according to the `Google Python Style Guide `_:
34+
35+ .. code-block :: text
3436
3537 Args:
3638 path (str): The path of the file to wrap
@@ -66,14 +68,18 @@ Getting Started
6668~~~~~~~~~~~~~~~
6769
68701. After :doc: `setting up Sphinx </usage/quickstart >` to build your docs,
69- enable napoleon in the Sphinx ``conf.py `` file::
71+ enable napoleon in the Sphinx ``conf.py `` file:
72+
73+ .. code-block :: python
7074
7175 # conf.py
7276
7377 # Add napoleon to the extensions list
7478 extensions = [' sphinx.ext.napoleon' ]
7579
76- 2. Use ``sphinx-apidoc `` to build your API documentation::
80+ 2. Use ``sphinx-apidoc `` to build your API documentation:
81+
82+ .. code-block :: console
7783
7884 $ sphinx-apidoc -f -o docs/source projectdir
7985
@@ -206,7 +212,9 @@ type checkers and IDEs can take advantage of them for static code
206212analysis. :pep: `484 ` was then extended by :pep: `526 ` which introduced
207213a similar way to annotate variables (and attributes).
208214
209- Google style with Python 3 type annotations::
215+ Google style with Python 3 type annotations:
216+
217+ .. code-block :: python
210218
211219 def func (arg1 : int , arg2 : str ) -> bool :
212220 """ Summary line.
@@ -236,7 +244,9 @@ Google style with Python 3 type annotations::
236244 attr1: int
237245 attr2: str
238246
239- Google style with types in docstrings::
247+ Google style with types in docstrings:
248+
249+ .. code-block :: python
240250
241251 def func (arg1 , arg2 ):
242252 """ Summary line.
@@ -263,19 +273,15 @@ Google style with types in docstrings::
263273 attr2 (str): Description of attr2
264274 """
265275
266- .. Note ::
267- `Python 2/3 compatible annotations `_ aren't currently
268- supported by Sphinx and won't show up in the docs.
269-
270- .. _Python 2/3 compatible annotations : https://peps.python.org/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code
271-
272276
273277 Configuration
274278-------------
275279
276280Listed below are all the settings used by napoleon and their default
277281values. These settings can be changed in the Sphinx ``conf.py `` file. Make
278- sure that "sphinx.ext.napoleon" is enabled in ``conf.py ``::
282+ sure that "sphinx.ext.napoleon" is enabled in ``conf.py ``:
283+
284+ .. code-block :: python
279285
280286 # conf.py
281287
@@ -326,7 +332,9 @@ sure that "sphinx.ext.napoleon" is enabled in ``conf.py``::
326332 considers the ``__init___ `` docstring as part of the class
327333 documentation.
328334
329- **If True **::
335+ **If True **:
336+
337+ .. code-block :: python
330338
331339 def __init__ (self ):
332340 """
@@ -343,7 +351,9 @@ sure that "sphinx.ext.napoleon" is enabled in ``conf.py``::
343351 True to include private members (like ``_membername ``) with docstrings
344352 in the documentation. False to fall back to Sphinx's default behavior.
345353
346- **If True **::
354+ **If True **:
355+
356+ .. code-block :: python
347357
348358 def _included (self ):
349359 """
@@ -363,7 +373,9 @@ sure that "sphinx.ext.napoleon" is enabled in ``conf.py``::
363373 docstrings in the documentation. False to fall back to Sphinx's
364374 default behavior.
365375
366- **If True **::
376+ **If True **:
377+
378+ .. code-block :: python
367379
368380 def __str__ (self ):
369381 """
@@ -384,19 +396,25 @@ sure that "sphinx.ext.napoleon" is enabled in ``conf.py``::
384396 instead. One may look better than the other depending on what HTML
385397 theme is used.
386398
387- This `NumPy style `_ snippet will be converted as follows::
399+ This `NumPy style `_ snippet will be converted as follows:
400+
401+ .. code-block :: text
388402
389403 Example
390404 -------
391405 This is just a quick example
392406
393- **If True **::
407+ **If True **:
408+
409+ .. code-block :: rst
394410
395411 .. admonition:: Example
396412
397413 This is just a quick example
398414
399- **If False **::
415+ **If False **:
416+
417+ .. code-block :: rst
400418
401419 .. rubric:: Example
402420
@@ -434,19 +452,25 @@ sure that "sphinx.ext.napoleon" is enabled in ``conf.py``::
434452 True to use the ``:ivar: `` role for instance variables. False to use
435453 the ``.. attribute:: `` directive instead.
436454
437- This `NumPy style `_ snippet will be converted as follows::
455+ This `NumPy style `_ snippet will be converted as follows:
456+
457+ .. code-block :: text
438458
439459 Attributes
440460 ----------
441461 attr1 : int
442462 Description of `attr1`
443463
444- **If True **::
464+ **If True **:
465+
466+ .. code-block :: rst
445467
446468 :ivar attr1: Description of `attr1`
447469 :vartype attr1: int
448470
449- **If False **::
471+ **If False **:
472+
473+ .. code-block :: rst
450474
451475 .. attribute:: attr1
452476
@@ -461,7 +485,9 @@ sure that "sphinx.ext.napoleon" is enabled in ``conf.py``::
461485 True to use a ``:param: `` role for each function parameter. False to
462486 use a single ``:parameters: `` role for all the parameters.
463487
464- This `NumPy style `_ snippet will be converted as follows::
488+ This `NumPy style `_ snippet will be converted as follows:
489+
490+ .. code-block :: text
465491
466492 Parameters
467493 ----------
@@ -470,14 +496,18 @@ sure that "sphinx.ext.napoleon" is enabled in ``conf.py``::
470496 arg2 : int, optional
471497 Description of `arg2`, defaults to 0
472498
473- **If True **::
499+ **If True **:
500+
501+ .. code-block :: rst
474502
475503 :param arg1: Description of `arg1`
476504 :type arg1: str
477505 :param arg2: Description of `arg2`, defaults to 0
478506 :type arg2: :class:`int`, *optional*
479507
480- **If False **::
508+ **If False **:
509+
510+ .. code-block :: rst
481511
482512 :parameters: * **arg1** (*str*) --
483513 Description of `arg1`
@@ -508,19 +538,25 @@ sure that "sphinx.ext.napoleon" is enabled in ``conf.py``::
508538 True to use the ``:rtype: `` role for the return type. False to output
509539 the return type inline with the description.
510540
511- This `NumPy style `_ snippet will be converted as follows::
541+ This `NumPy style `_ snippet will be converted as follows:
542+
543+ .. code-block :: text
512544
513545 Returns
514546 -------
515547 bool
516548 True if successful, False otherwise
517549
518- **If True **::
550+ **If True **:
551+
552+ .. code-block :: rst
519553
520554 :returns: True if successful, False otherwise
521555 :rtype: bool
522556
523- **If False **::
557+ **If False **:
558+
559+ .. code-block :: rst
524560
525561 :returns: *bool* -- True if successful, False otherwise
526562
@@ -542,14 +578,18 @@ sure that "sphinx.ext.napoleon" is enabled in ``conf.py``::
542578 A mapping to translate type names to other names or references. Works
543579 only when ``napoleon_use_param = True ``.
544580
545- With::
581+ With:
582+
583+ .. code-block :: python
546584
547585 napoleon_type_aliases = {
548586 " CustomType" : " mypackage.CustomType" ,
549587 " dict-like" : " :term:`dict-like <mapping>`" ,
550588 }
551589
552- This `NumPy style `_ snippet::
590+ This `NumPy style `_ snippet:
591+
592+ .. code-block :: text
553593
554594 Parameters
555595 ----------
@@ -558,7 +598,9 @@ sure that "sphinx.ext.napoleon" is enabled in ``conf.py``::
558598 arg2 : dict-like
559599 Description of `arg2`
560600
561- becomes::
601+ becomes:
602+
603+ .. code-block :: rst
562604
563605 :param arg1: Description of `arg1`
564606 :type arg1: mypackage.CustomType
0 commit comments