GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support #[cfg] in pymodule with by youknowone · Pull Request #6975 · RustPython/RustPython

Conversation

@youknowone

@youknowone youknowone commented Feb 3, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

All reactions
@coderabbitai

coderabbitai Bot commented Feb 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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

  • Support #[cfg] in pymodule with #6975: Implements similar changes to pymodule parsing/generation (PyModuleArgs / WithItem / cfg-aware with(...)) — strong overlap.
  • Allow #[pyexception] on module attr #6218: Modifies derive-impl/src/pymodule.rs parsing logic; touches same parsing surface.
  • PySSLCertificate #6219: Adjusts stdlib _ssl pymodule wiring and with(...) usage; related to module wiring changes.

Suggested reviewers

  • coolreader18
  • ShaharNaveh

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 docstrings
🧪 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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone force-pushed the cfg-with branch 2 times, most recently from b221086 to 306d939 Compare February 3, 2026 08:57
@youknowone
youknowone marked this pull request as ready for review February 3, 2026 09:39
coderabbitai[bot]
coderabbitai Bot reviewed Feb 3, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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.

All reactions
Comment thread crates/derive-impl/src/pymodule.rs Resolved

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
Support #[cfg] in with
fc13a9a
@youknowone
youknowone force-pushed the cfg-with branch from 306d939 to fc13a9a Compare February 3, 2026 09:55
@youknowone
youknowone merged commit 477e20a into RustPython:main Feb 3, 2026
@youknowone
youknowone deleted the cfg-with branch February 3, 2026 09:56
@coderabbitai coderabbitai Bot mentioned this pull request Feb 13, 2026
Use CRT functions for time module on Windows #7090
Merged
This was referenced Feb 22, 2026
sys.monitoring #7197
Closed
#[pymodule] submodule support and implicit module_name inheritance #7203
Merged
youknowone added a commit that referenced this pull request Sep 16, 2026
@youknowone
Support #[cfg] in with (#6975)
3b956c8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

1 participant

@youknowone
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.