pymethods: fix support for MSRV

This commit is contained in:
David Hewitt 2021-09-18 13:18:16 +01:00
parent 592c98c722
commit 179b5d1f47
3 changed files with 4 additions and 29 deletions

View File

@ -695,12 +695,14 @@ struct SlotDef {
return_mode: Option<ReturnMode>, return_mode: Option<ReturnMode>,
} }
const NO_ARGUMENTS: &[Ty] = &[];
impl SlotDef { impl SlotDef {
const fn new(slot: &'static str, func_ty: &'static str) -> Self { const fn new(slot: &'static str, func_ty: &'static str) -> Self {
SlotDef { SlotDef {
slot: StaticIdent(slot), slot: StaticIdent(slot),
func_ty: StaticIdent(func_ty), func_ty: StaticIdent(func_ty),
arguments: &[], arguments: NO_ARGUMENTS,
ret_ty: Ty::Object, ret_ty: Ty::Object,
before_call_method: None, before_call_method: None,
extract_error_mode: ExtractErrorMode::Raise, extract_error_mode: ExtractErrorMode::Raise,

View File

@ -41,17 +41,6 @@ impl CompareOp {
_ => None, _ => None,
} }
} }
pub fn matches_ordering(self, ordering: std::cmp::Ordering) -> bool {
match self {
CompareOp::Lt => ordering.is_lt(),
CompareOp::Le => ordering.is_le(),
CompareOp::Eq => ordering.is_eq(),
CompareOp::Ne => ordering.is_ne(),
CompareOp::Gt => ordering.is_gt(),
CompareOp::Ge => ordering.is_ge(),
}
}
} }
/// Basic Python class customization /// Basic Python class customization

View File

@ -2,7 +2,7 @@
use pyo3::exceptions::PyValueError; use pyo3::exceptions::PyValueError;
use pyo3::types::{PySlice, PyType}; use pyo3::types::{PySlice, PyType};
use pyo3::{basic::CompareOp, exceptions::PyAttributeError, prelude::*}; use pyo3::{exceptions::PyAttributeError, prelude::*};
use pyo3::{ffi, py_run, AsPyPointer, PyCell}; use pyo3::{ffi, py_run, AsPyPointer, PyCell};
use std::{isize, iter}; use std::{isize, iter};
@ -56,10 +56,6 @@ impl ExampleClass {
i64_value as u64 i64_value as u64
} }
fn __richcmp__(&self, other: &Self, op: CompareOp) -> bool {
op.matches_ordering(self.value.cmp(&other.value))
}
fn __bool__(&self) -> bool { fn __bool__(&self) -> bool {
self.value != 0 self.value != 0
} }
@ -156,18 +152,6 @@ fn test_hash() {
}) })
} }
#[test]
fn test_richcmp() {
Python::with_gil(|py| {
let example_py = make_example(py);
assert!(example_py
.rich_compare(example_py, CompareOp::Eq)
.unwrap()
.is_true()
.unwrap());
})
}
#[test] #[test]
fn test_bool() { fn test_bool() {
Python::with_gil(|py| { Python::with_gil(|py| {