| 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) |