Skip to content

Conversation

@Dravis-Xam
Copy link

@Dravis-Xam Dravis-Xam commented Nov 12, 2025

Summary by CodeRabbit

  • New Features

    • Automated generation of Python type stubs improves IDE autocomplete and enables better static type checking for Python package users.
  • Chores

    • Added continuous integration workflow to automatically generate and maintain type stubs on code updates.

@coderabbitai
Copy link

coderabbitai bot commented Nov 12, 2025

Walkthrough

A GitHub Actions workflow is added to automatically generate Python type stubs on merges to master and pull requests. The workflow installs mypy, runs stubgen to create type stubs for the package, and commits any generated files using bot credentials.

Changes

Cohort / File(s) Summary
CI/CD Workflow Configuration
.github/workflows/generate-pystubs.yml
Added GitHub Actions workflow to auto-generate Python type stubs on master merges and PRs using stubgen, with automated commit/push of generated stub files.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify workflow triggers (master merges and PRs) are appropriate for the project
  • Confirm Python 3.11 and mypy versions are suitable dependencies
  • Check stubgen command parameters and target package specification
  • Validate GitHub Actions bot credentials and push mechanism

Possibly related issues

Poem

🐰 Hop, hop, stubs take flight,
Through the CI/CD night,
Mypy whispers types so true,
Commits dance in workflow's brew,
Python's secrets now in sight! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, but the description template requires sections covering description, type of change, testing, and a checklist. Add a description following the template with context about the workflow purpose, select the appropriate type of change (Chore), and complete the required checklist sections.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a GitHub Actions workflow file for automatically generating Python type stubs.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
.github/workflows/generate-pystubs.yml (1)

29-33: Add error handling for stubgen failures.

If stubgen fails on line 33 (e.g., due to syntax errors in the package or missing dependencies), the script continues and attempts to commit/push anyway. This masks the underlying issue.

Add error handling to exit early on stubgen failure:

       - name: Generate type stubs
         run: |
           # Adjust 'src' to your code folder
           mkdir -p stubs
+          set -e
           stubgen -p your_package_name -o stubs
+          echo "Type stubs generated successfully"

The set -e flag ensures the workflow stops if any command fails.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c956fcb and 79bb029.

📒 Files selected for processing (1)
  • .github/workflows/generate-pystubs.yml (1 hunks)
🔇 Additional comments (1)
.github/workflows/generate-pystubs.yml (1)

35-41: Ensure git push credentials and branch protection are compatible.

The workflow uses bot credentials to commit and push to master. Verify that:

  1. The bot account has write permissions to the repository and branch.
  2. Branch protection rules (if any) allow force-pushes or bypass for bots, or the workflow must be adjusted.
  3. The git push (line 41) does not fail silently if the branch is ahead or behind upstream.

Consider adding explicit error handling:

           git add stubs/
           git commit -m "Auto-generate PyStubs on merge to master" || echo "No changes to commit"
-          git push
+          git push || echo "Warning: git push failed (branch may be protected or out of sync)"

Alternatively, use git push --force-with-lease if you want to ensure the push succeeds, but only if you understand the implications for concurrent commits.

Comment on lines +3 to +8
on:
push:
branches:
- master # or 'main' if that’s your default branch
pull_request:
branches: [ master ]
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Reconsider triggering on pull_request events.

The workflow is configured to run on both push to master and pull_request to master. This creates conflicting behavior:

  • On push: The workflow generates stubs, commits, and pushes (desired).
  • On pull_request: The workflow still attempts git push (line 41), which typically fails or behaves unexpectedly on PR branches due to branch protection or read-only restrictions.

For PR events, the workflow likely should only validate that stubs can be generated without committing changes. Consider splitting logic by event type:

       - name: Commit and push generated stubs
+        if: github.event_name == 'push'
         run: |
           git config user.name "github-actions[bot]"
           git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
           git add stubs/
           git commit -m "Auto-generate PyStubs on merge to master" || echo "No changes to commit"
           git push
+
+      - name: Validate stubs generation (PR only)
+        if: github.event_name == 'pull_request'
+        run: |
+          echo "Stubs generated successfully for validation"

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
.github/workflows/generate-pystubs.yml lines 3-8: the workflow currently runs on
both push and pull_request but still performs a git push step which fails on PR
runs; update the workflow to branch behavior by event type so PRs only run
generation/validation and pushes only occur on push events. Modify the job/steps
to conditionally skip the commit/push step when github.event_name != 'push' (or
add separate jobs keyed to github.event_name == 'pull_request' for validation
and github.event_name == 'push' for commit-and-push), and ensure the PR job
exits non-zero if generated stubs differ (to surface required changes) while the
push job performs the git commit and push.

@RafaelJohn9
Copy link
Member

RafaelJohn9 commented Nov 13, 2025

Hey,@Dravis-Xam thanks for the PR

Let's address the comments by CodeRabbit first

@Dravis-Xam Dravis-Xam closed this Nov 15, 2025
@RafaelJohn9 RafaelJohn9 reopened this Nov 16, 2025
@RafaelJohn9
Copy link
Member

Hey @Dravis-Xam ,

The only thing remaining, is to address the review comments by coderabbitai then we are good to merge 😄

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