From 61de05b35604b0ff153897b242e5b94cbd1595c2 Mon Sep 17 00:00:00 2001 From: kngwyu Date: Sun, 29 Mar 2020 22:40:20 +0900 Subject: [PATCH] Speficy METH_COEXIST for protocol methods --- pyo3-derive-backend/src/pyproto.rs | 2 +- tests/test_arithmetics.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyo3-derive-backend/src/pyproto.rs b/pyo3-derive-backend/src/pyproto.rs index 8416dfb2e97..2ae1043b25f 100644 --- a/pyo3-derive-backend/src/pyproto.rs +++ b/pyo3-derive-backend/src/pyproto.rs @@ -86,7 +86,7 @@ fn impl_proto_impl( Some(pyo3::class::PyMethodDef { ml_name: stringify!(#name), ml_meth: pyo3::class::PyMethodType::PyCFunctionWithKeywords(__wrap), - ml_flags: pyo3::ffi::METH_VARARGS | pyo3::ffi::METH_KEYWORDS, + ml_flags: pyo3::ffi::METH_VARARGS | pyo3::ffi::METH_KEYWORDS | pyo3::ffi::METH_COEXIST, ml_doc: "" }) } diff --git a/tests/test_arithmetics.rs b/tests/test_arithmetics.rs index 39367406cc7..c30089ae2ee 100755 --- a/tests/test_arithmetics.rs +++ b/tests/test_arithmetics.rs @@ -291,9 +291,11 @@ fn lhs_override_rhs() { let py = gil.python(); let c = PyCell::new(py, LhsAndRhsArithmetic {}).unwrap(); - py_run!(py, c, "assert c.__radd__(1) == '1 + BA'"); + // Not overrided + py_run!(py, c, "assert c.__radd__(1) == '1 + RA'"); + py_run!(py, c, "assert c.__rsub__(1) == '1 - RA'"); + // Overrided py_run!(py, c, "assert 1 + c == '1 + BA'"); - py_run!(py, c, "assert c.__rsub__(1) == '1 - BA'"); py_run!(py, c, "assert 1 - c == '1 - BA'"); }