Skip to content

Conversation

@mrexodia
Copy link

@mrexodia mrexodia commented Dec 16, 2025

The module doc is missing from the generated type stubs, this PR fixes that.

Copilot AI review requested due to automatic review settings December 16, 2025 17:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for capturing and outputting module-level docstrings in stubgen. When generating stub files, the module's __doc__ attribute is now included at the top of the generated output if docstrings are enabled.

Key changes:

  • Extracted docstring escaping logic into a separate escape_docstr() method for reuse
  • Added module docstring capture during module processing
  • Modified stub output generation to place module docstrings at the top of the file

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
tests/test_functions_ext.pyi.ref Added expected module docstring in test reference file
src/stubgen.py Implemented module docstring capture and output functionality

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mrexodia
Copy link
Author

I need some help with the CI, not exactly sure how the tests work...

@wjakob
Copy link
Owner

wjakob commented Dec 16, 2025

Is this an AI-generated PR?

Can you explain the change related to put_docstr and escape_docstr?

@mrexodia
Copy link
Author

Is this an AI-generated PR?

Yes, why? I saw this feature was missing and had Claude implement it. I obviously reviewed the logic myself before spamming you with some AI slop though 😅 I did forget to set it as a draft, that was a mistake on my part.

Can you explain the change related to put_docstr and escape_docstr?

The put_docstr appends to the self.output and this is inserted after the imports. The module docstring needs to be before the imports, so I moved the logic to escape the docstring to a separate function. Open to other ideas though 🙂

@mrexodia mrexodia marked this pull request as draft December 16, 2025 23:21
@wjakob wjakob force-pushed the master branch 3 times, most recently from 1235f9a to 4ba51fc Compare December 19, 2025 10:00
@mrexodia mrexodia force-pushed the module-docstring branch 3 times, most recently from 67ce20b to 4b4ca5e Compare December 19, 2025 12:37
@mrexodia mrexodia marked this pull request as ready for review December 19, 2025 12:38
@mrexodia
Copy link
Author

Alright, the PR should now be ready for review. I also had to update the special case for test_functions_ext in test_stubs.py to insert a bit further down so the tests would pass for every python version.

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