MCPcopy Index your code
hub / github.com/RustPython/RustPython / cmp

Method cmp

crates/vm/src/builtins/builtin_func.rs:86–105  ·  view source on GitHub ↗
(
        zelf: &Py<Self>,
        other: &PyObject,
        op: PyComparisonOp,
        _vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

84// meth_richcompare in CPython
85impl Comparable for PyNativeFunction {
86 fn cmp(
87 zelf: &Py<Self>,
88 other: &PyObject,
89 op: PyComparisonOp,
90 _vm: &VirtualMachine,
91 ) -> PyResult<PyComparisonValue> {
92 op.eq_only(|| {
93 if let Some(other) = other.downcast_ref::<Self>() {
94 let eq = match (zelf.zelf.as_ref(), other.zelf.as_ref()) {
95 (Some(z), Some(o)) => z.is(o),
96 (None, None) => true,
97 _ => false,
98 };
99 let eq = eq && core::ptr::eq(zelf.value, other.value);
100 Ok(eq.into())
101 } else {
102 Ok(PyComparisonValue::NotImplemented)
103 }
104 })
105 }
106}
107
108// meth_repr in CPython

Callers

nothing calls this directly

Calls 4

eq_onlyMethod · 0.80
isMethod · 0.80
eqFunction · 0.50
as_refMethod · 0.45

Tested by

no test coverage detected