Scope macro imports more tightly (#4088)
This commit is contained in:
parent
5d2f5b5702
commit
f5fee94afc
|
@ -382,10 +382,7 @@ fn module_initialization(options: PyModuleOptions, ident: &syn::Ident) -> TokenS
|
|||
fn process_functions_in_module(options: &PyModuleOptions, func: &mut syn::ItemFn) -> Result<()> {
|
||||
let ctx = &Ctx::new(&options.krate);
|
||||
let Ctx { pyo3_path } = ctx;
|
||||
let mut stmts: Vec<syn::Stmt> = vec![syn::parse_quote!(
|
||||
#[allow(unknown_lints, unused_imports, redundant_imports)]
|
||||
use #pyo3_path::{PyNativeType, types::PyModuleMethods};
|
||||
)];
|
||||
let mut stmts: Vec<syn::Stmt> = Vec::new();
|
||||
|
||||
for mut stmt in func.block.stmts.drain(..) {
|
||||
if let syn::Stmt::Item(Item::Fn(func)) = &mut stmt {
|
||||
|
@ -395,7 +392,11 @@ fn process_functions_in_module(options: &PyModuleOptions, func: &mut syn::ItemFn
|
|||
let name = &func.sig.ident;
|
||||
let statements: Vec<syn::Stmt> = syn::parse_quote! {
|
||||
#wrapped_function
|
||||
{
|
||||
#[allow(unknown_lints, unused_imports, redundant_imports)]
|
||||
use #pyo3_path::{PyNativeType, types::PyModuleMethods};
|
||||
#module_name.as_borrowed().add_function(#pyo3_path::wrap_pyfunction!(#name, #module_name.as_borrowed())?)?;
|
||||
}
|
||||
};
|
||||
stmts.extend(statements);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
use pyo3::{
|
||||
pyclass, pyfunction, pymodule, types::PyModule, wrap_pyfunction_bound, Bound, PyResult,
|
||||
pyclass, pyfunction, pymodule,
|
||||
types::{PyModule, PyModuleMethods},
|
||||
wrap_pyfunction_bound, Bound, PyResult,
|
||||
};
|
||||
|
||||
#[pymodule]
|
||||
|
|
|
@ -30,7 +30,10 @@ fn basic_module_bound(m: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyRes
|
|||
42
|
||||
}
|
||||
|
||||
m.add_function(pyo3::wrap_pyfunction_bound!(basic_function, m)?)?;
|
||||
pyo3::types::PyModuleMethods::add_function(
|
||||
m,
|
||||
pyo3::wrap_pyfunction_bound!(basic_function, m)?,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue