docstring_parser icon indicating copy to clipboard operation
docstring_parser copied to clipboard

Fix numpy docstring example parsing

Open kesmit13 opened this issue 5 months ago • 1 comments

The numpy example parsing didn't seem to work the way numpy examples are formatted in the real-world. The assumption is that they look like this:

Examples
-----------
>>> print('hi')        <== code snippet
hi                            <== description

However, the correct interpretation is:

Examples
-----------
>>> print('hi')          <== code snippet
hi                              <== output of code snippet

If descriptions are used, they go before the snippet:

Examples
----------
Print the word 'hi':

>>> print('hi')
hi

It is also possible to have continuation marks after the initial Python prompt:

Examples
-----------
Print the word 'hi' 5 times:

>>> for i in range(5):
...    print('hi')
hi
hi
hi
hi
hi

The code in this PR changes the way that numpy examples are parsed to allow for these changes, so it is a breaking change.

kesmit13 avatar Jul 30 '25 16:07 kesmit13

Thank you for the PR. A couple of notes:

  • Can we update the tests to cover the added functionality?
  • Let's update the changelog to include this change.
  • Let's rebase with the newest changes and fix the styling issues.

rr- avatar Aug 22 '25 21:08 rr-