← Winnitude! Search  ·  Reader Mode (2184 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 54 LINKS

Convert positional bool arguments in `io` and `os` by truth value by jseop-lim · Pull Request #9922 · RustPython/RustPython

Repository navigation

Convert positional bool arguments in io and os by truth value - #9922


Open
jseop-lim wants to merge 1 commit into RustPython:main from jseop-lim:fix/io-os-bool-arg-truthiness
Open

Convert positional bool arguments in io and os by truth value #9922 jseop-lim wants to merge 1 commit into RustPython:main from jseop-lim:fix/io-os-bool-arg-truthiness

Conversation

jseop-lim commented Nov 17, 2026 · edited by coderabbitai
Bot
Loading



Copy link Copy Markdown
Contributor

Summary

io.IncrementalNewlineDecoder(translate), its decode(final), io.FileIO(closefd), os.set_blocking(blocking) and os.dup2(inheritable) bind their flag as a Rust bool, whose conversion accepts only int instances. CPython declares all five as Argument Clinic bool, which calls PyObject_IsTrue (for example closefd ), so any object is accepted and an exception from __bool__ propagates.

AS-IS

>>> import io, os
>>> io.IncrementalNewlineDecoder(None, None)
TypeError: Expected type bool, not NoneType
>>> io.IncrementalNewlineDecoder(None, True).decode("a\r", None)
TypeError: Expected type bool, not NoneType
>>> io.FileIO(0, "r", None)
TypeError: Expected type bool, not NoneType
>>> os.set_blocking(0, None)
TypeError: Expected type bool, not NoneType
>>> os.dup2(0, 77, None)
TypeError: Expected type bool, not NoneType

TO-BE

>>> io.IncrementalNewlineDecoder(None, None)
<_io.IncrementalNewlineDecoder object at 0x...>
>>> io.IncrementalNewlineDecoder(None, True).decode("a\r", None)
'a'
>>> io.FileIO(0, "r", None)
<_io.FileIO name=0 mode='rb' closefd=False>
>>> os.set_blocking(0, None)
>>> os.dup2(0, 77, None)
77

(matching CPython 3.15.2)

Changes

  • Bind translate, final and closefd as ArgIntoBool in crates/vm/src/stdlib/_io.rs, and blocking and inheritable in crates/vm/src/stdlib/posix.rs. Signatures are unchanged.
  • Add cases to extra_tests/snippets/stdlib_io.py and extra_tests/snippets/stdlib_os.py.
  • Out of scope: the keyword-only flags in os (follow_symlinks, effective_ids), the closefd of open(), whose OpenArgs is also built from Rust in crates/capi, and what I could not build: the Windows versions in nt.rs and _WindowsConsoleIO, and the positional target_is_directory of os.symlink, which is only read in nt.rs.

Test plan

Built and run on macOS aarch64 against upstream/main 7abccf0 , using the CI feature set --no-default-features --features stdlib,importlib,stdio,encodings,sqlite,ssl-rustls-aws-lc,host_env,doc,ucd_3_2_0, plus threading, compared with CPython 3.15.2.

  • The extended stdlib_io.py and stdlib_os.py fail on an unpatched build of that commit (TypeError: Expected type bool, not NoneType) and pass with the patch and under CPython 3.15.2.
  • A falsy object, an object whose __bool__ raises, a str and 0 give the same result as CPython 3.15.2 for translate, closefd, blocking and inheritable.
  • rustpython -m test test_io test_os: 1,592 run, 202 skipped, all pass, as on the unpatched build.
  • cargo fmt --check clean, cargo clippy -p rustpython-vm -p rustpython-stdlib --all-targets reports nothing new, and the pre-commit hooks other than cspell and prettier pass on the changed files.

I used Claude Code (claude-fable-5-2) to draft the analysis, the patch and this description; Claude Code ran the commands above; I reviewed the diff and their output.

Summary by CodeRabbit

  • New Features
    • I/O newline-decoder options and file-closing controls now accept boolean-like values, including None and strings.
    • POSIX blocking and descriptor-inheritance options now accept boolean-like values, such as None and truthy strings.
  • Bug Fixes
    • Omitted options retain their expected defaults: newline decoding is non-final by default, and file descriptors are closed by default.

coderabbitai
Bot
commented Nov 17, 2026 · edited Loading



Copy link Copy Markdown
Contributor

No actionable comments were generated in the recent review.

Walkthrough

Selected IO and POSIX flag arguments now use ArgIntoBool. The code converts those arguments before storing values or calling host functions. Tests cover newline decoding, file descriptor ownership, blocking state, and inheritable state.

Changes: Standard-library boolean arguments

Layer / File(s) Summary
IO decoder and file flags
crates/vm/src/stdlib/_io.rs, extra_tests/snippets/stdlib_io.py
Newline-decoder arguments and FileIO.closefd use ArgIntoBool. The decoder's omitted final argument defaults to false, and closefd defaults to true. Tests cover None, "yes", and True values.
POSIX descriptor flags
crates/vm/src/stdlib/posix.rs, extra_tests/snippets/stdlib_os.py
posix.set_blocking and posix.dup2 parse their flag arguments with ArgIntoBool. Tests check blocking and inheritable states for the supplied values.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Possibly related issues

Suggested reviewers: youknowone, youknowdot

Merge Risk: Minimal · up to dc38d

The change makes these io and os flag arguments use Python truth-value conversion, matching CPython. The behavior change is narrow and covered by new tests. The only remaining concern is an obscure os.dup2 case involving a hostile __bool__ method. It does not warrant blocking the merge.

Pre-merge checks: 4

Check name Status Explanation
Description Check Check skipped - CodeRabbit's high-level summary is enabled.
Title check The title names the change: positional bool arguments in the io and os modules are converted by truth value. The raw summary and PR objectives confirm this is the main change. The affected arguments a...
Linked Issues check Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: positional bool arguments in the io and os modules are converted by truth value. The raw summary and PR objectives confirm this is the main change. The affected arguments are IncrementalNewlineDecoder translate, decode final, FileIO closefd, os.set_blocking blocking, and os.dup2 inheritable, all bound as ArgIntoBool. The title is specific and matches the changeset, so the check passes.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 4e52c26 and dc38dc6 .

Files selected for processing: 4

  • crates/vm/src/stdlib/_io.rs
  • crates/vm/src/stdlib/posix.rs
  • extra_tests/snippets/stdlib_io.py
  • extra_tests/snippets/stdlib_os.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Convert positional bool arguments in io and os by truth value dc38dc6
IncrementalNewlineDecoder(translate), its decode(final),
FileIO(closefd), os.set_blocking and os.dup2(inheritable) accepted only
int instances and raised TypeError for any other object. Bind them as
ArgIntoBool so every object is converted by its truth value.

Assisted-by: Claude Code:claude-fable-5-2
jseop-lim force-pushed the fix/io-os-bool-arg-truthiness branch from 26f81de to dc38dc6
Compare
November 26, 2026 05:10 jseop-lim marked this pull request as ready for review November 26, 2026 05:10

chatgpt-codex-connector
Bot
commented Nov 26, 2026 · edited Loading



Copy link Copy Markdown
Codex Review Summary : ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T05:15:10.706253Z dc38dc6 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.

chatgpt-codex-connector
Bot
reviewed Nov 26, 2026
View reviewed changes

chatgpt-codex-connector
Bot
left a comment



Copy link Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dc38dc623b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/vm/src/stdlib/posix.rs
#[pyarg(any, default = true )]
inheritable: bool ,
#[pyarg(any, default = ArgIntoBool::TRUE )]
inheritable: ArgIntoBool ,
Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment

Labels

None yet

1 participant