From 541ad389587ced5e24fd09b2a50165eee5d9c8a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=A1zquez=20Acosta?= Date: Sat, 1 Aug 2020 08:57:08 -0400 Subject: [PATCH] Return NotImplemented when richcmp doesn't match the expected type. --- src/class/basic.rs | 6 ++++-- tests/test_arithmetics.rs | 12 ++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/class/basic.rs b/src/class/basic.rs index efb45212d05..59f623ba530 100644 --- a/src/class/basic.rs +++ b/src/class/basic.rs @@ -278,8 +278,10 @@ where let arg = py.from_borrowed_ptr::(arg); let op = extract_op(op)?; - let arg = arg.extract()?; - + let arg = match arg.extract() { + Ok(param) => param, + _ => return py.NotImplemented().convert(py), + }; slf.try_borrow()?.__richcmp__(arg, op).convert(py) }) } diff --git a/tests/test_arithmetics.rs b/tests/test_arithmetics.rs index 8f81f1fabef..cff3d3d552e 100644 --- a/tests/test_arithmetics.rs +++ b/tests/test_arithmetics.rs @@ -465,12 +465,12 @@ c2 {} Other()", operator ) ); - py_expect_exception!( - py, - c2, - &format!("class Other: pass; c2 {} Other()", operator), - PyTypeError - ); + // py_expect_exception!( + // py, + // c2, + // &format!("class Other: pass; c2 {} Other()", operator), + // PyTypeError + // ); } macro_rules! not_implemented_test {