forked from Rust-related/RustPython
Merge pull request #2843 from eldpswp99/add_deque_iadd
add deque __iadd__ method
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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<VecDeque<PyObjectRef>>,
|
||||
maxlen: AtomicCell<Option<usize>>,
|
||||
}
|
||||
|
||||
type PyDequeRef = PyRef<PyDeque>;
|
||||
|
||||
impl PyValue for PyDeque {
|
||||
@@ -321,6 +322,23 @@ mod _collections {
|
||||
fn len(&self) -> usize {
|
||||
self.borrow_deque().len()
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn iadd(
|
||||
zelf: PyRef<Self>,
|
||||
other: PyObjectRef,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyRef<Self>> {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user