← Winnitude! Search  ·  Reader Mode (1742 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 58 LINKS

Support #[cfg] in pymodule with by youknowone ยท Pull Request #6975 ยท RustPython/RustPython

Repository navigation

Support #[cfg] in pymodule with - #6975


Merged
youknowone merged 1 commit into RustPython:main from youknowone:cfg-with Feb 3, 2026
Merged

Support #[cfg] in pymodule with #6975 youknowone merged 1 commit into RustPython:main from youknowone:cfg-with

Conversation

youknowone commented Feb 3, 2026 · edited by coderabbitai
Bot
Loading



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.

coderabbitai
Bot
commented Feb 3, 2026 · edited Loading



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

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

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

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

coderabbitai
Bot
left a comment



Copy link Copy Markdown
Contributor

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.
Support #[cfg] in with fc13a9a youknowone force-pushed the cfg-with branch from 306d939 to fc13a9a
Compare
February 3, 2026 09:55 youknowone merged commit 477e20a into RustPython : main Feb 3, 2026 youknowone deleted the cfg-with branch February 3, 2026 09:56 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 Support #[cfg] in with (#6975) 3b956c8 Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment

Labels

None yet

1 participant