diff --git a/Lib/test/test_deque.py b/Lib/test/test_deque.py index 81b25aebd8..77a2c9e707 100644 --- a/Lib/test/test_deque.py +++ b/Lib/test/test_deque.py @@ -236,8 +236,6 @@ class TestBasic(unittest.TestCase): with self.assertRaises(TypeError): deque('abc') + 'def' - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_iadd(self): d = deque('a') d += 'bcd' @@ -1010,7 +1008,6 @@ class TestSequence(seq_tests.CommonTest): def test_pickle(self): pass - @unittest.skip("TODO: RUSTPYTHON TypeError: '+=' not supported between instances of 'deque' and 'deque'") def test_iadd(self): pass diff --git a/vm/src/stdlib/collections.rs b/vm/src/stdlib/collections.rs index 3a814fdb75..df6530bc1a 100644 --- a/vm/src/stdlib/collections.rs +++ b/vm/src/stdlib/collections.rs @@ -8,7 +8,7 @@ mod _collections { use crate::slots::{Comparable, Hashable, Iterable, PyComparisonOp, PyIter, Unhashable}; use crate::vm::ReprGuard; use crate::VirtualMachine; - use crate::{sequence, sliceable}; + use crate::{sequence, sliceable, IdProtocol, TryFromObject}; use crate::{PyComparisonValue, PyIterable, PyObjectRef, PyRef, PyResult, PyValue, StaticType}; use itertools::Itertools; use std::collections::VecDeque; @@ -22,6 +22,7 @@ mod _collections { deque: PyRwLock>, maxlen: AtomicCell>, } + type PyDequeRef = PyRef; impl PyValue for PyDeque { @@ -321,6 +322,23 @@ mod _collections { fn len(&self) -> usize { self.borrow_deque().len() } + + #[pymethod(magic)] + fn iadd( + zelf: PyRef, + other: PyObjectRef, + vm: &VirtualMachine, + ) -> PyResult> { + let other: PyObjectRef = if zelf.is(&other) { + vm.new_pyobj(zelf.copy()) + } else { + other + }; + let other = PyIterable::try_from_object(vm, other)?; + + zelf.extend(other, vm)?; + Ok(zelf) + } } impl Comparable for PyDeque {