declarative modules: #[pymodule_export] macro cannot be gated in `cfg_attr`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
The following code fails to work properly because #[pymodule_export] gets ignored even if the pyo3 feature is enabled:
#[cfg(feature = "pyo3")]
use pyo3::prelude::*;
#[cfg_attr(feature = "pyo3", pymodule)]
pub mod py_const {
#[cfg_attr(feature = "pyo3", pymodule_export)]
pub const MY_CONST: () = ();
}
We should update the pymodule macro code to support cfg_attr and not blindly match on #[pymodule_export].
Issue initially reported by @SichangHe (I reused the example): https://github.com/PyO3/pyo3/issues/3900#issuecomment-2944213501
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the pymodule macro code and reproduce the issue with the Rust example and the pyo3 feature enabled. Trace how pymodule_export attributes are recognized through cfg_attr; done means the constant is exported when the feature is enabled without the direct attribute form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100