X Tutup
Skip to content

Commit 08fbe7a

Browse files
committed
Implement bytes.__str__
1 parent bfe3d8b commit 08fbe7a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

crates/vm/src/builtins/bytes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,12 @@ impl PyBytes {
224224
size_of::<Self>() + self.len() * size_of::<u8>()
225225
}
226226

227+
#[pymethod]
228+
fn __str__(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
229+
PyBytesInner::warn_on_str("str() on a bytes instance", vm)?;
230+
Ok(vm.ctx.new_str(zelf.inner.repr_bytes(vm)?))
231+
}
232+
227233
fn __add__(&self, other: ArgBytesLike) -> Vec<u8> {
228234
self.inner.add(&other.borrow_buf())
229235
}

0 commit comments

Comments
 (0)
X Tutup