Skip to content

Commit bd4f7ab

Browse files
authored
Merge pull request RustPython#3734 from gnsxun/map-mod
Add map.reduce()
2 parents d9b3d80 + d1f22fe commit bd4f7ab

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

Lib/test/test_builtin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,6 @@ def badfunc(x):
925925
raise RuntimeError
926926
self.assertRaises(RuntimeError, list, map(badfunc, range(5)))
927927

928-
# TODO: RUSTPYTHON
929-
@unittest.expectedFailure
930928
def test_map_pickle(self):
931929
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
932930
m1 = map(map_char, "Is this the real life?")

Lib/test/test_pickle.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ def test_buffers_error(self): # TODO: RUSTPYTHON, remove when this passes
100100
def test_c_methods(self): # TODO: RUSTPYTHON, remove when this passes
101101
super().test_c_methods() # TODO: RUSTPYTHON, remove when this passes
102102

103-
# TODO: RUSTPYTHON, TypeError: cannot pickle 'map' object
104-
@unittest.expectedFailure
105103
def test_compat_pickle(self): # TODO: RUSTPYTHON, remove when this passes
106104
super().test_compat_pickle() # TODO: RUSTPYTHON, remove when this passes
107105

@@ -211,8 +209,6 @@ def test_buffers_error(self): # TODO: RUSTPYTHON, remove when this passes
211209
def test_c_methods(self): # TODO: RUSTPYTHON, remove when this passes
212210
super().test_c_methods() # TODO: RUSTPYTHON, remove when this passes
213211

214-
# TODO: RUSTPYTHON, TypeError: cannot pickle 'map' object
215-
@unittest.expectedFailure
216212
def test_compat_pickle(self): # TODO: RUSTPYTHON, remove when this passes
217213
super().test_compat_pickle() # TODO: RUSTPYTHON, remove when this passes
218214

Lib/test/test_pickletools.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def test_buffers_error(self): # TODO: RUSTPYTHON, remove when this passes
2222
def test_c_methods(self): # TODO: RUSTPYTHON, remove when this passes
2323
super().test_c_methods()
2424

25-
# TODO: RUSTPYTHON, TypeError: cannot pickle 'map' object
26-
@unittest.expectedFailure
2725
def test_compat_pickle(self): # TODO: RUSTPYTHON, remove when this passes
2826
super().test_compat_pickle()
2927

vm/src/builtins/map.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::PyTypeRef;
22
use crate::{
3+
builtins::PyTupleRef,
34
class::PyClassImpl,
45
function::PosArgs,
56
protocol::{PyIter, PyIterReturn},
@@ -45,6 +46,13 @@ impl PyMap {
4546
Ok(max)
4647
})
4748
}
49+
50+
#[pymethod(magic)]
51+
fn reduce(&self, vm: &VirtualMachine) -> (PyTypeRef, PyTupleRef) {
52+
let mut vec = vec![self.mapper.clone()];
53+
vec.extend(self.iterators.iter().map(|o| o.clone().into()));
54+
(vm.ctx.types.map_type.clone(), vm.new_tuple(vec))
55+
}
4856
}
4957

5058
impl IterNextIterable for PyMap {}

0 commit comments

Comments
 (0)