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

Method cmp

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

Source from the content-addressed store, hash-verified

497
498impl Comparable for PyRange {
499 fn cmp(
500 zelf: &Py<Self>,
501 other: &PyObject,
502 op: PyComparisonOp,
503 _vm: &VirtualMachine,
504 ) -> PyResult<PyComparisonValue> {
505 op.eq_only(|| {
506 if zelf.is(other) {
507 return Ok(true.into());
508 }
509 let rhs = class_or_notimplemented!(Self, other);
510 let lhs_len = zelf.compute_length();
511 let eq = if lhs_len != rhs.compute_length() {
512 false
513 } else if lhs_len.is_zero() {
514 true
515 } else if zelf.start.as_bigint() != rhs.start.as_bigint() {
516 false
517 } else if lhs_len.is_one() {
518 true
519 } else {
520 zelf.step.as_bigint() == rhs.step.as_bigint()
521 };
522 Ok(eq.into())
523 })
524 }
525}
526
527impl Iterable for PyRange {

Callers

nothing calls this directly

Calls 5

eq_onlyMethod · 0.80
isMethod · 0.80
compute_lengthMethod · 0.80
as_bigintMethod · 0.80
is_zeroMethod · 0.45

Tested by

no test coverage detected