Skip to content

Share builtin standard-stream callback controls - #9720

Merged
youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:fix/builtin-stdio-controls-20261104
Nov 7, 2026
Merged

youknowone merged 2 commits into
RustPython:mainfrom
youknowdot:fix/builtin-stdio-controls-20261104

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Group CPython 3.15 print/input callback controls in 167 changed lines across two production Rust files.

  • Retain the existing derived argument binders while keeping print options as raw owners. Reject unknown keywords before flush truth conversion, resolve stdout afterward, and validate separator/end only after the stdout=None short-circuit.
  • Borrow printed objects through every write and final flush. Preserve separator/end str-subclass conversion and contextual validation errors.
  • Share a PyFile_WriteObject-style helper between print pieces and noninteractive input prompts. Resolve write before stringification, retain the selected callable through conversion, then release converted text, callable and write result in order.
  • Accept arbitrary input prompts. Select and retain stdin/stdout/stderr directly from the sys dictionary, reject missing/None streams, and emit the input audit event before stream callbacks.
  • Distinguish ignored fileno call failures from propagated integer conversion failures. Use platform C-long width, and check stdin's actual terminal status before invoking stdout.fileno.
  • Preserve input flush-error handling, newline/EOF behavior and the existing rustyline/PTY safeguards. Convert interactive prompts once and emit the result audit event after rustyline success. Improve non-string readline diagnostics through the existing qualified-type helper.

Validation

Reference: CPython d220409a13b77de7a6c30abe16ea90db01528edc, Python/bltinmodule.c, its generated clinic binder, Objects/fileobject.c and Python/sysmodule.c.

The pinned CPython oracle passed 47 probes and 10 explicit assertions. Independent review reran it and added seven assertions across three callback/finalizer probes. These are reference/source checks, not execution of RustPython.

Independent exact-source review passed, including the final borrowed-option cleanup. Final threaded cargo check passed in 1m06s and all-targets Clippy in 2m21s, with all 12 unchanged baseline diagnostics matching exactly. No warnings were suppressed. Normal commit hooks, rustfmt and git diff --check passed.

No tests, Lib files, assertions, expected failures or workflows were changed. Native RustPython execution remains unrun because the required execution guard has not been verified. Full workspace/C-API suites, native differential tests and separate platform/feature graphs remain unrun; hosted CI is pending.

Scope and integration

The shared file writer performs one lookup per emitted piece, not a cached lookup for the whole print call. Selected streams and raw input/print owners remain alive across callbacks. Caller-wide argument and outer stream teardown beyond the retained lifetimes are not claimed fixed. Existing extremely long separator/end type-name diagnostics are not truncated to CPython's 200-byte limit.

Full CPython interactive readline, terminal encoding and fallback parity remain outside scope. The existing rustyline/PTY guard is retained, and no terminal runtime validation was performed. The independent vars exception-masking issue is not included.

Existing #9690 shutdown/unraisable handling, #9699 iterator controls and #9718 min/max streaming do not duplicate these behaviors. No general sys stream helper or shutdown behavior is changed. The shared readline diagnostic affects its existing callers without changing successful or EOF behavior.

AI-assisted contribution by OpenAI Codex; assistance is disclosed in the commit trailer.

Preserve print and input argument owners, stream selection, conversion order, audit hooks and writer callback cleanup through shared I/O helpers.

Assisted-by: OpenAI Codex:model version not exposed
Avoid duplicate separator owners without moving controls out of their retained argument structure.

Assisted-by: OpenAI Codex:model version not exposed
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

// Missing means an empty prompt.
#[pyarg(positional, optional, py_default = "''")]
prompt: OptionalArg<PyStrRef>,
prompt: OptionalArg<PyObjectRef>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if this is necessary after #9563

@youknowone
youknowone marked this pull request as ready for review November 7, 2026 12:33
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-07T12:33:49.904675Z
We couldn’t complete this review. Comment @codex review to try again.
2b4acc2 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@youknowone
youknowone merged commit 3d0f6fc into RustPython:main Nov 7, 2026
24 of 28 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants