mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Add Iter of WeakProxy for test\test_weakref.py's "test_proxy_next"
This commit is contained in:
2
Lib/test/test_weakref.py
vendored
2
Lib/test/test_weakref.py
vendored
@@ -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():
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user