Repository navigation
bz2: return streaming output from BZ2Compressor.compress() - #8330
Conversation
Return output produced during compression instead of waiting for flush(). Constraint: Preserve encoder state without flushing the BZ2 stream Confidence: high Scope-risk: narrow Directive: Do not flush merely to retrieve partial output Tested: test_bz2; stdlib_bz2.py; prek run --all-files Assisted-by: Codex:gpt-5.6-sol
📝 WalkthroughWalkthrough
ChangesBZ2 streaming output
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/bz2.py dependencies:
dependent tests: (101 tests)
[x] lib: cpython/Lib/csv.py dependencies:
dependent tests: (4 tests)
Legend:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/stdlib/src/bz2.rs`:
- Around line 169-173: Update the encoder handling in the bz2 compression flow
around encoder.as_mut(), replacing unwrap() with ok_or_else that returns a
Python ValueError when the encoder is unavailable. Propagate write_all and the
empty write errors through map_err as Python OS errors, remove the assert_eq!,
and use ? while ignoring the empty write’s byte count.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 1dce455e-0c8b-4ef7-89f7-7fad4f4503ff
⛔ Files ignored due to path filters (1)
Lib/test/test_bz2.pyis excluded by!Lib/**
📒 Files selected for processing (2)
crates/stdlib/src/bz2.rsextra_tests/snippets/stdlib_bz2.py
There was a problem hiding this comment.
isn't cpython already tests that?
There was a problem hiding this comment.
That was my mistake. TY
* bz2: return streaming output from BZ2Compressor.compress() Return output produced during compression instead of waiting for flush(). Constraint: Preserve encoder state without flushing the BZ2 stream Confidence: high Scope-risk: narrow Directive: Do not flush merely to retrieve partial output Tested: test_bz2; stdlib_bz2.py; prek run --all-files Assisted-by: Codex:gpt-5.6-sol * bz2: remove redundant streaming-output snippet
AI assistance: Codex gpt-5.6-sol
I reviewed and manually verified the change.
Summary
Return output produced by
BZ2Compressor.compress()instead of waiting untilflush().This restores incremental compression output and lets
testDecompressorChunksMaxsizerun without its RustPython expected-failure marker.Testing
cargo run --release -- -m test test_bz2cargo run -- extra_tests/snippets/stdlib_bz2.pyprek run --all-filesSummary by CodeRabbit
Bug Fixes
compress()returns available compressed data immediately instead of an empty result.flush()output and successfully decompressed.Tests