2021-04-17 21:22:06 +00:00
|
|
|
#![deny(deprecated)]
|
2024-03-15 10:25:27 +00:00
|
|
|
#![allow(dead_code)]
|
2021-04-17 21:22:06 +00:00
|
|
|
|
|
|
|
use pyo3::prelude::*;
|
2024-03-09 09:52:12 +00:00
|
|
|
use pyo3::types::{PyString, PyType};
|
2021-04-17 21:22:06 +00:00
|
|
|
|
2022-10-25 06:23:21 +00:00
|
|
|
#[pyclass]
|
|
|
|
struct MyClass;
|
2021-04-17 21:22:06 +00:00
|
|
|
|
2023-10-05 22:59:03 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[__new__]
|
|
|
|
fn new() -> Self {
|
|
|
|
Self
|
|
|
|
}
|
2024-03-09 09:52:12 +00:00
|
|
|
|
|
|
|
#[classmethod]
|
|
|
|
fn cls_method_gil_ref(_cls: &PyType) {}
|
|
|
|
|
|
|
|
#[classmethod]
|
|
|
|
fn cls_method_bound(_cls: &Bound<'_, PyType>) {}
|
|
|
|
|
|
|
|
fn method_gil_ref(_slf: &PyCell<Self>) {}
|
|
|
|
|
|
|
|
fn method_bound(_slf: &Bound<'_, Self>) {}
|
2023-10-05 22:59:03 +00:00
|
|
|
}
|
|
|
|
|
2023-06-13 07:19:43 +00:00
|
|
|
fn main() {}
|
2024-03-08 00:28:11 +00:00
|
|
|
|
2024-03-09 09:52:12 +00:00
|
|
|
#[pyfunction]
|
|
|
|
#[pyo3(pass_module)]
|
|
|
|
fn pyfunction_with_module<'py>(module: &Bound<'py, PyModule>) -> PyResult<Bound<'py, PyString>> {
|
|
|
|
module.name()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pyfunction]
|
|
|
|
#[pyo3(pass_module)]
|
|
|
|
fn pyfunction_with_module_gil_ref(module: &PyModule) -> PyResult<&str> {
|
|
|
|
module.name()
|
|
|
|
}
|
|
|
|
|
2024-03-08 00:28:11 +00:00
|
|
|
#[pyfunction]
|
|
|
|
fn double(x: usize) -> usize {
|
|
|
|
x * 2
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymodule]
|
|
|
|
fn module_gil_ref(m: &PyModule) -> PyResult<()> {
|
|
|
|
m.add_function(wrap_pyfunction!(double, m)?)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymodule]
|
|
|
|
fn module_gil_ref_with_explicit_py_arg(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
|
|
|
|
m.add_function(wrap_pyfunction!(double, m)?)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymodule]
|
|
|
|
fn module_bound(m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
|
|
m.add_function(wrap_pyfunction!(double, m)?)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymodule]
|
|
|
|
fn module_bound_with_explicit_py_arg(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
|
|
|
|
m.add_function(wrap_pyfunction!(double, m)?)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymodule]
|
|
|
|
fn module_bound_by_value(m: Bound<'_, PyModule>) -> PyResult<()> {
|
|
|
|
m.add_function(wrap_pyfunction!(double, &m)?)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-03-12 22:57:03 +00:00
|
|
|
|
|
|
|
fn test_wrap_pyfunction(py: Python<'_>, m: &Bound<'_, PyModule>) {
|
|
|
|
// should lint
|
|
|
|
let _ = wrap_pyfunction!(double, py);
|
|
|
|
|
|
|
|
// should lint but currently does not
|
|
|
|
let _ = wrap_pyfunction!(double)(py);
|
|
|
|
|
|
|
|
// should not lint
|
|
|
|
let _ = wrap_pyfunction!(double, m);
|
|
|
|
let _ = wrap_pyfunction!(double)(m);
|
|
|
|
let _ = wrap_pyfunction!(double, m.as_gil_ref());
|
|
|
|
let _ = wrap_pyfunction!(double)(m.as_gil_ref());
|
|
|
|
let _ = wrap_pyfunction_bound!(double, py);
|
|
|
|
let _ = wrap_pyfunction_bound!(double)(py);
|
|
|
|
}
|