Add Iter of WeakProxy for test\test_weakref.py's "test_proxy_next"

This commit is contained in:
jyj
2023-03-25 20:41:45 +09:00
parent 6f8a652653
commit 95f3c0d69d
2 changed files with 18 additions and 6 deletions

View File

@@ -432,8 +432,6 @@ class ReferencesTestCase(TestBase):
# can be killed in the middle of the call
"blech" in p
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_proxy_next(self):
arr = [4, 5, 6]
def iterator_func():

View File

@@ -5,10 +5,10 @@ use crate::{
atomic_func,
class::PyClassImpl,
function::{OptionalArg, PyComparisonValue, PySetterValue},
protocol::{PyMappingMethods, PySequenceMethods},
protocol::{PyIter, PyIterReturn, PyMappingMethods, PySequenceMethods},
types::{
AsMapping, AsSequence, Comparable, Constructor, GetAttr, PyComparisonOp, Representable,
SetAttr,
AsMapping, AsSequence, Comparable, Constructor, GetAttr, IterNext, Iterable,
PyComparisonOp, Representable, SetAttr,
},
Context, Py, PyObject, PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
};
@@ -71,7 +71,8 @@ crate::common::static_cell! {
Comparable,
AsSequence,
AsMapping,
Representable
Representable,
IterNext
))]
impl PyWeakProxy {
fn try_upgrade(&self, vm: &VirtualMachine) -> PyResult {
@@ -122,6 +123,19 @@ impl PyWeakProxy {
obj.del_item(&*needle, vm)
}
}
impl Iterable for PyWeakProxy {
fn iter(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let obj = zelf.try_upgrade(vm)?;
Ok(obj.get_iter(vm)?.into())
}
}
impl IterNext for PyWeakProxy {
fn next(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> {
let obj = zelf.try_upgrade(vm)?;
PyIter::new(obj).next(vm)
}
}
fn new_reference_error(vm: &VirtualMachine) -> PyRef<super::PyBaseException> {
vm.new_exception_msg(