Skip to content

show_doc includes parsed sections from numpy docstrings #964

@rxavier

Description

@rxavier

Hi! I'm trying to port an existing codebase to nbdev and running into trouble with docstrings.

I'm not sure if I'm not following numpy style docstrings as strictly as I should and tripping over the parser in the process, or whether this is a legitimate bug, so here's a minimal example

I've included a method documented with docments which of course renders nicely.

#| export

class Test:
    """A class for testing
    
    Second line.
    
    Parameters
    ----------
    x
        First param
    y
        Second param in which I have added a /
        line break due to length
        
    Attributes
    ----------
    comb
        String combination of `x` and `y`
    """
    def __init__(self, x: str, y: Optional[int] = None):
        self.x = x
        self.y = y
        self.comb = x + str(y)
        
    def print(self,
              end: str = "-", # Line ending
              ) -> None: # No need to return anything, just print
        """Print attrs
        
        Print attrs 2
        """
        print(self.x, self.y, end=end)
  1. A warning is printed in the rendered docs due to the Attributes section (/Users/rafxavier/Envs/poniard/lib/python3.8/site-packages/fastcore/docscrape.py:225: UserWarning: Unknown section Attributes else: warn(msg)). This is probably because fastcore/docscrape does not support it. Is this intentional? What about other standard numpy sections like Raises? The idea is to document these in notebook markdown?
  2. Types are correctly pulled from the signature and descriptions from the docstings, and everything is rendered nicely in a table. However, a Parameters section with weird formatting is also included.

image

3. If the parameter description has a line break, it's not rendered correctly in the table

image

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions