Skip to content

✨ Add auto-generated stub file#520

Merged
denialhaag merged 3 commits into
mainfrom
auto-stubs
Jan 26, 2026
Merged

✨ Add auto-generated stub file#520
denialhaag merged 3 commits into
mainfrom
auto-stubs

Conversation

@denialhaag

Copy link
Copy Markdown
Member

Description

After we have switched from pybind11 to nanobind in #514, we can now auto-generate the stub file.

Checklist:

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

@denialhaag denialhaag self-assigned this Jan 25, 2026
@denialhaag denialhaag added python Anything related to Python code usability Anything related to usability minor Changes that imply a new minor release labels Jan 25, 2026
Comment thread bindings/bindings.cpp
@coderabbitai

coderabbitai Bot commented Jan 25, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@denialhaag has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 21 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

This pull request adds Python type stub generation infrastructure and updates the Python binding API. It introduces a new nox session to generate .pyi type stubs, enables stub checking in CI, updates binding parameter names, removes the addModule method, and adds a comprehensive type stub file defining the public API for the SyReC quantum synthesis framework.

Changes

Cohort / File(s) Summary
CI and Workflow Configuration
.github/workflows/ci.yml, .license-tools-config.json, pyproject.toml
Added stub checking flag to python-linter workflow; expanded per-file ignore rules for .pyi files from single code D to multiple codes (D418, E501, N801, PYI021); excluded syrec_patterns.txt from license tool scanning
Stub Generation Infrastructure
bindings/syrec_patterns.txt, noxfile.py
Created new syrec_patterns.txt for nanobind stub generation configuration; added nox "stubs" session (50 lines) that runs nanobind.stubgen, executes code quality tools via prek (license-tools, ruff), and manages environment setup
Python Type Stub Definitions
python/mqt/syrec/pysyrec.pyi
Added comprehensive type stub file (236 lines) defining public API for quantum synthesis framework: data model types (qubit_inlining_stack_entry, inlined_qubit_information), core classes (annotatable_quantum_computation, program, configurable_options, n_bit_values_container), enums (qubit_label_type, integer_constant_truncation_operation), and synthesis/simulation functions
Python Bindings API Updates
bindings/bindings.cpp
Removed addModule method exposure on Program; renamed parameter stringifiedProgramstringified_program in read_from_string; renamed parameter inputinput_ in simple_simulation; updated docstring parameter name in NBitValuesContainer constructor
Editor Implementation
python/mqt/syrec/syrec_editor.py
Added public attribute annotatable_quantum_computation: syrec.annotatable_quantum_computation | None; added runtime assertions in stat() and sim() methods; modified save_settings() to conditionally update main_module_identifier only when not None

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • workflows#288: Modifies stub-generation workflow to use the new nox "stubs" session that this PR introduces
  • workflows#286: Enables the check-stubs behavior in the reusable python-linter that this PR activates in CI
  • syrec#514: Relates to binding infrastructure changes; previous pybind11-to-nanobind migration affecting the binding API updates in this PR

Suggested reviewers

  • burgholzer

Poem

🐰 With stubs now typed and bindings clean,
The finest API you've ever seen!
Patterns in files, sessions that gleam,
Type safety flows like a quantum dream!

🚥 Pre-merge checks | ❌ 3
❌ Failed checks (1 warning, 2 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.19% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic. While it mentions 'stub file', it uses the general term 'auto-generated' without specifying what this enables or why it matters. Provide a more descriptive title that clearly indicates the specific improvement, such as 'Enable auto-generation of Python type stubs' or 'Add nanobind stub generation workflow'.
Description check ❓ Inconclusive The description addresses the main context but lacks critical details about implementation scope and specific changes made across multiple files in the changeset. Enhance the description to detail the key changes: new nox stubs session, bindings API updates, CI workflow changes, and pyproject.toml linting rules for .pyi files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Fix all issues with AI agents
In `@noxfile.py`:
- Around line 198-214: pyi_files is a list of Path objects from
package_root.glob("**/*.pyi") but is passed directly into session.run calls;
convert each Path to a string before invoking prek so the subprocess arguments
are consistent with earlier code: map or list-comprehend pyi_files into string
paths and use that string list when calling session.run("prek", "run", ...,
"--files", *pyi_files, external=True, success_codes=...) (and the final
ruff-check run) to ensure all calls use str paths.

In `@python/mqt/syrec/syrec_editor.py`:
- Around line 1252-1255: The assignment to
configurable_parser_and_synthesis_options.main_module_identifier should only
occur when the textbox holds a non-empty identifier; change the guard around
expected_main_module_identifier_textbox.text() so you validate and use
.text().strip() and only assign when that stripped value is non-empty (i.e.,
replace the current None-check with a check that
expected_main_module_identifier_textbox.text().strip() != ""), leaving the rest
of the assignment to
configurable_parser_and_synthesis_options.main_module_identifier as-is.
- Around line 460-462: The stat() (and similarly sim()) method currently uses an
assert on self.annotatable_quantum_computation which can be removed under -O;
replace the assert with an explicit runtime guard that checks if
self.annotatable_quantum_computation is None, calls show_error_dialog(...) with
a clear user-facing message, and returns early to avoid further access; update
any subsequent accesses in stat() to rely on the guarded value (e.g., local
variable qc = self.annotatable_quantum_computation after the guard) so the
method no longer depends on assert behavior.

Comment thread noxfile.py
Comment thread python/mqt/syrec/syrec_editor.py
Comment thread python/mqt/syrec/syrec_editor.py Outdated
@codecov

codecov Bot commented Jan 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@denialhaag denialhaag requested a review from burgholzer January 26, 2026 00:43
@denialhaag denialhaag added the feature New feature or request label Jan 26, 2026

@burgholzer burgholzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great! Thanks 🙏🏼
I think the stubs really help here.
They also show that some of the naming patterns in the bindings are not particularly optimal (especially class names). We may want to change that in a subsequent PR to align the naming closer with the Python naming conventions.

Comment thread bindings/bindings.cpp
@denialhaag

Copy link
Copy Markdown
Member Author

They also show that some of the naming patterns in the bindings are not particularly optimal (especially class names). We may want to change that in a subsequent PR to align the naming closer with the Python naming conventions.

I agree! I'll add it to my list!

@denialhaag denialhaag merged commit b886a91 into main Jan 26, 2026
26 checks passed
@denialhaag denialhaag deleted the auto-stubs branch January 26, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request minor Changes that imply a new minor release python Anything related to Python code usability Anything related to usability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants