Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1ecdf3

Browse files
authored
Fix bz2 pickle (#5819)
1 parent dfc8fe0 commit b1ecdf3

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Lib/test/test_bz2.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,6 @@ def testCompress4G(self, size):
676676
finally:
677677
data = None
678678

679-
# TODO: RUSTPYTHON
680-
@unittest.expectedFailure
681679
def testPickle(self):
682680
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
683681
with self.assertRaises(TypeError):
@@ -736,8 +734,6 @@ def testDecompress4G(self, size):
736734
compressed = None
737735
decompressed = None
738736

739-
# TODO: RUSTPYTHON
740-
@unittest.expectedFailure
741737
def testPickle(self):
742738
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
743739
with self.assertRaises(TypeError):

stdlib/src/bz2.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ mod _bz2 {
103103
self.state.lock().needs_input()
104104
}
105105

106+
#[pymethod(name = "__reduce__")]
107+
fn reduce(&self, vm: &VirtualMachine) -> PyResult<()> {
108+
Err(vm.new_type_error("cannot pickle '_bz2.BZ2Decompressor' object".to_owned()))
109+
}
110+
106111
// TODO: mro()?
107112
}
108113

@@ -185,5 +190,10 @@ mod _bz2 {
185190
state.flushed = true;
186191
Ok(vm.ctx.new_bytes(out.to_vec()))
187192
}
193+
194+
#[pymethod(name = "__reduce__")]
195+
fn reduce(&self, vm: &VirtualMachine) -> PyResult<()> {
196+
Err(vm.new_type_error("cannot pickle '_bz2.BZ2Compressor' object".to_owned()))
197+
}
188198
}
189199
}

0 commit comments

Comments
 (0)