← Back to Pull requests

Add the `io` module with `StringIO` and `BytesIO` #1420

Closed
unknown closed this pull request without merging on Nov 27, 2026 14:41 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 14:17 UTC
Author

  • io.StringIO and io.BytesIO, native, matching CPython's messages and check ordering

  • io.SEEK_SET / SEEK_CUR / SEEK_END, DEFAULT_BUFFER_SIZE, open, open_code, text_encoding, UnsupportedOperation

  • BlockingIOError as a new builtin exception (also io.BlockingIOError)

  • io.TextIOWrapper, BufferedReader, BufferedWriter, BufferedRandom exported for isinstance checks

  • json.load/dump, csv readers/writers and print(file=...) accept the in-memory streams

  • open() accepts encoding='locale'

  • limitations/io.md
  • 🤖 Generated with Claude Code

    <!-- This is an auto-generated description by cubic. -->
    ---

    Summary by cubic


    Adds the io module with native StringIO and BytesIO in-memory streams that match CPython's error messages, argument-check ordering, and newline handling.

    What changed

  • io is split like CPython: native _io holds the streams, file classes, open, open_code, text_encoding, DEFAULT_BUFFER_SIZE and the io exceptions; io is CPython's vendored io.py, patched to drop the ABCs and Reader/Writer protocols.

  • StringIO and BytesIO share newline translation with open() text files; both take CPython's newline argument and support re-running __init__ to reset the stream.

  • Stream methods register through attribute tables, so unbound calls like io.BytesIO.read(b) validate their receiver as CPython does.

  • print(file=...), json.load/dump, and the csv readers and writers read and write through the streams; csv.writerows writes a stream row by row, only open() files batch rows.

  • Writes ending past ssize_t raise CPython's OverflowError instead of panicking or wrapping; the wasm harness pins the 32-bit bounds of seek() and writes, read/readline sizes search only their bounds, and a closed BytesIO reports ValueError before preflighting a write payload.

  • Stream buffers preflight their growth against the sandbox memory limit at each doubling, including through print(file=) and readlines().

  • CPython's test_memoryio suite runs 57 of its 188 tests; the rest are skipped with reasons in skips.toml.

  • Typeshed stubs are narrowed to the same surface, so absent names like FileIO and io.IOBase fail type checking.
  • New module surface

  • Exports SEEK_SET/SEEK_CUR/SEEK_END, DEFAULT_BUFFER_SIZE, open, open_code, text_encoding, and UnsupportedOperation (shared with open() files).

  • BlockingIOError is a new builtin exception, also exported as io.BlockingIOError; _io is listed in sys.builtin_module_names.

  • TextIOWrapper, BufferedReader, BufferedWriter, and BufferedRandom are exported for isinstance checks only; constructing them raises TypeError. FileIO, BufferedRWPair, and IncrementalNewlineDecoder are absent.

  • open() now accepts encoding='locale', which resolves to UTF-8 in the sandbox.
  • <sup>Written for commit 8eb18bed92158538fc363e63833fa3e88339b853. Summary will update on new commits.</sup>

    <a href="https://cubic.dev/pr/pydantic/monty/pull/1420?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a>

    <!-- End of auto-generated description by cubic. -->

    Diff: 446 lines (+334 / -112) across 5 files Reviewer: davidhewitt Review duration: 4343m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 446 lines diff across 5 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.365
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1420"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.4% (MEDIUM) · Higher = larger blast radius
    50.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.9% · Safe to merge
    19.9%
    Repository