From 09a10aaf270aee85f21f2df6e4006e9933d226b8 Mon Sep 17 00:00:00 2001 From: gnsxun Date: Sat, 21 May 2022 20:05:05 +0900 Subject: [PATCH 1/2] Add map.reduce() --- vm/src/builtins/map.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vm/src/builtins/map.rs b/vm/src/builtins/map.rs index 21769149d62..3e857273715 100644 --- a/vm/src/builtins/map.rs +++ b/vm/src/builtins/map.rs @@ -1,5 +1,6 @@ use super::PyTypeRef; use crate::{ + builtins::PyTupleRef, class::PyClassImpl, function::PosArgs, protocol::{PyIter, PyIterReturn}, @@ -45,6 +46,13 @@ impl PyMap { Ok(max) }) } + + #[pymethod(magic)] + fn reduce(&self, vm: &VirtualMachine) -> (PyTypeRef, PyTupleRef) { + let mut vec = vec![self.mapper.clone()]; + vec.extend(self.iterators.iter().map(|o| o.clone().into())); + (vm.ctx.types.map_type.clone(), vm.new_tuple(vec)) + } } impl IterNextIterable for PyMap {} From d1f22fe4c30072b6e8ec27f301ebb674d475e6b4 Mon Sep 17 00:00:00 2001 From: gnsxun Date: Sun, 22 May 2022 12:40:57 +0900 Subject: [PATCH 2/2] delete expectedFailtures --- Lib/test/test_builtin.py | 2 -- Lib/test/test_pickle.py | 4 ---- Lib/test/test_pickletools.py | 2 -- 3 files changed, 8 deletions(-) diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 8f5b8f0e171..dfdf307798a 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -927,8 +927,6 @@ def badfunc(x): raise RuntimeError self.assertRaises(RuntimeError, list, map(badfunc, range(5))) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_map_pickle(self): for proto in range(pickle.HIGHEST_PROTOCOL + 1): m1 = map(map_char, "Is this the real life?") diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py index 39f0dd63686..28690b11ba6 100644 --- a/Lib/test/test_pickle.py +++ b/Lib/test/test_pickle.py @@ -100,8 +100,6 @@ def test_buffers_error(self): # TODO: RUSTPYTHON, remove when this passes def test_c_methods(self): # TODO: RUSTPYTHON, remove when this passes super().test_c_methods() # TODO: RUSTPYTHON, remove when this passes - # TODO: RUSTPYTHON, TypeError: cannot pickle 'map' object - @unittest.expectedFailure def test_compat_pickle(self): # TODO: RUSTPYTHON, remove when this passes super().test_compat_pickle() # TODO: RUSTPYTHON, remove when this passes @@ -211,8 +209,6 @@ def test_buffers_error(self): # TODO: RUSTPYTHON, remove when this passes def test_c_methods(self): # TODO: RUSTPYTHON, remove when this passes super().test_c_methods() # TODO: RUSTPYTHON, remove when this passes - # TODO: RUSTPYTHON, TypeError: cannot pickle 'map' object - @unittest.expectedFailure def test_compat_pickle(self): # TODO: RUSTPYTHON, remove when this passes super().test_compat_pickle() # TODO: RUSTPYTHON, remove when this passes diff --git a/Lib/test/test_pickletools.py b/Lib/test/test_pickletools.py index ae4b7eb1785..3920261bd39 100644 --- a/Lib/test/test_pickletools.py +++ b/Lib/test/test_pickletools.py @@ -22,8 +22,6 @@ def test_buffers_error(self): # TODO: RUSTPYTHON, remove when this passes def test_c_methods(self): # TODO: RUSTPYTHON, remove when this passes super().test_c_methods() - # TODO: RUSTPYTHON, TypeError: cannot pickle 'map' object - @unittest.expectedFailure def test_compat_pickle(self): # TODO: RUSTPYTHON, remove when this passes super().test_compat_pickle()