Upgrade test_io from 3.13.11 and fix more io tests by youknowone · Pull Request #6565 · RustPython/RustPython
Caution
Review failed
The pull request is closed.
📝 Walkthrough
Walkthrough
Per-field #[cfg(...)] handling was added to generated struct-sequence initializers, and the I/O subsystem gained atomic closing coordination, non-blocking semantics (Option-wrapped reads/writes), and API updates (renamed __reduce__ → __getstate__) with buffering and flush/rewind adjustments.
Changes
| Cohort / File(s) | Summary |
|---|---|
Struct Sequence Code Generation crates/derive-impl/src/pystructseq.rs |
try_from_elements now initializes each field with per-field cfg_attrs awareness; visible/skipped field inits are conditionally compiled per field, falling back to previous logic when no cfg present. |
I/O Subsystem — Core File crates/vm/src/stdlib/io.rs |
Large changes to buffered and raw I/O: added AtomicBool closing flags, closing() accessors, get_raw_unlocked(), flush/rewind adjustments, and coordinated closing checks across buffered types. |
I/O Subsystem — API Signatures crates/vm/src/stdlib/io.rs |
Replaced __reduce__ with __getstate__ and updated pickle error messages. FileIO read/readinto/write signatures now return Option-wrapped results to represent non-blocking EAGAIN semantics. |
I/O Subsystem — Non-blocking & Buffering Behavior crates/vm/src/stdlib/io.rs |
Read/write/readinto flows updated for non-blocking paths (returning None on would-block), partial buffering now maps to BlockingIOError with EAGAIN semantics, and pre-read flush/rewind added to keep buffers consistent. |
Sequence Diagram(s)
sequenceDiagram
participant Client
participant TextIO as TextIOWrapper
participant Buf as BufferedReader/Writer
participant Raw as FileIO
participant Kernel as OS/Kernel
rect rgb(235,245,255)
Note over Client,Kernel: Non-blocking read path (high-level)
end
Client->>TextIO: read(size, non_blocking=True)
TextIO->>Buf: read(size, non_blocking=True)
alt data in buffer
Buf-->>TextIO: Option<Some(bytes)>
TextIO-->>Client: Some(bytes)
else need raw I/O
Buf->>Raw: read(size, non_blocking=True)
Raw->>Kernel: sys_read(non-blocking)
alt kernel returns bytes
Kernel->>Raw: bytes
Raw-->>Buf: Option<Some(bytes)>
Buf-->>TextIO: Some(bytes)
TextIO-->>Client: Some(bytes)
else EAGAIN
Kernel->>Raw: EAGAIN
Raw-->>Buf: Option<None>
Buf-->>TextIO: None
TextIO-->>Client: None
end
end
sequenceDiagram
participant Writer
participant BufW as BufferedWriter
participant Buffer as LocalBuffer
participant Raw as FileIO
participant Closer as AtomicCloser
rect rgb(255,245,235)
Note over Writer,Closer: Write path with closing coordination
end
Writer->>BufW: write(data)
BufW->>Closer: check closing()
alt closing true
BufW->>Closer: spin-wait / short yield
Closer-->>BufW: still closing -> error
BufW-->>Writer: raise value/error (write to closed)
else closing false
BufW->>Buffer: append data
BufW->>Raw: flush()
alt raw write succeeds
Raw-->>BufW: Ok(n)
BufW-->>Writer: Some(n)
else EAGAIN / BlockingIOError
Raw-->>BufW: BlockingIOError (EAGAIN)
BufW->>Buffer: shift buffer, update positions
BufW-->>Writer: raise BlockingIOError (EAGAIN)
end
end
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
- update _pyio, test_fileio from 3.13.11 and impl more io features #6560: Similar changes to
crates/derive-impl/src/pystructseq.rsimplementing per-field#[cfg(...)]handling in code generation. - Fix test_io on windows #6387: Related to I/O close/cleanup behavior; adds destructors that call
close()on buffered/file IO types impacted by the new closing coordination. - Upgrade test_io from 3.13.11 and fix more io tests #6565: Overlapping edits for both per-field cfg-aware initialization and the atomic closing/non-blocking IO changes in
crates/vm/src/stdlib/io.rs.
Poem
🐰 I hopped through fields with tiny cfg bows,
I guarded streams where the wild wind blows,
Atomic flags hold the closing tight,
Non-blocking bytes dance in moonlight,
sniff — code and carrots, both just right.
Pre-merge checks and finishing touches
✅ Passed checks (3 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately reflects the main changes in the PR: upgrading test_io from Python 3.13.11 and fixing multiple IO-related issues across buffered I/O, file I/O, and text I/O implementations. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 96.55% which is sufficient. The required threshold is 80.00%. |
📜 Recent review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Lib/test/test_io.pyis excluded by!Lib/**
📒 Files selected for processing (2)
crates/derive-impl/src/pystructseq.rscrates/vm/src/stdlib/io.rs
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 @coderabbitai help to get the list of available commands and usage tips.