pyo3_path, part 3: move test_hygiene into lib crate
This removes the crate-root `pyo3` item to ensure that our selected pyo3_path needs to be taken into account.
This commit is contained in:
parent
e4f608f605
commit
681217d8d9
|
@ -360,6 +360,11 @@ pub use pyo3_macros::{pyclass, pyfunction, pymethods, pymodule, pyproto, FromPyO
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
||||||
|
/// Test macro hygiene - this is in the crate since we won't have
|
||||||
|
/// `pyo3` available in the crate root.
|
||||||
|
#[cfg(all(test, feature = "macros"))]
|
||||||
|
mod test_hygiene;
|
||||||
|
|
||||||
/// Test readme and user guide
|
/// Test readme and user guide
|
||||||
#[cfg(doctest)]
|
#[cfg(doctest)]
|
||||||
pub mod doc_test {
|
pub mod doc_test {
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
#![no_implicit_prelude]
|
||||||
|
|
||||||
|
#[derive(crate::FromPyObject)]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
|
struct Derive1(i32); // newtype case
|
||||||
|
|
||||||
|
#[derive(crate::FromPyObject)]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
struct Derive2(i32, i32); // tuple case
|
||||||
|
|
||||||
|
#[derive(crate::FromPyObject)]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
struct Derive3 {
|
||||||
|
f: i32,
|
||||||
|
g: i32,
|
||||||
|
} // struct case
|
||||||
|
|
||||||
|
#[derive(crate::FromPyObject)]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
enum Derive4 {
|
||||||
|
A(i32),
|
||||||
|
B { f: i32 },
|
||||||
|
} // enum case
|
||||||
|
|
||||||
|
crate::create_exception!(mymodule, CustomError, crate::exceptions::PyException);
|
||||||
|
crate::import_exception!(socket, gaierror);
|
|
@ -0,0 +1,5 @@
|
||||||
|
mod misc;
|
||||||
|
mod pyclass;
|
||||||
|
mod pyfunction;
|
||||||
|
mod pymethods;
|
||||||
|
mod pymodule;
|
|
@ -1,27 +1,30 @@
|
||||||
#![no_implicit_prelude]
|
#![no_implicit_prelude]
|
||||||
#![allow(unused_variables)]
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
#[::pyo3::pyclass]
|
#[crate::pyclass]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
#[derive(::std::clone::Clone)]
|
#[derive(::std::clone::Clone)]
|
||||||
pub struct Foo;
|
pub struct Foo;
|
||||||
|
|
||||||
#[::pyo3::pyclass]
|
#[crate::pyclass]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
pub struct Foo2;
|
pub struct Foo2;
|
||||||
|
|
||||||
#[::pyo3::pyclass(
|
#[crate::pyclass(
|
||||||
name = "ActuallyBar",
|
name = "ActuallyBar",
|
||||||
freelist = 8,
|
freelist = 8,
|
||||||
weakref,
|
weakref,
|
||||||
unsendable,
|
unsendable,
|
||||||
subclass,
|
subclass,
|
||||||
extends = ::pyo3::types::PyAny,
|
extends = crate::types::PyAny,
|
||||||
module = "Spam"
|
module = "Spam"
|
||||||
)]
|
)]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
pub struct Bar {
|
pub struct Bar {
|
||||||
#[pyo3(get, set)]
|
#[pyo3(get, set)]
|
||||||
a: u8,
|
a: u8,
|
||||||
#[pyo3(get, set)]
|
#[pyo3(get, set)]
|
||||||
b: Foo,
|
b: Foo,
|
||||||
#[pyo3(get, set)]
|
#[pyo3(get, set)]
|
||||||
c: ::std::option::Option<::pyo3::Py<Foo2>>,
|
c: ::std::option::Option<crate::Py<Foo2>>,
|
||||||
}
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
#![no_implicit_prelude]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
|
#[crate::pyfunction]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
|
fn do_something(x: i32) -> crate::PyResult<i32> {
|
||||||
|
::std::result::Result::Ok(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn invoke_wrap_pyfunction() {
|
||||||
|
crate::Python::with_gil(|py| {
|
||||||
|
let func = crate::wrap_pyfunction!(do_something)(py).unwrap();
|
||||||
|
crate::py_run!(py, func, r#"func(5)"#);
|
||||||
|
});
|
||||||
|
}
|
|
@ -1,13 +1,16 @@
|
||||||
#![no_implicit_prelude]
|
#![no_implicit_prelude]
|
||||||
#![allow(unused_variables)]
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
#[::pyo3::pyclass]
|
#[crate::pyclass]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
pub struct Dummy;
|
pub struct Dummy;
|
||||||
|
|
||||||
#[::pyo3::pyclass]
|
#[crate::pyclass]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
pub struct DummyIter;
|
pub struct DummyIter;
|
||||||
|
|
||||||
#[::pyo3::pymethods]
|
#[crate::pymethods]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
impl Dummy {
|
impl Dummy {
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// Basic customization
|
// Basic customization
|
||||||
|
@ -20,8 +23,8 @@ impl Dummy {
|
||||||
"Dummy"
|
"Dummy"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __bytes__<'py>(&self, py: ::pyo3::Python<'py>) -> &'py ::pyo3::types::PyBytes {
|
fn __bytes__<'py>(&self, py: crate::Python<'py>) -> &'py crate::types::PyBytes {
|
||||||
::pyo3::types::PyBytes::new(py, &[0])
|
crate::types::PyBytes::new(py, &[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __format__(&self, format_spec: ::std::string::String) -> ::std::string::String {
|
fn __format__(&self, format_spec: ::std::string::String) -> ::std::string::String {
|
||||||
|
@ -60,11 +63,11 @@ impl Dummy {
|
||||||
// Customizing attribute access
|
// Customizing attribute access
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
|
||||||
fn __getattr__(&self, name: ::std::string::String) -> &::pyo3::PyAny {
|
fn __getattr__(&self, name: ::std::string::String) -> &crate::PyAny {
|
||||||
::std::panic!("unimplemented isn't hygienic before 1.50")
|
::std::panic!("unimplemented isn't hygienic before 1.50")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __getattribute__(&self, name: ::std::string::String) -> &::pyo3::PyAny {
|
fn __getattribute__(&self, name: ::std::string::String) -> &crate::PyAny {
|
||||||
::std::panic!("unimplemented isn't hygienic before 1.50")
|
::std::panic!("unimplemented isn't hygienic before 1.50")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +75,8 @@ impl Dummy {
|
||||||
|
|
||||||
fn __delattr__(&mut self, name: ::std::string::String) {}
|
fn __delattr__(&mut self, name: ::std::string::String) {}
|
||||||
|
|
||||||
fn __dir__<'py>(&self, py: ::pyo3::Python<'py>) -> &'py ::pyo3::types::PyList {
|
fn __dir__<'py>(&self, py: crate::Python<'py>) -> &'py crate::types::PyList {
|
||||||
::pyo3::types::PyList::new(py, ::std::vec![0_u8])
|
crate::types::PyList::new(py, ::std::vec![0_u8])
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
@ -82,17 +85,17 @@ impl Dummy {
|
||||||
|
|
||||||
fn __get__(
|
fn __get__(
|
||||||
&self,
|
&self,
|
||||||
instance: &::pyo3::PyAny,
|
instance: &crate::PyAny,
|
||||||
owner: &::pyo3::PyAny,
|
owner: &crate::PyAny,
|
||||||
) -> ::pyo3::PyResult<&::pyo3::PyAny> {
|
) -> crate::PyResult<&crate::PyAny> {
|
||||||
::std::panic!("unimplemented isn't hygienic before 1.50")
|
::std::panic!("unimplemented isn't hygienic before 1.50")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __set__(&self, instance: &::pyo3::PyAny, owner: &::pyo3::PyAny) {}
|
fn __set__(&self, instance: &crate::PyAny, owner: &crate::PyAny) {}
|
||||||
|
|
||||||
fn __delete__(&self, instance: &::pyo3::PyAny) {}
|
fn __delete__(&self, instance: &crate::PyAny) {}
|
||||||
|
|
||||||
fn __set_name__(&self, owner: &::pyo3::PyAny, name: &::pyo3::PyAny) {}
|
fn __set_name__(&self, owner: &crate::PyAny, name: &crate::PyAny) {}
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// Implementing Descriptors
|
// Implementing Descriptors
|
||||||
|
@ -102,24 +105,24 @@ impl Dummy {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __getitem__(&self, key: u32) -> ::pyo3::PyResult<u32> {
|
fn __getitem__(&self, key: u32) -> crate::PyResult<u32> {
|
||||||
::std::result::Result::Err(::pyo3::exceptions::PyKeyError::new_err("boo"))
|
::std::result::Result::Err(crate::exceptions::PyKeyError::new_err("boo"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __setitem__(&self, key: u32, value: u32) {}
|
fn __setitem__(&self, key: u32, value: u32) {}
|
||||||
|
|
||||||
fn __delitem__(&self, key: u32) {}
|
fn __delitem__(&self, key: u32) {}
|
||||||
|
|
||||||
fn __iter__(_: ::pyo3::pycell::PyRef<Self>, py: ::pyo3::Python) -> ::pyo3::Py<DummyIter> {
|
fn __iter__(_: crate::pycell::PyRef<Self>, py: crate::Python) -> crate::Py<DummyIter> {
|
||||||
::pyo3::Py::new(py, DummyIter {}).unwrap()
|
crate::Py::new(py, DummyIter {}).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __next__(&mut self) -> ::std::option::Option<()> {
|
fn __next__(&mut self) -> ::std::option::Option<()> {
|
||||||
::std::option::Option::None
|
::std::option::Option::None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __reversed__(slf: ::pyo3::pycell::PyRef<Self>, py: ::pyo3::Python) -> ::pyo3::Py<DummyIter> {
|
fn __reversed__(slf: crate::pycell::PyRef<Self>, py: crate::Python) -> crate::Py<DummyIter> {
|
||||||
::pyo3::Py::new(py, DummyIter {}).unwrap()
|
crate::Py::new(py, DummyIter {}).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __contains__(&self, item: u32) -> bool {
|
fn __contains__(&self, item: u32) -> bool {
|
||||||
|
@ -142,12 +145,12 @@ impl Dummy {
|
||||||
Dummy {}
|
Dummy {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __truediv__(&self, _other: &Self) -> ::pyo3::PyResult<()> {
|
fn __truediv__(&self, _other: &Self) -> crate::PyResult<()> {
|
||||||
::std::result::Result::Err(::pyo3::exceptions::PyZeroDivisionError::new_err("boo"))
|
::std::result::Result::Err(crate::exceptions::PyZeroDivisionError::new_err("boo"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __floordiv__(&self, _other: &Self) -> ::pyo3::PyResult<()> {
|
fn __floordiv__(&self, _other: &Self) -> crate::PyResult<()> {
|
||||||
::std::result::Result::Err(::pyo3::exceptions::PyZeroDivisionError::new_err("boo"))
|
::std::result::Result::Err(crate::exceptions::PyZeroDivisionError::new_err("boo"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __mod__(&self, _other: &Self) -> u32 {
|
fn __mod__(&self, _other: &Self) -> u32 {
|
||||||
|
@ -194,12 +197,12 @@ impl Dummy {
|
||||||
Dummy {}
|
Dummy {}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __rtruediv__(&self, _other: &Self) -> ::pyo3::PyResult<()> {
|
fn __rtruediv__(&self, _other: &Self) -> crate::PyResult<()> {
|
||||||
::std::result::Result::Err(::pyo3::exceptions::PyZeroDivisionError::new_err("boo"))
|
::std::result::Result::Err(crate::exceptions::PyZeroDivisionError::new_err("boo"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __rfloordiv__(&self, _other: &Self) -> ::pyo3::PyResult<()> {
|
fn __rfloordiv__(&self, _other: &Self) -> crate::PyResult<()> {
|
||||||
::std::result::Result::Err(::pyo3::exceptions::PyZeroDivisionError::new_err("boo"))
|
::std::result::Result::Err(crate::exceptions::PyZeroDivisionError::new_err("boo"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __rmod__(&self, _other: &Self) -> u32 {
|
fn __rmod__(&self, _other: &Self) -> u32 {
|
||||||
|
@ -258,24 +261,24 @@ impl Dummy {
|
||||||
|
|
||||||
fn __ior__(&mut self, other: &Self) {}
|
fn __ior__(&mut self, other: &Self) {}
|
||||||
|
|
||||||
fn __neg__(slf: ::pyo3::pycell::PyRef<Self>) -> ::pyo3::pycell::PyRef<Self> {
|
fn __neg__(slf: crate::pycell::PyRef<Self>) -> crate::pycell::PyRef<Self> {
|
||||||
slf
|
slf
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __pos__(slf: ::pyo3::pycell::PyRef<Self>) -> ::pyo3::pycell::PyRef<Self> {
|
fn __pos__(slf: crate::pycell::PyRef<Self>) -> crate::pycell::PyRef<Self> {
|
||||||
slf
|
slf
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __abs__(slf: ::pyo3::pycell::PyRef<Self>) -> ::pyo3::pycell::PyRef<Self> {
|
fn __abs__(slf: crate::pycell::PyRef<Self>) -> crate::pycell::PyRef<Self> {
|
||||||
slf
|
slf
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __invert__(slf: ::pyo3::pycell::PyRef<Self>) -> ::pyo3::pycell::PyRef<Self> {
|
fn __invert__(slf: crate::pycell::PyRef<Self>) -> crate::pycell::PyRef<Self> {
|
||||||
slf
|
slf
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __complex__<'py>(&self, py: ::pyo3::Python<'py>) -> &'py ::pyo3::types::PyComplex {
|
fn __complex__<'py>(&self, py: crate::Python<'py>) -> &'py crate::types::PyComplex {
|
||||||
::pyo3::types::PyComplex::from_doubles(py, 0.0, 0.0)
|
crate::types::PyComplex::from_doubles(py, 0.0, 0.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __int__(&self) -> u32 {
|
fn __int__(&self) -> u32 {
|
||||||
|
@ -314,9 +317,9 @@ impl Dummy {
|
||||||
|
|
||||||
fn __exit__(
|
fn __exit__(
|
||||||
&mut self,
|
&mut self,
|
||||||
exc_type: &::pyo3::PyAny,
|
exc_type: &crate::PyAny,
|
||||||
exc_value: &::pyo3::PyAny,
|
exc_value: &crate::PyAny,
|
||||||
traceback: &::pyo3::PyAny,
|
traceback: &crate::PyAny,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +327,7 @@ impl Dummy {
|
||||||
// Awaitable Objects
|
// Awaitable Objects
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
|
||||||
fn __await__(slf: ::pyo3::pycell::PyRef<Self>) -> ::pyo3::pycell::PyRef<Self> {
|
fn __await__(slf: crate::pycell::PyRef<Self>) -> crate::pycell::PyRef<Self> {
|
||||||
slf
|
slf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,8 +336,8 @@ impl Dummy {
|
||||||
// Asynchronous Iterators
|
// Asynchronous Iterators
|
||||||
//////////////////////
|
//////////////////////
|
||||||
|
|
||||||
fn __aiter__(slf: ::pyo3::pycell::PyRef<Self>, py: ::pyo3::Python) -> ::pyo3::Py<DummyIter> {
|
fn __aiter__(slf: crate::pycell::PyRef<Self>, py: crate::Python) -> crate::Py<DummyIter> {
|
||||||
::pyo3::Py::new(py, DummyIter {}).unwrap()
|
crate::Py::new(py, DummyIter {}).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn __anext__(&mut self) -> ::std::option::Option<()> {
|
fn __anext__(&mut self) -> ::std::option::Option<()> {
|
||||||
|
@ -349,9 +352,9 @@ impl Dummy {
|
||||||
|
|
||||||
fn __aexit__(
|
fn __aexit__(
|
||||||
&mut self,
|
&mut self,
|
||||||
exc_type: &::pyo3::PyAny,
|
exc_type: &crate::PyAny,
|
||||||
exc_value: &::pyo3::PyAny,
|
exc_value: &crate::PyAny,
|
||||||
traceback: &::pyo3::PyAny,
|
traceback: &crate::PyAny,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,13 +365,13 @@ impl Dummy {
|
||||||
#[staticmethod]
|
#[staticmethod]
|
||||||
fn staticmethod() {}
|
fn staticmethod() {}
|
||||||
#[classmethod]
|
#[classmethod]
|
||||||
fn clsmethod(_: &::pyo3::types::PyType) {}
|
fn clsmethod(_: &crate::types::PyType) {}
|
||||||
#[args(args = "*", kwds = "**")]
|
#[args(args = "*", kwds = "**")]
|
||||||
fn __call__(
|
fn __call__(
|
||||||
&self,
|
&self,
|
||||||
_args: &::pyo3::types::PyTuple,
|
_args: &crate::types::PyTuple,
|
||||||
_kwds: ::std::option::Option<&::pyo3::types::PyDict>,
|
_kwds: ::std::option::Option<&crate::types::PyDict>,
|
||||||
) -> ::pyo3::PyResult<i32> {
|
) -> crate::PyResult<i32> {
|
||||||
::std::panic!("unimplemented isn't hygienic before 1.50")
|
::std::panic!("unimplemented isn't hygienic before 1.50")
|
||||||
}
|
}
|
||||||
#[new]
|
#[new]
|
||||||
|
@ -391,8 +394,8 @@ impl Dummy {
|
||||||
fn __richcmp__(
|
fn __richcmp__(
|
||||||
&self,
|
&self,
|
||||||
other: &Self,
|
other: &Self,
|
||||||
op: ::pyo3::class::basic::CompareOp,
|
op: crate::class::basic::CompareOp,
|
||||||
) -> ::pyo3::PyResult<bool> {
|
) -> crate::PyResult<bool> {
|
||||||
::std::result::Result::Ok(false)
|
::std::result::Result::Ok(false)
|
||||||
}
|
}
|
||||||
// PyGcProtocol
|
// PyGcProtocol
|
|
@ -0,0 +1,23 @@
|
||||||
|
#![no_implicit_prelude]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
|
||||||
|
#[crate::pyfunction]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
|
fn do_something(x: i32) -> crate::PyResult<i32> {
|
||||||
|
::std::result::Result::Ok(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[crate::pymodule]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
|
fn foo(_py: crate::Python, _m: &crate::types::PyModule) -> crate::PyResult<()> {
|
||||||
|
::std::result::Result::Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[crate::pymodule]
|
||||||
|
#[pyo3(pyo3_path = "crate")]
|
||||||
|
fn my_module(_py: crate::Python, m: &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(())
|
||||||
|
}
|
|
@ -1,25 +0,0 @@
|
||||||
#![no_implicit_prelude]
|
|
||||||
|
|
||||||
#[derive(::pyo3::FromPyObject)]
|
|
||||||
struct Derive1(i32); // newtype case
|
|
||||||
|
|
||||||
#[derive(::pyo3::FromPyObject)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
struct Derive2(i32, i32); // tuple case
|
|
||||||
|
|
||||||
#[derive(::pyo3::FromPyObject)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
struct Derive3 {
|
|
||||||
f: i32,
|
|
||||||
g: i32,
|
|
||||||
} // struct case
|
|
||||||
|
|
||||||
#[derive(::pyo3::FromPyObject)]
|
|
||||||
#[allow(dead_code)]
|
|
||||||
enum Derive4 {
|
|
||||||
A(i32),
|
|
||||||
B { f: i32 },
|
|
||||||
} // enum case
|
|
||||||
|
|
||||||
::pyo3::create_exception!(mymodule, CustomError, ::pyo3::exceptions::PyException);
|
|
||||||
::pyo3::import_exception!(socket, gaierror);
|
|
|
@ -1,15 +0,0 @@
|
||||||
#![no_implicit_prelude]
|
|
||||||
#![allow(unused_variables)]
|
|
||||||
|
|
||||||
#[::pyo3::pyfunction]
|
|
||||||
fn do_something(x: i32) -> ::pyo3::PyResult<i32> {
|
|
||||||
::std::result::Result::Ok(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn invoke_wrap_pyfunction() {
|
|
||||||
::pyo3::Python::with_gil(|py| {
|
|
||||||
let func = ::pyo3::wrap_pyfunction!(do_something)(py).unwrap();
|
|
||||||
::pyo3::py_run!(py, func, r#"func(5)"#);
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -1,20 +0,0 @@
|
||||||
#![no_implicit_prelude]
|
|
||||||
#![allow(unused_variables)]
|
|
||||||
|
|
||||||
#[::pyo3::pyfunction]
|
|
||||||
fn do_something(x: i32) -> ::pyo3::PyResult<i32> {
|
|
||||||
::std::result::Result::Ok(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[::pyo3::pymodule]
|
|
||||||
fn foo(_py: ::pyo3::Python, _m: &::pyo3::types::PyModule) -> ::pyo3::PyResult<()> {
|
|
||||||
::std::result::Result::Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[::pyo3::pymodule]
|
|
||||||
fn my_module(_py: ::pyo3::Python, m: &::pyo3::types::PyModule) -> ::pyo3::PyResult<()> {
|
|
||||||
m.add_function(::pyo3::wrap_pyfunction!(do_something, m)?)?;
|
|
||||||
m.add_wrapped(::pyo3::wrap_pymodule!(foo))?;
|
|
||||||
|
|
||||||
::std::result::Result::Ok(())
|
|
||||||
}
|
|
|
@ -1,58 +0,0 @@
|
||||||
#![no_implicit_prelude]
|
|
||||||
#![allow(unused_variables)]
|
|
||||||
|
|
||||||
#[::pyo3::pyclass]
|
|
||||||
#[derive(::std::clone::Clone)]
|
|
||||||
pub struct Foo;
|
|
||||||
|
|
||||||
#[::pyo3::pyclass]
|
|
||||||
pub struct Foo2;
|
|
||||||
|
|
||||||
#[::pyo3::pyclass(
|
|
||||||
name = "ActuallyBar",
|
|
||||||
freelist = 8,
|
|
||||||
weakref,
|
|
||||||
unsendable,
|
|
||||||
gc,
|
|
||||||
subclass,
|
|
||||||
extends = ::pyo3::types::PyAny,
|
|
||||||
module = "Spam"
|
|
||||||
)]
|
|
||||||
pub struct Bar {
|
|
||||||
#[pyo3(get, set)]
|
|
||||||
a: u8,
|
|
||||||
#[pyo3(get, set)]
|
|
||||||
b: Foo,
|
|
||||||
#[pyo3(get, set)]
|
|
||||||
c: ::std::option::Option<::pyo3::Py<Foo2>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[::pyo3::pyproto]
|
|
||||||
impl ::pyo3::class::gc::PyGCProtocol for Bar {
|
|
||||||
fn __traverse__(
|
|
||||||
&self,
|
|
||||||
visit: ::pyo3::class::gc::PyVisit,
|
|
||||||
) -> ::std::result::Result<(), ::pyo3::class::gc::PyTraverseError> {
|
|
||||||
if let ::std::option::Option::Some(obj) = &self.c {
|
|
||||||
visit.call(obj)?
|
|
||||||
}
|
|
||||||
::std::result::Result::Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn __clear__(&mut self) {
|
|
||||||
self.c = ::std::option::Option::None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(not(Py_LIMITED_API))]
|
|
||||||
#[::pyo3::pyproto]
|
|
||||||
impl ::pyo3::class::PyBufferProtocol for Bar {
|
|
||||||
fn bf_getbuffer(
|
|
||||||
_s: ::pyo3::PyRefMut<Self>,
|
|
||||||
_v: *mut ::pyo3::ffi::Py_buffer,
|
|
||||||
_f: ::std::os::raw::c_int,
|
|
||||||
) -> ::pyo3::PyResult<()> {
|
|
||||||
::std::panic!("unimplemented isn't hygienic before 1.50")
|
|
||||||
}
|
|
||||||
fn bf_releasebuffer(_s: ::pyo3::PyRefMut<Self>, _v: *mut ::pyo3::ffi::Py_buffer) {}
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
#![cfg(feature = "macros")]
|
|
||||||
|
|
||||||
mod hygiene {
|
|
||||||
mod misc;
|
|
||||||
mod pyclass;
|
|
||||||
mod pyfunction;
|
|
||||||
mod pymethods;
|
|
||||||
mod pymodule;
|
|
||||||
mod pyproto;
|
|
||||||
}
|
|
Loading…
Reference in New Issue