| 173 | |
| 174 | impl 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( |