clean up hygiene tests (#4328)
This commit is contained in:
parent
8652ac8e1c
commit
97d60e869b
|
@ -0,0 +1 @@
|
||||||
|
Fix compile failure in declarative `#[pymodule]` under presence of `#![no_implicit_prelude]`.
|
|
@ -373,7 +373,7 @@ pub fn pymodule_module_impl(
|
||||||
#module_items::_PYO3_DEF.add_to_module(module)?;
|
#module_items::_PYO3_DEF.add_to_module(module)?;
|
||||||
)*
|
)*
|
||||||
#pymodule_init
|
#pymodule_init
|
||||||
Ok(())
|
::std::result::Result::Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
#![no_implicit_prelude]
|
#[derive(crate::FromPyObject)]
|
||||||
|
#[pyo3(crate = "crate")]
|
||||||
|
struct Derive1(i32); // newtype case
|
||||||
|
|
||||||
#[derive(crate::FromPyObject)]
|
#[derive(crate::FromPyObject)]
|
||||||
#[pyo3(crate = "crate")]
|
#[pyo3(crate = "crate")]
|
||||||
struct Derive1(#[allow(dead_code)] i32); // newtype case
|
|
||||||
|
|
||||||
#[derive(crate::FromPyObject)]
|
|
||||||
#[pyo3(crate = "crate")]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
struct Derive2(i32, i32); // tuple case
|
struct Derive2(i32, i32); // tuple case
|
||||||
|
|
||||||
#[derive(crate::FromPyObject)]
|
#[derive(crate::FromPyObject)]
|
||||||
#[pyo3(crate = "crate")]
|
#[pyo3(crate = "crate")]
|
||||||
#[allow(dead_code)]
|
|
||||||
struct Derive3 {
|
struct Derive3 {
|
||||||
f: i32,
|
f: i32,
|
||||||
#[pyo3(item(42))]
|
#[pyo3(item(42))]
|
||||||
|
@ -20,7 +16,6 @@ struct Derive3 {
|
||||||
|
|
||||||
#[derive(crate::FromPyObject)]
|
#[derive(crate::FromPyObject)]
|
||||||
#[pyo3(crate = "crate")]
|
#[pyo3(crate = "crate")]
|
||||||
#[allow(dead_code)]
|
|
||||||
enum Derive4 {
|
enum Derive4 {
|
||||||
A(i32),
|
A(i32),
|
||||||
B { f: i32 },
|
B { f: i32 },
|
||||||
|
@ -29,23 +24,16 @@ enum Derive4 {
|
||||||
crate::create_exception!(mymodule, CustomError, crate::exceptions::PyException);
|
crate::create_exception!(mymodule, CustomError, crate::exceptions::PyException);
|
||||||
crate::import_exception!(socket, gaierror);
|
crate::import_exception!(socket, gaierror);
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
fn intern(py: crate::Python<'_>) {
|
fn intern(py: crate::Python<'_>) {
|
||||||
let _foo = crate::intern!(py, "foo");
|
let _foo = crate::intern!(py, "foo");
|
||||||
let _bar = crate::intern!(py, stringify!(bar));
|
let _bar = crate::intern!(py, stringify!(bar));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[cfg(not(PyPy))]
|
#[cfg(not(PyPy))]
|
||||||
fn append_to_inittab() {
|
fn append_to_inittab() {
|
||||||
#[crate::pymodule]
|
#[crate::pymodule]
|
||||||
#[pyo3(crate = "crate")]
|
#[pyo3(crate = "crate")]
|
||||||
#[allow(clippy::unnecessary_wraps)]
|
mod module_for_inittab {}
|
||||||
fn module_for_inittab(
|
|
||||||
_: crate::Python<'_>,
|
|
||||||
_: &crate::Bound<'_, crate::types::PyModule>,
|
|
||||||
) -> crate::PyResult<()> {
|
|
||||||
::std::result::Result::Ok(())
|
|
||||||
}
|
|
||||||
crate::append_to_inittab!(module_for_inittab);
|
crate::append_to_inittab!(module_for_inittab);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#![no_implicit_prelude]
|
||||||
|
#![allow(dead_code, unused_variables, clippy::unnecessary_wraps)]
|
||||||
|
|
||||||
// The modules in this test are used to check PyO3 macro expansion is hygienic. By locating the test
|
// The modules in this test are used to check PyO3 macro expansion is hygienic. By locating the test
|
||||||
// inside the crate the global `::pyo3` namespace is not available, so in combination with
|
// inside the crate the global `::pyo3` namespace is not available, so in combination with
|
||||||
// #[pyo3(crate = "crate")] this validates that all macro expansion respects the setting.
|
// #[pyo3(crate = "crate")] this validates that all macro expansion respects the setting.
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#![no_implicit_prelude]
|
|
||||||
#![allow(unused_variables)]
|
|
||||||
|
|
||||||
#[crate::pyclass]
|
#[crate::pyclass]
|
||||||
#[pyo3(crate = "crate")]
|
#[pyo3(crate = "crate")]
|
||||||
#[derive(::std::clone::Clone)]
|
#[derive(::std::clone::Clone)]
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#![no_implicit_prelude]
|
|
||||||
#![allow(unused_variables, clippy::unnecessary_wraps)]
|
|
||||||
|
|
||||||
#[crate::pyfunction]
|
#[crate::pyfunction]
|
||||||
#[pyo3(crate = "crate")]
|
#[pyo3(crate = "crate")]
|
||||||
fn do_something(x: i32) -> crate::PyResult<i32> {
|
fn do_something(x: i32) -> crate::PyResult<i32> {
|
||||||
|
@ -8,19 +5,9 @@ fn do_something(x: i32) -> crate::PyResult<i32> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "gil-refs")]
|
|
||||||
fn invoke_wrap_pyfunction() {
|
fn invoke_wrap_pyfunction() {
|
||||||
crate::Python::with_gil(|py| {
|
crate::Python::with_gil(|py| {
|
||||||
#[allow(deprecated)]
|
let func = crate::wrap_pyfunction!(do_something, py).unwrap();
|
||||||
let func = crate::wrap_pyfunction!(do_something)(py).unwrap();
|
|
||||||
crate::py_run!(py, func, r#"func(5)"#);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn invoke_wrap_pyfunction_bound() {
|
|
||||||
crate::Python::with_gil(|py| {
|
|
||||||
let func = crate::wrap_pyfunction_bound!(do_something, py).unwrap();
|
|
||||||
crate::py_run!(py, func, r#"func(5)"#);
|
crate::py_run!(py, func, r#"func(5)"#);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#![no_implicit_prelude]
|
|
||||||
#![allow(unused_variables, clippy::unnecessary_wraps)]
|
|
||||||
|
|
||||||
#[crate::pyclass]
|
#[crate::pyclass]
|
||||||
#[pyo3(crate = "crate")]
|
#[pyo3(crate = "crate")]
|
||||||
pub struct Dummy;
|
pub struct Dummy;
|
||||||
|
|
|
@ -1,51 +1,36 @@
|
||||||
#![no_implicit_prelude]
|
|
||||||
#![allow(unused_variables, clippy::unnecessary_wraps)]
|
|
||||||
|
|
||||||
#[crate::pyfunction]
|
#[crate::pyfunction]
|
||||||
#[pyo3(crate = "crate")]
|
#[pyo3(crate = "crate")]
|
||||||
fn do_something(x: i32) -> crate::PyResult<i32> {
|
fn do_something(x: i32) -> crate::PyResult<i32> {
|
||||||
::std::result::Result::Ok(x)
|
::std::result::Result::Ok(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gil-refs")]
|
|
||||||
#[allow(deprecated)]
|
|
||||||
#[crate::pymodule]
|
#[crate::pymodule]
|
||||||
#[pyo3(crate = "crate")]
|
#[pyo3(crate = "crate")]
|
||||||
fn foo(_py: crate::Python<'_>, _m: &crate::types::PyModule) -> crate::PyResult<()> {
|
fn foo(
|
||||||
::std::result::Result::Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[crate::pymodule]
|
|
||||||
#[pyo3(crate = "crate")]
|
|
||||||
fn foo_bound(
|
|
||||||
_py: crate::Python<'_>,
|
_py: crate::Python<'_>,
|
||||||
_m: &crate::Bound<'_, crate::types::PyModule>,
|
_m: &crate::Bound<'_, crate::types::PyModule>,
|
||||||
) -> crate::PyResult<()> {
|
) -> crate::PyResult<()> {
|
||||||
::std::result::Result::Ok(())
|
::std::result::Result::Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gil-refs")]
|
|
||||||
#[allow(deprecated)]
|
|
||||||
#[crate::pymodule]
|
#[crate::pymodule]
|
||||||
#[pyo3(crate = "crate")]
|
#[pyo3(crate = "crate")]
|
||||||
fn my_module(_py: crate::Python<'_>, m: &crate::types::PyModule) -> crate::PyResult<()> {
|
fn my_module(m: &crate::Bound<'_, crate::types::PyModule>) -> crate::PyResult<()> {
|
||||||
m.add_function(crate::wrap_pyfunction!(do_something, m)?)?;
|
|
||||||
m.add_wrapped(crate::wrap_pymodule!(foo))?;
|
|
||||||
|
|
||||||
::std::result::Result::Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[crate::pymodule]
|
|
||||||
#[pyo3(crate = "crate")]
|
|
||||||
fn my_module_bound(m: &crate::Bound<'_, crate::types::PyModule>) -> crate::PyResult<()> {
|
|
||||||
<crate::Bound<'_, crate::types::PyModule> as crate::types::PyModuleMethods>::add_function(
|
<crate::Bound<'_, crate::types::PyModule> as crate::types::PyModuleMethods>::add_function(
|
||||||
m,
|
m,
|
||||||
crate::wrap_pyfunction_bound!(do_something, m)?,
|
crate::wrap_pyfunction_bound!(do_something, m)?,
|
||||||
)?;
|
)?;
|
||||||
<crate::Bound<'_, crate::types::PyModule> as crate::types::PyModuleMethods>::add_wrapped(
|
<crate::Bound<'_, crate::types::PyModule> as crate::types::PyModuleMethods>::add_wrapped(
|
||||||
m,
|
m,
|
||||||
crate::wrap_pymodule!(foo_bound),
|
crate::wrap_pymodule!(foo),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
::std::result::Result::Ok(())
|
::std::result::Result::Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[crate::pymodule(submodule)]
|
||||||
|
#[pyo3(crate = "crate")]
|
||||||
|
mod my_module_declarative {
|
||||||
|
#[pymodule_export]
|
||||||
|
use super::{do_something, foo};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue