Skip to content

Fix IndexErrors when the "Examples" is the last section in a docstring #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

agriyakhetarpal
Copy link
Member

This PR closes #291, it fixes an IndexError that occurs when processing docstrings where the Examples section is the last section in a docstring when using sphinx.ext.napoleon. I've added bounds checking to prevent accessing indices beyond the end of the lines list in the insert_try_examples_directive function.

@agriyakhetarpal agriyakhetarpal added the bug Something isn't working label May 8, 2025
@agriyakhetarpal agriyakhetarpal added this to the 0.20.1 milestone May 8, 2025
@agriyakhetarpal
Copy link
Member Author

closing/opening to restart CI

@agriyakhetarpal agriyakhetarpal changed the title Fix IndexError when the "Examples" is the last section in a docstring Fix IndexErrors when the "Examples" is the last section in a docstring May 8, 2025
@agriyakhetarpal
Copy link
Member Author

agriyakhetarpal commented May 8, 2025

The errors look unrelated, and I think GitHub has degraded performance at the moment – we should be fine. I don't see anything at https://www.githubstatus.com/, though…

There is now https://www.githubstatus.com/incidents/42gtccf6dd98

@agriyakhetarpal
Copy link
Member Author

Okay, the error is apparently on pre-commit.ci's side; we should be good to go here as the RTD build is working.

@agriyakhetarpal agriyakhetarpal requested a review from steppi May 8, 2025 15:48
)

# Append the remainder of the docstring, if there is any
if right_index < len(lines):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure I understand correctly, this condition will be False in the case where the example section is last and there is no emptyline after it. The check keeps jupyterlite_sphinx from inserting an emptyline at the end in this case. If so, that sounds reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right!

Copy link
Collaborator

@steppi steppi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @agriyakhetarpal, thanks for fixing this.

@agriyakhetarpal
Copy link
Member Author

I still can't figure out what the issue with the check release job is, but it's not related, obviously, so we can debug it as a part of the release process.

@agriyakhetarpal
Copy link
Member Author

Thanks for the review!

@steppi steppi merged commit 637c32e into jupyterlite:main May 8, 2025
7 of 14 checks passed
@agriyakhetarpal agriyakhetarpal deleted the fix-examples-section-end-of-docstring branch May 8, 2025 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

try_examples fails if the examples sections is last
3 participants