Skip to content

Commit 95f3c0d

Browse files
committed
Add Iter of WeakProxy for test\test_weakref.py's "test_proxy_next"
1 parent 6f8a652 commit 95f3c0d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Lib/test/test_weakref.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,6 @@ def __iter__(self):
432432
# can be killed in the middle of the call
433433
"blech" in p
434434

435-
# TODO: RUSTPYTHON
436-
@unittest.expectedFailure
437435
def test_proxy_next(self):
438436
arr = [4, 5, 6]
439437
def iterator_func():

vm/src/builtins/weakproxy.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use crate::{
55
atomic_func,
66
class::PyClassImpl,
77
function::{OptionalArg, PyComparisonValue, PySetterValue},
8-
protocol::{PyMappingMethods, PySequenceMethods},
8+
protocol::{PyIter, PyIterReturn, PyMappingMethods, PySequenceMethods},
99
types::{
10-
AsMapping, AsSequence, Comparable, Constructor, GetAttr, PyComparisonOp, Representable,
11-
SetAttr,
10+
AsMapping, AsSequence, Comparable, Constructor, GetAttr, IterNext, Iterable,
11+
PyComparisonOp, Representable, SetAttr,
1212
},
1313
Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
1414
};
@@ -71,7 +71,8 @@ crate::common::static_cell! {
7171
Comparable,
7272
AsSequence,
7373
AsMapping,
74-
Representable
74+
Representable,
75+
IterNext
7576
))]
7677
impl PyWeakProxy {
7778
fn try_upgrade(&self, vm: &VirtualMachine) -> PyResult {
@@ -122,6 +123,19 @@ impl PyWeakProxy {
122123
obj.del_item(&*needle, vm)
123124
}
124125
}
126+
impl Iterable for PyWeakProxy {
127+
fn iter(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
128+
let obj = zelf.try_upgrade(vm)?;
129+
Ok(obj.get_iter(vm)?.into())
130+
}
131+
}
132+
133+
impl IterNext for PyWeakProxy {
134+
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
135+
let obj = zelf.try_upgrade(vm)?;
136+
PyIter::new(obj).next(vm)
137+
}
138+
}
125139

126140
fn new_reference_error(vm: &VirtualMachine) -> PyRef<super::PyBaseException> {
127141
vm.new_exception_msg(

0 commit comments

Comments
 (0)