2021-01-09 17:33:28 +00:00
|
|
|
use pyo3::prelude::*;
|
|
|
|
|
|
|
|
#[pyclass]
|
|
|
|
struct MyClass {}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[classattr]
|
|
|
|
fn class_attr_with_args(foo: i32) {}
|
|
|
|
}
|
|
|
|
|
2021-04-17 21:22:06 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[classattr(foobar)]
|
|
|
|
const CLASS_ATTR_WITH_ATTRIBUTE_ARG: i32 = 3;
|
|
|
|
}
|
|
|
|
|
2021-01-09 17:33:28 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
fn staticmethod_without_attribute() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[staticmethod]
|
|
|
|
fn staticmethod_with_receiver(&self) {}
|
|
|
|
}
|
|
|
|
|
2023-10-10 05:30:19 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[classmethod]
|
|
|
|
fn classmethod_with_receiver(&self) {}
|
|
|
|
}
|
2021-01-09 17:33:28 +00:00
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[getter(x)]
|
|
|
|
fn getter_without_receiver() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[setter(x)]
|
|
|
|
fn setter_without_receiver() {}
|
|
|
|
}
|
|
|
|
|
2021-10-23 20:32:39 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
2022-11-15 20:10:19 +00:00
|
|
|
#[pyo3(name = "__call__", text_signature = "()")]
|
|
|
|
fn text_signature_on_call() {}
|
2021-10-23 20:32:39 +00:00
|
|
|
}
|
2021-01-09 17:33:28 +00:00
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[getter(x)]
|
2021-06-05 15:28:31 +00:00
|
|
|
#[pyo3(text_signature = "()")]
|
2021-01-09 17:33:28 +00:00
|
|
|
fn text_signature_on_getter(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[setter(x)]
|
2021-06-05 15:28:31 +00:00
|
|
|
#[pyo3(text_signature = "()")]
|
2021-01-09 17:33:28 +00:00
|
|
|
fn text_signature_on_setter(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[classattr]
|
2021-06-05 15:28:31 +00:00
|
|
|
#[pyo3(text_signature = "()")]
|
2021-01-09 17:33:28 +00:00
|
|
|
fn text_signature_on_classattr() {}
|
|
|
|
}
|
|
|
|
|
2022-11-24 22:05:16 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[pyo3(text_signature = 1)]
|
|
|
|
fn invalid_text_signature() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[pyo3(text_signature = "()")]
|
|
|
|
#[pyo3(text_signature = None)]
|
|
|
|
fn duplicate_text_signature() {}
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:10:19 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[getter(x)]
|
|
|
|
#[pyo3(signature = ())]
|
|
|
|
fn signature_on_getter(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[setter(x)]
|
|
|
|
#[pyo3(signature = ())]
|
|
|
|
fn signature_on_setter(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[classattr]
|
|
|
|
#[pyo3(signature = ())]
|
|
|
|
fn signature_on_classattr() {}
|
|
|
|
}
|
|
|
|
|
2021-01-09 17:33:28 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
2023-09-30 21:51:52 +00:00
|
|
|
#[new]
|
|
|
|
#[classmethod]
|
2021-01-09 17:33:28 +00:00
|
|
|
#[staticmethod]
|
2023-09-30 21:51:52 +00:00
|
|
|
#[classattr]
|
|
|
|
#[getter(x)]
|
|
|
|
#[setter(x)]
|
2021-01-09 17:33:28 +00:00
|
|
|
fn multiple_method_types() {}
|
|
|
|
}
|
|
|
|
|
2023-09-30 21:51:52 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[new(signature = ())]
|
|
|
|
fn new_takes_no_arguments(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[new = ()] // in this form there's no suggestion to move arguments to `#[pyo3()]` attribute
|
|
|
|
fn new_takes_no_arguments_nv(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[classmethod(signature = ())]
|
|
|
|
fn classmethod_takes_no_arguments(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[staticmethod(signature = ())]
|
|
|
|
fn staticmethod_takes_no_arguments(&self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[classattr(signature = ())]
|
|
|
|
fn classattr_takes_no_arguments(&self) {}
|
|
|
|
}
|
|
|
|
|
2021-03-09 23:37:01 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
fn generic_method<T>(value: T) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
fn impl_trait_method_first_arg(impl_trait: impl AsRef<PyAny>) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
fn impl_trait_method_second_arg(&self, impl_trait: impl AsRef<PyAny>) {}
|
|
|
|
}
|
2021-01-09 17:33:28 +00:00
|
|
|
|
2021-05-25 10:31:48 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
async fn async_method(&self) {}
|
|
|
|
}
|
|
|
|
|
2021-06-05 15:39:54 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[pyo3(pass_module)]
|
|
|
|
fn method_cannot_pass_module(&self, m: &PyModule) {}
|
|
|
|
}
|
|
|
|
|
2022-03-24 09:27:37 +00:00
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
2022-11-15 20:10:19 +00:00
|
|
|
fn method_self_by_value(self) {}
|
2022-03-24 09:27:37 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 20:10:19 +00:00
|
|
|
struct TwoNew {}
|
2022-02-08 23:44:23 +00:00
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl TwoNew {
|
|
|
|
#[new]
|
2022-11-15 20:10:19 +00:00
|
|
|
fn new_1() -> Self {
|
|
|
|
Self {}
|
|
|
|
}
|
2022-02-08 23:44:23 +00:00
|
|
|
|
|
|
|
#[new]
|
2022-11-15 20:10:19 +00:00
|
|
|
fn new_2() -> Self {
|
|
|
|
Self {}
|
|
|
|
}
|
2022-02-08 23:44:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-15 20:10:19 +00:00
|
|
|
struct DuplicateMethod {}
|
2022-05-24 18:36:24 +00:00
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl DuplicateMethod {
|
|
|
|
#[pyo3(name = "func")]
|
2022-11-15 20:10:19 +00:00
|
|
|
fn func_a(&self) {}
|
2022-05-24 18:36:24 +00:00
|
|
|
|
|
|
|
#[pyo3(name = "func")]
|
2022-11-15 20:10:19 +00:00
|
|
|
fn func_b(&self) {}
|
2022-05-24 18:36:24 +00:00
|
|
|
}
|
|
|
|
|
2023-10-02 20:49:19 +00:00
|
|
|
macro_rules! macro_invocation {
|
|
|
|
() => {};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
macro_invocation!();
|
|
|
|
}
|
|
|
|
|
2021-01-09 17:33:28 +00:00
|
|
|
fn main() {}
|