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

Method cmp

crates/vm/src/builtins/object.rs:319–346  ·  view source on GitHub ↗
(
        zelf: &PyObject,
        other: &PyObject,
        op: PyComparisonOp,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

317
318 #[inline(always)]
319 fn cmp(
320 zelf: &PyObject,
321 other: &PyObject,
322 op: PyComparisonOp,
323 vm: &VirtualMachine,
324 ) -> PyResult<PyComparisonValue> {
325 let res = match op {
326 PyComparisonOp::Eq => {
327 if zelf.is(other) {
328 PyComparisonValue::Implemented(true)
329 } else {
330 PyComparisonValue::NotImplemented
331 }
332 }
333 PyComparisonOp::Ne => {
334 let cmp = zelf.class().slots.richcompare.load().unwrap();
335 let value = match cmp(zelf, other, PyComparisonOp::Eq, vm)? {
336 Either::A(obj) => PyArithmeticValue::from_object(vm, obj)
337 .map(|obj| obj.try_to_bool(vm))
338 .transpose()?,
339 Either::B(value) => value,
340 };
341 value.map(|v| !v)
342 }
343 _ => PyComparisonValue::NotImplemented,
344 };
345 Ok(res)
346 }
347
348 /// Implement setattr(self, name, value).
349 #[pymethod]

Callers

nothing calls this directly

Calls 7

cmpFunction · 0.85
isMethod · 0.80
try_to_boolMethod · 0.80
unwrapMethod · 0.45
loadMethod · 0.45
classMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected