Skip to content

Commit ddff8be

Browse files
authored
Stabilize declarative modules (#4257)
1 parent baae929 commit ddff8be

10 files changed

+4
-36
lines changed

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ experimental-async = ["macros", "pyo3-macros/experimental-async"]
7575
# and IntoPy traits
7676
experimental-inspect = []
7777

78-
# Enables annotating Rust inline modules with #[pymodule] to build Python modules declaratively
79-
experimental-declarative-modules = ["pyo3-macros/experimental-declarative-modules", "macros"]
80-
8178
# Enables macros: #[pyclass], #[pymodule], #[pyfunction] etc.
8279
macros = ["pyo3-macros", "indoc", "unindent"]
8380

@@ -125,7 +122,6 @@ full = [
125122
"chrono-tz",
126123
"either",
127124
"experimental-async",
128-
"experimental-declarative-modules",
129125
"experimental-inspect",
130126
"eyre",
131127
"hashbrown",

guide/src/features.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ This feature adds support for `async fn` in `#[pyfunction]` and `#[pymethods]`.
5757

5858
The feature has some unfinished refinements and performance improvements. To help finish this off, see [issue #1632](https://github.com/PyO3/pyo3/issues/1632) and its associated draft PRs.
5959

60-
### `experimental-declarative-modules`
61-
62-
This feature allows to declare Python modules using `#[pymodule] mod my_module { ... }` syntax.
63-
64-
The feature has some unfinished refinements and edge cases. To help finish this off, see [issue #3900](https://github.com/PyO3/pyo3/issues/3900).
65-
6660
### `experimental-inspect`
6761

6862
This feature adds the `pyo3::inspect` module, as well as `IntoPy::type_output` and `FromPyObject::type_input` APIs to produce Python type "annotations" for Rust types.

guide/src/module.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,12 @@ submodules by using `from parent_module import child_module`. For more informati
106106

107107
It is not necessary to add `#[pymodule]` on nested modules, which is only required on the top-level module.
108108

109-
## Declarative modules (experimental)
109+
## Declarative modules
110110

111111
Another syntax based on Rust inline modules is also available to declare modules.
112-
The `experimental-declarative-modules` feature must be enabled to use it.
113112

114113
For example:
115114
```rust
116-
# #[cfg(feature = "experimental-declarative-modules")]
117115
# mod declarative_module_test {
118116
use pyo3::prelude::*;
119117

@@ -157,7 +155,6 @@ For nested modules, the name of the parent module is automatically added.
157155
In the following example, the `Unit` class will have for `module` `my_extension.submodule` because it is properly nested
158156
but the `Ext` class will have for `module` the default `builtins` because it not nested.
159157
```rust
160-
# #[cfg(feature = "experimental-declarative-modules")]
161158
# mod declarative_module_module_attr_test {
162159
use pyo3::prelude::*;
163160

@@ -184,7 +181,3 @@ mod my_extension {
184181
```
185182
It is possible to customize the `module` value for a `#[pymodule]` with the `#[pyo3(module = "MY_MODULE")]` option.
186183

187-
Some changes are planned to this feature before stabilization, like automatically
188-
filling submodules into `sys.modules` to allow easier imports (see [issue #759](https://github.com/PyO3/pyo3/issues/759)).
189-
Macro names might also change.
190-
See [issue #3900](https://github.com/PyO3/pyo3/issues/3900) to track this feature progress.

newsfragments/4257.changed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The `experimental-declarative-modules` feature is now stabilized and available by default

pyo3-macros/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ proc-macro = true
1616
[features]
1717
multiple-pymethods = []
1818
experimental-async = ["pyo3-macros-backend/experimental-async"]
19-
experimental-declarative-modules = []
2019
gil-refs = ["pyo3-macros-backend/gil-refs"]
2120

2221
[dependencies]

pyo3-macros/src/lib.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,7 @@ use syn::{parse::Nothing, parse_macro_input, Item};
3737
pub fn pymodule(args: TokenStream, input: TokenStream) -> TokenStream {
3838
parse_macro_input!(args as Nothing);
3939
match parse_macro_input!(input as Item) {
40-
Item::Mod(module) => if cfg!(feature = "experimental-declarative-modules") {
41-
pymodule_module_impl(module)
42-
} else {
43-
Err(syn::Error::new_spanned(
44-
module,
45-
"#[pymodule] requires the 'experimental-declarative-modules' feature to be used on Rust modules.",
46-
))
47-
},
40+
Item::Mod(module) => pymodule_module_impl(module),
4841
Item::Fn(function) => pymodule_function_impl(function),
4942
unsupported => Err(syn::Error::new_spanned(
5043
unsupported,

tests/test_append_to_inittab.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fn module_fn_with_functions(m: &Bound<'_, PyModule>) -> PyResult<()> {
1313
Ok(())
1414
}
1515

16-
#[cfg(feature = "experimental-declarative-modules")]
1716
#[pymodule]
1817
mod module_mod_with_functions {
1918
#[pymodule_export]
@@ -27,7 +26,6 @@ fn test_module_append_to_inittab() {
2726

2827
append_to_inittab!(module_fn_with_functions);
2928

30-
#[cfg(feature = "experimental-declarative-modules")]
3129
append_to_inittab!(module_mod_with_functions);
3230

3331
Python::with_gil(|py| {
@@ -43,7 +41,6 @@ assert module_fn_with_functions.foo() == 123
4341
.unwrap();
4442
});
4543

46-
#[cfg(feature = "experimental-declarative-modules")]
4744
Python::with_gil(|py| {
4845
py.run_bound(
4946
r#"

tests/test_compile_error.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,9 @@ fn test_compile_errors() {
5252
t.compile_fail("tests/ui/not_send2.rs");
5353
t.compile_fail("tests/ui/get_set_all.rs");
5454
t.compile_fail("tests/ui/traverse.rs");
55-
#[cfg(feature = "experimental-declarative-modules")]
5655
t.compile_fail("tests/ui/invalid_pymodule_in_root.rs");
57-
#[cfg(feature = "experimental-declarative-modules")]
5856
t.compile_fail("tests/ui/invalid_pymodule_glob.rs");
59-
#[cfg(feature = "experimental-declarative-modules")]
6057
t.compile_fail("tests/ui/invalid_pymodule_trait.rs");
61-
#[cfg(feature = "experimental-declarative-modules")]
6258
t.compile_fail("tests/ui/invalid_pymodule_two_pymodule_init.rs");
6359
#[cfg(feature = "experimental-async")]
6460
#[cfg(any(not(Py_LIMITED_API), Py_3_10))] // to avoid PyFunctionArgument for &str

tests/test_declarative_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg(feature = "experimental-declarative-modules")]
1+
#![cfg(feature = "macros")]
22

33
use pyo3::create_exception;
44
use pyo3::exceptions::PyException;

tests/ui/pymodule_missing_docs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub fn python_module(_m: &Bound<'_, PyModule>) -> PyResult<()> {
99
Ok(())
1010
}
1111

12-
#[cfg(feature = "experimental-declarative-modules")]
1312
/// Some module documentation
1413
#[pymodule]
1514
pub mod declarative_python_module {}

0 commit comments

Comments
 (0)