Better codecs and fix lots of test_io and other expectedFailures#6997
Better codecs and fix lots of test_io and other expectedFailures#6997youknowone merged 4 commits into
Conversation
📝 WalkthroughWalkthroughAdds partial-output handling to SurrogateEscape encoding; tightens codec-name validation and exposes Changes
Sequence Diagram(s)sequenceDiagram
participant GC as GC (finalizer)
participant Wrapper as TextIOWrapper
participant Raw as RawBuffer/FileIO
participant VM as VirtualMachine
GC->>Wrapper: invoke destructor / finalize
Wrapper->>Wrapper: check/set finalizing (AtomicBool)
alt first finalize
Wrapper->>Raw: call close()/flush()
Raw-->>Wrapper: success / failure
alt failure or not closed
Wrapper->>VM: emit ResourceWarning via iobase_finalize/_dealloc_warn
end
else reentrant finalize
Wrapper-->>GC: skip redundant finalize
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Sorry, something went wrong.
c160d81 to
a10351b
Compare
February 5, 2026 01:13
|
Code has been automatically formatted The code in this PR has been formatted using:
git pull origin test_io |
Sorry, something went wrong.
0194bb5 to
856c6f1
Compare
February 5, 2026 09:16
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/vm/src/stdlib/io.rs (1)
2687-2727: ⚠️ Potential issue | 🟠 MajorRoute
TextIOWrapperencoding parameter throughtext_encoding()to emit EncodingWarning.Per PEP 597,
TextIOWrapper(..., encoding=None)should emitEncodingWarningwhenwarn_default_encodingis enabled, but currently it bypasses the warning mechanism by callingresolve_encoding()directly. This is inconsistent withio.open(), which correctly usestext_encoding()to emit the warning. TheNonecase inTextIOWrapper::init()should be routed throughtext_encoding()to comply with PEP 597.
🤖 Fix all issues with AI agents
In `@crates/vm/src/stdlib/io.rs`:
- Around line 2770-2862: The bool_from_index function currently calls
value.try_index() and converts to i32 which breaks truthiness and can overflow;
replace its body to directly use value.try_to_bool(vm) and return that result
(i.e., remove try_index()/try_to_primitive() logic and simply call
value.try_to_bool(vm)?), keeping the function signature (fn
bool_from_index(value: PyObjectRef, vm: &VirtualMachine) -> PyResult<bool>) so
callers (and the pattern used elsewhere with try_to_bool) continue to work.
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@crates/vm/src/stdlib/codecs.rs`:
- Around line 996-1013: The replacement-handling branch currently rejects
non-ASCII code points; instead, encode the replacement PyStr using the same code
page as the fast path by calling try_encode_code_page_strict on rep_str with
encoding_str and handle errors the same way as other encoding failures: on
success extend output with the returned bytes, on failure return
vm.new_unicode_encode_error_real (preserving s, pos, encoding_str and an
appropriate error message). Replace the manual per-codepoint ASCII check with
this call in the branch that inspects replacement.downcast_ref::<PyStr>() so the
error handler can emit bytes valid for encodings like cp1252.
Sorry, something went wrong.
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/codecs.py dependencies:
dependent tests: (106 tests)
[ ] lib: cpython/Lib/encodings dependencies:
dependent tests: (57 tests)
[x] lib: cpython/Lib/bz2.py dependencies:
dependent tests: (1 tests)
[x] lib: cpython/Lib/fileinput.py dependencies:
dependent tests: (2 tests)
[x] lib: cpython/Lib/gzip.py dependencies:
dependent tests: (no tests depend on gzip) [ ] lib: cpython/Lib/io.py dependencies:
dependent tests: (87 tests)
[ ] lib: cpython/Lib/logging dependencies:
dependent tests: (9 tests)
[x] lib: cpython/Lib/lzma.py dependencies:
dependent tests: (1 tests)
[ ] lib: cpython/Lib/plistlib.py dependencies:
dependent tests: (1 tests)
[ ] lib: cpython/Lib/test/libregrtest dependencies:
dependent tests: (no tests depend on regrtest) [ ] test: cpython/Lib/test/test_str.py (TODO: 16) dependencies: dependent tests: (no tests depend on str) [ ] lib: cpython/Lib/tarfile.py dependencies:
dependent tests: (2 tests)
[ ] test: cpython/Lib/test/test_utf8_mode.py (TODO: 6) dependencies: dependent tests: (no tests depend on utf8_mode) Legend:
|
Sorry, something went wrong.
1e1b423
into
RustPython:main
Feb 6, 2026
Summary by CodeRabbit
New Features
-X utf8command-line option to control UTF‑8 modeImprovements