From b5aa8c8284e2308beeb07bf65677e4d997497b2b Mon Sep 17 00:00:00 2001 From: "Kim, YeonWoo" Date: Tue, 25 Oct 2022 20:48:14 +0900 Subject: [PATCH] Add `StopIteration` type to marshal --- Lib/test/test_marshal.py | 2 -- vm/src/stdlib/marshal.rs | 10 ++++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_marshal.py b/Lib/test/test_marshal.py index 6b6c36732..2161e06b2 100644 --- a/Lib/test/test_marshal.py +++ b/Lib/test/test_marshal.py @@ -104,8 +104,6 @@ class StringTestCase(unittest.TestCase, HelperMixin): self.helper(s) class ExceptionTestCase(unittest.TestCase): - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_exceptions(self): new = marshal.loads(marshal.dumps(StopIteration)) self.assertEqual(StopIteration, new) diff --git a/vm/src/stdlib/marshal.rs b/vm/src/stdlib/marshal.rs index 11ecc6f55..8133117b1 100644 --- a/vm/src/stdlib/marshal.rs +++ b/vm/src/stdlib/marshal.rs @@ -23,7 +23,7 @@ mod decl { None = b'N', False = b'F', True = b'T', - // StopIter = b'S', + StopIter = b'S', Ellipsis = b'.', Int = b'i', Float = b'g', @@ -57,7 +57,7 @@ mod decl { b'N' => None, b'F' => False, b'T' => True, - // b'S' => StopIter, + b'S' => StopIter, b'.' => Ellipsis, b'i' => Int, b'g' => Float, @@ -112,6 +112,8 @@ mod decl { fn dump_obj(buf: &mut Vec, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> { if vm.is_none(&value) { buf.push(Type::None as u8); + } else if value.is(vm.ctx.exceptions.stop_iteration) { + buf.push(Type::StopIter as u8); } else if value.is(&vm.ctx.ellipsis) { buf.push(Type::Ellipsis as u8); } else { @@ -277,6 +279,10 @@ mod decl { Type::True => (true.to_pyobject(vm), buf), Type::False => (false.to_pyobject(vm), buf), Type::None => (vm.ctx.none(), buf), + Type::StopIter => ( + vm.ctx.exceptions.stop_iteration.to_owned().to_pyobject(vm), + buf, + ), Type::Ellipsis => (vm.ctx.ellipsis(), buf), Type::Int => { if buf.len() < 4 {