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<()> {
|
fn process_functions_in_module(options: &PyModuleOptions, func: &mut syn::ItemFn) -> Result<()> {
|
||||||
let ctx = &Ctx::new(&options.krate);
|
let ctx = &Ctx::new(&options.krate);
|
||||||
let Ctx { pyo3_path } = ctx;
|
let Ctx { pyo3_path } = ctx;
|
||||||
let mut stmts: Vec<syn::Stmt> = vec![syn::parse_quote!(
|
let mut stmts: Vec<syn::Stmt> = Vec::new();
|
||||||
#[allow(unknown_lints, unused_imports, redundant_imports)]
|
|
||||||
use #pyo3_path::{PyNativeType, types::PyModuleMethods};
|
|
||||||
)];
|
|
||||||
|
|
||||||
for mut stmt in func.block.stmts.drain(..) {
|
for mut stmt in func.block.stmts.drain(..) {
|
||||||
if let syn::Stmt::Item(Item::Fn(func)) = &mut stmt {
|
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 name = &func.sig.ident;
|
||||||
let statements: Vec<syn::Stmt> = syn::parse_quote! {
|
let statements: Vec<syn::Stmt> = syn::parse_quote! {
|
||||||
#wrapped_function
|
#wrapped_function
|
||||||
#module_name.as_borrowed().add_function(#pyo3_path::wrap_pyfunction!(#name, #module_name.as_borrowed())?)?;
|
{
|
||||||
|
#[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);
|
stmts.extend(statements);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use pyo3::{
|
use pyo3::{
|
||||||
pyclass, pyfunction, pymodule, types::PyModule, wrap_pyfunction_bound, Bound, PyResult,
|
pyclass, pyfunction, pymodule,
|
||||||
|
types::{PyModule, PyModuleMethods},
|
||||||
|
wrap_pyfunction_bound, Bound, PyResult,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[pymodule]
|
#[pymodule]
|
||||||
|
|
|
@ -30,7 +30,10 @@ fn basic_module_bound(m: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyRes
|
||||||
42
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue