mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fix byte __imul__
This commit is contained in:
1 parent
b569ccf240
commit
4d40a36fd2
3 files changed
+4
-19
No files matched your search
@@ -1392,8 +1392,6 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
|
||||
else:
|
||||
self.fail("bytes += unicode didn't raise TypeError")
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_irepeat(self):
|
||||
b = bytearray(b"abc")
|
||||
b1 = b
|
||||
@@ -1402,8 +1400,6 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
|
||||
self.assertEqual(b, b1)
|
||||
self.assertIs(b, b1)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_irepeat_1char(self):
|
||||
b = bytearray(b"x")
|
||||
b1 = b
|
||||
|
||||
+1
-13
@@ -1010,19 +1010,7 @@ impl PyBytesInner {
|
||||
// We can multiple an empty vector by any integer, even if it doesn't fit in an isize.
|
||||
return;
|
||||
}
|
||||
|
||||
if n <= 0 {
|
||||
self.elements.clear();
|
||||
} else {
|
||||
let n = n.to_usize().unwrap(); // always positive by outer if condition
|
||||
|
||||
let old = self.elements.clone();
|
||||
|
||||
self.elements.reserve((n - 1) * old.len());
|
||||
for _ in 1..n {
|
||||
self.elements.extend(&old);
|
||||
}
|
||||
}
|
||||
self.elements = self.repeat(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -574,8 +574,9 @@ impl PyByteArray {
|
||||
}
|
||||
|
||||
#[pymethod(name = "__imul__")]
|
||||
fn imul(&self, n: isize) {
|
||||
self.borrow_value_mut().irepeat(n)
|
||||
fn imul(zelf: PyRef<Self>, n: isize) -> PyRef<Self> {
|
||||
zelf.borrow_value_mut().irepeat(n);
|
||||
zelf
|
||||
}
|
||||
|
||||
#[pymethod(name = "__mod__")]
|
||||
|
||||
Reference in new issue
Block a user