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

Method repeat

crates/vm/src/builtins/bytes.rs:175–186  ·  view source on GitHub ↗
(self, count: isize, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

173
174impl PyRef<PyBytes> {
175 fn repeat(self, count: isize, vm: &VirtualMachine) -> PyResult<Self> {
176 if count == 1 && self.class().is(vm.ctx.types.bytes_type) {
177 // Special case: when some `bytes` is multiplied by `1`,
178 // nothing really happens, we need to return an object itself
179 // with the same `id()` to be compatible with CPython.
180 // This only works for `bytes` itself, not its subclasses.
181 return Ok(self);
182 }
183 self.inner
184 .mul(count, vm)
185 .map(|x| PyBytes::from(x).into_ref(&vm.ctx))
186 }
187}
188
189#[pyclass(

Callers 1

__mul__Method · 0.45

Calls 5

isMethod · 0.80
classMethod · 0.45
mapMethod · 0.45
mulMethod · 0.45
into_refMethod · 0.45

Tested by

no test coverage detected