Skip to content

Commit f000488

Browse files
committed
new_buffer_error
1 parent 9792001 commit f000488

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

vm/src/function/buffer.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ impl PyObject {
1919
f: impl FnOnce(&[u8]) -> R,
2020
) -> PyResult<R> {
2121
let buffer = PyBuffer::try_from_borrowed_object(vm, self)?;
22-
buffer
23-
.as_contiguous()
24-
.map(|x| f(&x))
25-
.ok_or_else(|| vm.new_type_error("non-contiguous buffer is not a bytes-like object"))
22+
buffer.as_contiguous().map(|x| f(&x)).ok_or_else(|| {
23+
vm.new_buffer_error("non-contiguous buffer is not a bytes-like object".to_owned())
24+
})
2625
}
2726

2827
pub fn try_rw_bytes_like<R>(
@@ -81,7 +80,7 @@ impl<'a> TryFromBorrowedObject<'a> for ArgBytesLike {
8180
if buffer.desc.is_contiguous() {
8281
Ok(Self(buffer))
8382
} else {
84-
Err(vm.new_type_error("non-contiguous buffer is not a bytes-like object"))
83+
Err(vm.new_buffer_error("non-contiguous buffer is not a bytes-like object".to_owned()))
8584
}
8685
}
8786
}
@@ -121,9 +120,9 @@ impl<'a> TryFromBorrowedObject<'a> for ArgMemoryBuffer {
121120
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &'a PyObject) -> PyResult<Self> {
122121
let buffer = PyBuffer::try_from_borrowed_object(vm, obj)?;
123122
if !buffer.desc.is_contiguous() {
124-
Err(vm.new_type_error("non-contiguous buffer is not a bytes-like object"))
123+
Err(vm.new_buffer_error("non-contiguous buffer is not a bytes-like object".to_owned()))
125124
} else if buffer.desc.readonly {
126-
Err(vm.new_type_error("buffer is not a read-write bytes-like object"))
125+
Err(vm.new_buffer_error("buffer is not a read-write bytes-like object".to_owned()))
127126
} else {
128127
Ok(Self(buffer))
129128
}

0 commit comments

Comments
 (0)