Skip to content

Commit b5aa8c8

Browse files
committed
Add StopIteration type to marshal
1 parent 247072c commit b5aa8c8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Lib/test/test_marshal.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ def test_bytes(self):
104104
self.helper(s)
105105

106106
class ExceptionTestCase(unittest.TestCase):
107-
# TODO: RUSTPYTHON
108-
@unittest.expectedFailure
109107
def test_exceptions(self):
110108
new = marshal.loads(marshal.dumps(StopIteration))
111109
self.assertEqual(StopIteration, new)

vm/src/stdlib/marshal.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mod decl {
2323
None = b'N',
2424
False = b'F',
2525
True = b'T',
26-
// StopIter = b'S',
26+
StopIter = b'S',
2727
Ellipsis = b'.',
2828
Int = b'i',
2929
Float = b'g',
@@ -57,7 +57,7 @@ mod decl {
5757
b'N' => None,
5858
b'F' => False,
5959
b'T' => True,
60-
// b'S' => StopIter,
60+
b'S' => StopIter,
6161
b'.' => Ellipsis,
6262
b'i' => Int,
6363
b'g' => Float,
@@ -112,6 +112,8 @@ mod decl {
112112
fn dump_obj(buf: &mut Vec<u8>, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
113113
if vm.is_none(&value) {
114114
buf.push(Type::None as u8);
115+
} else if value.is(vm.ctx.exceptions.stop_iteration) {
116+
buf.push(Type::StopIter as u8);
115117
} else if value.is(&vm.ctx.ellipsis) {
116118
buf.push(Type::Ellipsis as u8);
117119
} else {
@@ -277,6 +279,10 @@ mod decl {
277279
Type::True => (true.to_pyobject(vm), buf),
278280
Type::False => (false.to_pyobject(vm), buf),
279281
Type::None => (vm.ctx.none(), buf),
282+
Type::StopIter => (
283+
vm.ctx.exceptions.stop_iteration.to_owned().to_pyobject(vm),
284+
buf,
285+
),
280286
Type::Ellipsis => (vm.ctx.ellipsis(), buf),
281287
Type::Int => {
282288
if buf.len() < 4 {

0 commit comments

Comments
 (0)