mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #3451 from waroad/enumerate_add_reduce
add reduce in enumerate
This commit is contained in:
2
Lib/test/test_enumerate.py
vendored
2
Lib/test/test_enumerate.py
vendored
@@ -94,8 +94,6 @@ class EnumerateTestCase(unittest.TestCase, PickleTest):
|
||||
self.assertEqual(list(self.enum(self.seq)), self.res)
|
||||
self.enum.__doc__
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_pickle(self):
|
||||
self.check_pickle(self.enum(self.seq), self.res)
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ use crate::{
|
||||
function::{IntoPyObject, OptionalArg},
|
||||
protocol::{PyIter, PyIterReturn},
|
||||
types::{Constructor, IterNext, IterNextIterable},
|
||||
ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyResult, PyValue, VirtualMachine,
|
||||
ItemProtocol, PyClassImpl, PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol,
|
||||
VirtualMachine,
|
||||
};
|
||||
use num_bigint::BigInt;
|
||||
use num_traits::Zero;
|
||||
@@ -52,6 +53,13 @@ impl PyEnumerate {
|
||||
fn class_getitem(cls: PyTypeRef, args: PyObjectRef, vm: &VirtualMachine) -> PyGenericAlias {
|
||||
PyGenericAlias::new(cls, args, vm)
|
||||
}
|
||||
#[pymethod(magic)]
|
||||
fn reduce(zelf: PyRef<Self>) -> (PyTypeRef, (PyIter, BigInt)) {
|
||||
(
|
||||
zelf.clone_class(),
|
||||
(zelf.iterator.clone(), zelf.counter.read().clone()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl IterNextIterable for PyEnumerate {}
|
||||
|
||||
Reference in New Issue
Block a user