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

Method _imul

crates/vm/src/vm/vm_ops.rs:484–513  ·  view source on GitHub ↗
(&self, a: &PyObject, b: &PyObject)

Source from the content-addressed store, hash-verified

482 }
483
484 pub fn _imul(&self, a: &PyObject, b: &PyObject) -> PyResult {
485 let result = self.binary_iop1(
486 a,
487 b,
488 PyNumberBinaryOp::InplaceMultiply,
489 PyNumberBinaryOp::Multiply,
490 )?;
491 if !result.is(&self.ctx.not_implemented) {
492 return Ok(result);
493 }
494 if let Ok(seq_a) = a.try_sequence(self) {
495 let n = b
496 .try_index(self)?
497 .as_bigint()
498 .to_isize()
499 .ok_or_else(|| self.new_overflow_error("repeated bytes are too long"))?;
500 return seq_a.inplace_repeat(n, self);
501 } else if let Ok(seq_b) = b.try_sequence(self) {
502 let n = a
503 .try_index(self)?
504 .as_bigint()
505 .to_isize()
506 .ok_or_else(|| self.new_overflow_error("repeated bytes are too long"))?;
507 /* Note that the right hand operand should not be
508 * mutated in this case so inplace_repeat is not
509 * used. */
510 return seq_b.repeat(n, self);
511 }
512 Err(self.new_unsupported_bin_op_error(a, b, "*="))
513 }
514
515 pub fn _abs(&self, a: &PyObject) -> PyResult<PyObjectRef> {
516 self.get_special_method(a, identifier!(self, __abs__))?

Callers 3

execute_bin_opMethod · 0.80
inplace_repeatMethod · 0.80
imulFunction · 0.80

Calls 10

binary_iop1Method · 0.80
isMethod · 0.80
try_sequenceMethod · 0.80
ok_or_elseMethod · 0.80
as_bigintMethod · 0.80
try_indexMethod · 0.80
inplace_repeatMethod · 0.80
ErrClass · 0.50
repeatMethod · 0.45

Tested by

no test coverage detected