Search code examples
pythonspyderdocstring

docstring codeblock not showing properly in spyder


I am trying to create an block of example code for a python module that I have written, according to here spyder uses sphinx to render the docstring in the help window. When I try to create a code block with:

'''
Example:
---------
.. code-block :: python

:: 
    def testing():
        pass
'''

Below is what is rendered:
testing(): ... should be inside the highlighted block. I have no idea how to fix this... Any help would be greatly appreciated!


Solution

  • So it turns out (after a lot of fiddling) that an empty line under :: is required:

    '''
    Example:
    ---------
    ::
    
        def testing():
            pass
    '''
    

    Renders properly, enter image description here
    It seems that .. code-block :: python was also causing some problems, I am not sure why.