Skip to content

Commit 88bd2d9

Browse files
committed
add list iadd TypeError for non iterable object
1 parent 119913b commit 88bd2d9

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

Lib/test/list_tests.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,6 @@ def test_slice(self):
486486
u[:2] = "h"
487487
self.assertEqual(u, list("ham"))
488488

489-
# TODO: RUSTPYTHON
490-
@unittest.expectedFailure
491489
def test_iadd(self):
492490
super().test_iadd()
493491
u = self.type2test([0, 1])

vm/src/builtins/list.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,21 @@ impl PyList {
138138
self.concat(&other, vm)
139139
}
140140

141-
fn inplace_concat(zelf: &Py<Self>, other: &PyObject, vm: &VirtualMachine) -> PyObjectRef {
142-
if let Ok(mut seq) = extract_cloned(other, Ok, vm) {
143-
zelf.borrow_vec_mut().append(&mut seq);
144-
zelf.to_owned().into()
145-
} else {
146-
vm.ctx.not_implemented()
147-
}
141+
fn inplace_concat(
142+
zelf: &Py<Self>,
143+
other: &PyObject,
144+
vm: &VirtualMachine,
145+
) -> PyResult<PyObjectRef> {
146+
let mut seq = extract_cloned(other, Ok, vm)?;
147+
zelf.borrow_vec_mut().append(&mut seq);
148+
Ok(zelf.to_owned().into())
148149
}
149150

150151
#[pymethod(magic)]
151-
fn iadd(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyObjectRef {
152-
if let Ok(mut seq) = extract_cloned(&*other, Ok, vm) {
153-
zelf.borrow_vec_mut().append(&mut seq);
154-
zelf.into()
155-
} else {
156-
vm.ctx.not_implemented()
157-
}
152+
fn iadd(zelf: PyRef<Self>, other: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
153+
let mut seq = extract_cloned(&*other, Ok, vm)?;
154+
zelf.borrow_vec_mut().append(&mut seq);
155+
Ok(zelf)
158156
}
159157

160158
#[pymethod(magic)]
@@ -462,7 +460,7 @@ impl AsSequence for PyList {
462460
}),
463461
inplace_concat: Some(|seq, other, vm| {
464462
let zelf = Self::sequence_downcast(seq);
465-
Ok(Self::inplace_concat(zelf, other, vm))
463+
Self::inplace_concat(zelf, other, vm)
466464
}),
467465
inplace_repeat: Some(|seq, n, vm| {
468466
let zelf = Self::sequence_downcast(seq);

0 commit comments

Comments
 (0)