Skip to content

Parse indented numpy docstring examples#465

Closed
gselzer wants to merge 3 commits into
mkdocstrings:mainfrom
gselzer:indented-numpy-examples
Closed

Parse indented numpy docstring examples#465
gselzer wants to merge 3 commits into
mkdocstrings:mainfrom
gselzer:indented-numpy-examples

Conversation

@gselzer

@gselzer gselzer commented Jun 19, 2026

Copy link
Copy Markdown

For reviewers

  • I did not use AI
  • I used AI and thoroughly reviewed every code/docs change

I've never dug into mkdocstrings before, so the LLM was useful for pinpointing the issue and suggesting a quick fix. Afterwards I slimmed down a rather verbose test 😅

Description of the change

This PR is designed to enable the parsing of numpy-style code examples that are nonuniformly indented. Sometimes authors (read: me) might want to indent a code example to highlight it amidst the larger section - but griffe doesn't pick those up.

This PR also includes a test that fails without the changes.

Relevant resources

This issue was spotted in pyapp-kit/scenex#89

@gselzer gselzer force-pushed the indented-numpy-examples branch from 3b80110 to 815812d Compare June 19, 2026 14:45
@pawamoy

pawamoy commented Jun 19, 2026

Copy link
Copy Markdown
Member

Thanks for the PR @gselzer. Have you considered simply not indenting your >>> blocks and use https://github.com/pawamoy/markdown-pycon to enable proper highlighting once rendered through MkDocs/Zensical?

Also the rendering issue in pyapp-kit/scenex#89 might simply be due to the lack of a blank line between the markup and the >>> block.

@gselzer

gselzer commented Jun 19, 2026

Copy link
Copy Markdown
Author

Have you considered simply not indenting your >>> blocks

Yes, that's what pyapp-kit/scenex#93 does, however it is clear to me now that I am prone to doing this, and in the case others are as well I figured a fix upstream couldn't hurt 😅

and use https://github.com/pawamoy/markdown-pycon to enable proper highlighting once rendered through MkDocs/Zensical?

Umm, maybe, how is that different from the examples within the docstrings are being rendered now without pycon?

image

Also the rendering issue in pyapp-kit/scenex#89 might simply be due to the lack of a blank line between the markup and the >>> block.

Based on a quick change and a local Zensical build that doesn't seem to be part of the issue 🙁

@pawamoy

pawamoy commented Jun 19, 2026

Copy link
Copy Markdown
Member

Ah right the markdown-pycon extension makes it possible to write >>> anywhere, not just in Examples sections understood by Griffe.

Since de-denting such blocks in Examples sections works as expected, I'm gonna close this PR. I'll reconsider if more people run into this 🙂

Thanks again for your contribution!

@pawamoy pawamoy closed this Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants