Google-style docstring example is not relevant to code snippet
I recently started adding documentation to my project and I am trying to follow the google style guide. I am using Sphinx for document generation and Sphinx napoleon extension to bridge the gap between Google styleguide and reST.
I have no problem with rendering and Notes options, but I can't get an Example section to render a code snippet.
class Chicken(object):
"""Animal that lays egg and has feathers
Note:
Chickens love to eat feed
Example:
chicken.eats(feed)
"""
I've also tried double colon using the Example section.
Example::
+3
source to share
1 answer
You need a double colon and a blank line between the section section Example::
and the literal block.
See an example from the Napoleon docs :
"""Example Google style docstrings.
This module demonstrates documentation as specified by the `Google Python
Style Guide`_. Docstrings may extend over multiple lines. Sections are created
with a section header and a colon followed by a block of indented text.
Example:
Examples can be given using either the ``Example`` or ``Examples``
sections. Sections support any reStructuredText formatting, including
literal blocks::
$ python example_google.py
Section breaks are created by resuming unindented text. Section breaks
are also implicitly created anytime a new section starts.
"""
So, in your example, try this:
class Chicken(object):
"""Animal that lays egg and has feathers
Note:
Chickens love to eat feed
Example::
chicken.eats(feed)
"""
+2
source to share