Skip to content

Commit 93d3155

Browse files
committed
add missing ZBytes::__str__
It was clearly an oversight, as `ZBytes.__str__` is present in the stub
1 parent 5ca29d3 commit 93d3155

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/bytes.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ impl ZBytes {
4949
}
5050
}
5151

52-
fn to_bytes(&self) -> Cow<[u8]> {
53-
self.0.to_bytes()
52+
fn to_bytes<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyBytes>> {
53+
// Not using `ZBytes::to_bytes`
54+
PyBytes::new_bound_with(py, self.0.len(), |bytes| {
55+
self.0.reader().read_exact(bytes).into_pyres()
56+
})
5457
}
5558

5659
fn to_string(&self) -> PyResult<Cow<str>> {
@@ -68,9 +71,11 @@ impl ZBytes {
6871
}
6972

7073
fn __bytes__<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyBytes>> {
71-
PyBytes::new_bound_with(py, self.0.len(), |bytes| {
72-
self.0.reader().read_exact(bytes).into_pyres()
73-
})
74+
self.to_bytes(py)
75+
}
76+
77+
fn __str__(&self) -> PyResult<Cow<str>> {
78+
self.to_string()
7479
}
7580

7681
fn __eq__(&self, other: &Bound<PyAny>) -> PyResult<bool> {

0 commit comments

Comments
 (0)