GeezerVison is showing github.com — Support #[cfg] in pymodule with by youknowone · Pull Request #6975 · RustPython/RustPython
Conversation
youknowone
commented
Feb 3, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary by CodeRabbit
-
New Features
- Enhanced attribute parsing to support cfg-aware module items, enabling conditional inclusion of submodules.
-
Refactor
- Reworked module initialization and metadata assembly to honor cfg-gated with(...) entries across modules.
-
Bug Fixes
- Corrected platform gating for stdlib modules (ssl, time), removing unconditional stubs and fixing platform-specific exports.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Feb 3, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Caution
Review failed
The pull request is closed.
📝 Walkthrough
Walkthrough
Refactors pymodule attribute parsing: introduces PyModuleArgs and WithItem, makes pymodule/impl_pymodule accept parsed args instead of PunctuatedNestedMeta, adds cfg-aware handling for with(...) items, removes ModuleItemMeta::with(), and updates stdlib usages to use cfg-gated with items. (48 words)
Changes
| Cohort / File(s) |
Summary |
Derive-impl public API & entry crates/derive-impl/src/lib.rs |
Re-exported PyModuleArgs and changed pymodule signature to accept PyModuleArgs. |
Pymodule parsing & generation crates/derive-impl/src/pymodule.rs |
Added WithItem and PyModuleArgs types and parsing; switched impl to accept PyModuleArgs; implemented cfg-aware partitioning of with-items, const gating, negated cfg helpers, and adjusted METHOD_DEFS / __init_attributes generation. |
Utility parsing rules crates/derive-impl/src/util.rs |
Removed ModuleItemMeta::with() and updated ALLOWED_NAMES to exclude "with". |
Derive wrapper crates/derive/src/lib.rs |
Now parses pymodule attributes as derive_impl::PyModuleArgs before calling into derive_impl. |
Stdlib module wiring crates/stdlib/src/openssl.rs, crates/vm/src/stdlib/time.rs |
Rewrote with(...) lists to include #[cfg(...)]-gated items and removed unconditional empty submodule stubs / wasm32 fallback stubs. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested reviewers
Poem
🐰
I parsed the args with nimble paws,
WithItem hops through cfg-gated laws,
No stub left standing in my wake,
Module lists now only compile what’s awake,
Hooray — a hop, a patch, and cake! 🎉
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title clearly summarizes the main change: adding support for conditional compilation attributes (#[cfg]) in pymodule with(...) expressions. |
| Docstring Coverage |
✅ Passed |
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ 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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@crates/derive-impl/src/pymodule.rs`:
- Around line 45-80: The parser for PyModuleArgs currently assigns to with_items
when it encounters a with(...) block, so later with(...) blocks overwrite
earlier ones; in the impl syn::parse::Parse for PyModuleArgs (the parse
function) change the handling inside the "if ident == \"with\"" branch to merge
parsed items into the existing with_items (use Vec::extend or similar on the
Vec<WithItem>) instead of replacing it, ensuring you still parse the trailing
comma and continue; reference the with_items local variable and the parse of
syn::punctuated::Punctuated::<WithItem,...>::parse_terminated(...) as the
locations to modify.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Feb 22, 2026
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|