Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
d33b319
commit b58826e
Showing
12 changed files
with
139 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod misc; | ||
mod pyclass; | ||
mod pyfunction; | ||
mod pymethods; | ||
mod pymodule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
#![no_implicit_prelude] | ||
#![allow(unused_variables)] | ||
|
||
#[::pyo3::pyclass] | ||
#[crate::pyclass] | ||
#[pyo3(pyo3_path = "crate")] | ||
#[derive(::std::clone::Clone)] | ||
pub struct Foo; | ||
|
||
#[::pyo3::pyclass] | ||
#[crate::pyclass] | ||
#[pyo3(pyo3_path = "crate")] | ||
pub struct Foo2; | ||
|
||
#[::pyo3::pyclass( | ||
#[crate::pyclass( | ||
name = "ActuallyBar", | ||
freelist = 8, | ||
weakref, | ||
unsendable, | ||
subclass, | ||
extends = ::pyo3::types::PyAny, | ||
extends = crate::types::PyAny, | ||
module = "Spam" | ||
)] | ||
#[pyo3(pyo3_path = "crate")] | ||
pub struct Bar { | ||
#[pyo3(get, set)] | ||
a: u8, | ||
#[pyo3(get, set)] | ||
b: Foo, | ||
#[pyo3(get, set)] | ||
c: ::std::option::Option<::pyo3::Py<Foo2>>, | ||
c: ::std::option::Option<crate::Py<Foo2>>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)"#); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(()) | ||
} |
Oops, something went wrong.