Skip to content

Commit 5d6d72f

Browse files
committed
Comparable for SchedParam
1 parent dec6608 commit 5d6d72f

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

crates/vm/src/stdlib/posix.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ pub mod module {
2222
builtins::{PyDictRef, PyInt, PyListRef, PyStr, PyTupleRef, PyType},
2323
convert::{IntoPyException, ToPyObject, TryFromObject},
2424
exceptions::OSErrorBuilder,
25-
function::{Either, KwArgs, OptionalArg},
25+
function::{Either, KwArgs, OptionalArg, PyComparisonValue},
2626
ospath::{OsPath, OsPathOrFd},
2727
stdlib::os::{
2828
_os, DirFd, FollowSymlinks, SupportFunc, TargetIsDirectory, fs_metadata,
2929
warn_if_bool_fd,
3030
},
31-
types::{Constructor, Representable},
31+
types::{Comparable, Constructor, PyComparisonOp, Representable},
3232
};
3333
#[cfg(any(
3434
target_os = "android",
@@ -904,7 +904,7 @@ pub mod module {
904904
}
905905
}
906906

907-
#[pyclass(with(Constructor, Representable))]
907+
#[pyclass(with(Comparable, Constructor, Representable))]
908908
impl SchedParam {
909909
#[pygetset]
910910
fn sched_priority(&self, vm: &VirtualMachine) -> PyObjectRef {
@@ -988,6 +988,24 @@ pub mod module {
988988
}
989989
}
990990

991+
impl Comparable for SchedParam {
992+
fn cmp(
993+
zelf: &Py<Self>,
994+
other: &crate::PyObject,
995+
op: PyComparisonOp,
996+
vm: &VirtualMachine,
997+
) -> PyResult<PyComparisonValue> {
998+
op.eq_only(|| {
999+
let other = class_or_notimplemented!(Self, other);
1000+
let eq = vm.identical_or_equal(
1001+
&zelf.sched_priority,
1002+
&other.sched_priority,
1003+
)?;
1004+
Ok(eq.into())
1005+
})
1006+
}
1007+
}
1008+
9911009
#[cfg(any(
9921010
target_os = "linux",
9931011
target_os = "netbsd",

0 commit comments

Comments
 (0)