2022-11-15 20:10:19 +00:00
|
|
|
//! Check that some magic methods edge cases error as expected.
|
|
|
|
//!
|
|
|
|
//! For convenience use #[pyo3(name = "__some_dunder__")] to create the methods,
|
|
|
|
//! so that the function names can describe the edge case to be rejected.
|
|
|
|
|
|
|
|
use pyo3::prelude::*;
|
2023-06-03 14:55:13 +00:00
|
|
|
use pyo3::pyclass::CompareOp;
|
2022-11-15 20:10:19 +00:00
|
|
|
|
|
|
|
#[pyclass]
|
|
|
|
struct MyClass {}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Argument counts
|
|
|
|
//
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[pyo3(name = "__truediv__")]
|
|
|
|
fn truediv_expects_one_argument(&self) -> PyResult<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[pyo3(name = "__truediv__")]
|
|
|
|
fn truediv_expects_one_argument_py(&self, _py: Python<'_>) -> PyResult<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Forbidden attributes
|
|
|
|
//
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[pyo3(name = "__bool__", signature = ())]
|
|
|
|
fn signature_is_forbidden(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl MyClass {
|
|
|
|
#[pyo3(name = "__bool__", text_signature = "")]
|
|
|
|
fn text_signature_is_forbidden(&self) -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-03 14:55:13 +00:00
|
|
|
#[pyclass]
|
|
|
|
struct EqAndRichcmp;
|
|
|
|
|
|
|
|
#[pymethods]
|
|
|
|
impl EqAndRichcmp {
|
2024-05-03 07:42:30 +00:00
|
|
|
fn __eq__(&self, _other: &Self) -> bool {
|
2023-06-03 14:55:13 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2024-05-03 07:42:30 +00:00
|
|
|
fn __richcmp__(&self, _other: &Self, _op: CompareOp) -> bool {
|
2023-06-03 14:55:13 +00:00
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-15 20:10:19 +00:00
|
|
|
fn main() {}
|