Skip to content

Commit

Permalink
Return NotImplemented when richcmp doesn't match the expected type.
Browse files Browse the repository at this point in the history
  • Loading branch information
mvaled committed Aug 1, 2020
1 parent 0d727c7 commit 541ad38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/class/basic.rs
Expand Up @@ -278,8 +278,10 @@ where
let arg = py.from_borrowed_ptr::<PyAny>(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)
})
}
Expand Down
12 changes: 6 additions & 6 deletions tests/test_arithmetics.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit 541ad38

Please sign in to comment.