Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Lib/test/test_deque.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ def test_add(self):
with self.assertRaises(TypeError):
deque('abc') + 'def'

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_iadd(self):
d = deque('a')
d += 'bcd'
Expand Down Expand Up @@ -1010,7 +1008,6 @@ def test_free_after_iterating(self):
def test_pickle(self):
pass

@unittest.skip("TODO: RUSTPYTHON TypeError: '+=' not supported between instances of 'deque' and 'deque'")
def test_iadd(self):
pass

Expand Down
20 changes: 19 additions & 1 deletion vm/src/stdlib/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +22,7 @@ mod _collections {
deque: PyRwLock<VecDeque<PyObjectRef>>,
maxlen: AtomicCell<Option<usize>>,
}

type PyDequeRef = PyRef<PyDeque>;

impl PyValue for PyDeque {
Expand Down Expand Up @@ -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())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by calling here new_pyobj and calling try_from_object later, this is making unnessessary PyObjectRef.

} else {
other
};
let other = PyIterable::try_from_object(vm, other)?;

zelf.extend(other, vm)?;
Ok(zelf)
}
}

impl Comparable for PyDeque {
Expand Down