◐ Shell
clean mode source ↗

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

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.