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

Method repeat

crates/vm/src/builtins/tuple.rs:332–346  ·  view source on GitHub ↗
(zelf: PyRef<Self>, value: isize, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

330 }
331
332 fn repeat(zelf: PyRef<Self>, value: isize, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
333 Ok(if zelf.elements.is_empty() || value == 0 {
334 vm.ctx.empty_tuple.clone()
335 } else if value == 1 && zelf.class().is(vm.ctx.types.tuple_type) {
336 // Special case: when some `tuple` is multiplied by `1`,
337 // nothing really happens, we need to return an object itself
338 // with the same `id()` to be compatible with CPython.
339 // This only works for `tuple` itself, not its subclasses.
340 zelf
341 } else {
342 let v = zelf.elements.mul(vm, value)?;
343 let elements = v.into_boxed_slice();
344 Self { elements }.into_ref(&vm.ctx)
345 })
346 }
347
348 pub fn extract_tuple<'a, T: FromPyTuple<'a>>(&'a self, vm: &VirtualMachine) -> PyResult<T> {
349 T::from_pytuple(self, vm)

Callers

nothing calls this directly

Calls 6

isMethod · 0.80
is_emptyMethod · 0.45
cloneMethod · 0.45
classMethod · 0.45
mulMethod · 0.45
into_refMethod · 0.45

Tested by

no test coverage detected