Skip to content

Commit 15fdf1e

Browse files
authored
Merge pull request RustPython#4967 from youknowone/fix-bytearray
Fix repr(bytearray) in debug
2 parents 0a10e6c + 4c2ab63 commit 15fdf1e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

vm/src/bytesinner.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,12 @@ impl PyBytesInner {
253253
}
254254

255255
pub fn repr_with_name(&self, class_name: &str, vm: &VirtualMachine) -> PyResult<String> {
256+
const DECORATION_LEN: isize = 2 + 3; // 2 for (), 3 for b"" => bytearray(b"")
256257
let escape = crate::literal::escape::AsciiEscape::new_repr(&self.elements);
257258
let len = escape
258259
.layout()
259260
.len
260-
.and_then(|len| (len as isize).checked_add(2 + class_name.len() as isize))
261+
.and_then(|len| (len as isize).checked_add(DECORATION_LEN + class_name.len() as isize))
261262
.ok_or_else(|| Self::new_repr_overflow_error(vm))? as usize;
262263
let mut buf = String::with_capacity(len);
263264
buf.push_str(class_name);

0 commit comments

Comments
 (0)