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

Skip to content

Fix bz2 pickle #5819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Lib/test/test_bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,6 @@ def testCompress4G(self, size):
finally:
data = None

# TODO: RUSTPYTHON
@unittest.expectedFailure
def testPickle(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.assertRaises(TypeError):
Expand Down Expand Up @@ -736,8 +734,6 @@ def testDecompress4G(self, size):
compressed = None
decompressed = None

# TODO: RUSTPYTHON
@unittest.expectedFailure
def testPickle(self):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.assertRaises(TypeError):
Expand Down
10 changes: 10 additions & 0 deletions stdlib/src/bz2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ mod _bz2 {
self.state.lock().needs_input()
}

#[pymethod(name = "__reduce__")]
fn reduce(&self, vm: &VirtualMachine) -> PyResult<()> {
Err(vm.new_type_error("cannot pickle '_bz2.BZ2Decompressor' object".to_owned()))
}

// TODO: mro()?
}

Expand Down Expand Up @@ -185,5 +190,10 @@ mod _bz2 {
state.flushed = true;
Ok(vm.ctx.new_bytes(out.to_vec()))
}

#[pymethod(name = "__reduce__")]
fn reduce(&self, vm: &VirtualMachine) -> PyResult<()> {
Err(vm.new_type_error("cannot pickle '_bz2.BZ2Compressor' object".to_owned()))
}
}
}
Loading