Skip to content

Commit

Permalink
Simplify _PYO3_DEF in #[pymodule] macro by no longer generating a…
Browse files Browse the repository at this point in the history
… `const fn`

Instead we can just declare a `const`. This may help with coverage issues, refs PyO3#4286.
  • Loading branch information
alex committed Jun 27, 2024
1 parent 2e2d440 commit ba6d6dc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pyo3-macros-backend/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ pub fn pymodule_module_impl(mut module: syn::ItemMod) -> Result<TokenStream> {

#[allow(unknown_lints, non_local_definitions)]
impl MakeDef {
const fn make_def() -> #pyo3_path::impl_::pymodule::ModuleDef {
const _DEF: #pyo3_path::impl_::pymodule::ModuleDef = {
use #pyo3_path::impl_::pymodule as impl_;
const INITIALIZER: impl_::ModuleInitializer = impl_::ModuleInitializer(__pyo3_pymodule);
unsafe {
Expand All @@ -306,7 +306,7 @@ pub fn pymodule_module_impl(mut module: syn::ItemMod) -> Result<TokenStream> {
INITIALIZER
)
}
}
};
}

fn __pyo3_pymodule(module: &#pyo3_path::Bound<'_, #pyo3_path::types::PyModule>) -> #pyo3_path::PyResult<()> {
Expand Down Expand Up @@ -382,7 +382,7 @@ pub fn pymodule_function_impl(mut function: syn::ItemFn) -> Result<TokenStream>
// inside a function body)
#[allow(unknown_lints, non_local_definitions)]
impl #ident::MakeDef {
const fn make_def() -> #pyo3_path::impl_::pymodule::ModuleDef {
const _DEF: #pyo3_path::impl_::pymodule::ModuleDef = {
fn __pyo3_pymodule(module: &#pyo3_path::Bound<'_, #pyo3_path::types::PyModule>) -> #pyo3_path::PyResult<()> {
#ident(#(#module_args),*)
}
Expand All @@ -395,7 +395,7 @@ pub fn pymodule_function_impl(mut function: syn::ItemFn) -> Result<TokenStream>
INITIALIZER
)
}
}
};
}
})
}
Expand All @@ -412,7 +412,7 @@ fn module_initialization(name: &syn::Ident, ctx: &Ctx) -> TokenStream {

pub(super) struct MakeDef;
#[doc(hidden)]
pub static _PYO3_DEF: #pyo3_path::impl_::pymodule::ModuleDef = MakeDef::make_def();
pub static _PYO3_DEF: #pyo3_path::impl_::pymodule::ModuleDef = MakeDef::_DEF;

/// This autogenerated function is called by the python interpreter when importing
/// the module.
Expand Down

0 comments on commit ba6d6dc

Please sign in to comment.