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
- Part of Assorted CPython compatibility divergences (18 items) #9913 (item 6)
- This PR follows our AI policy
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,finalandclosefdasArgIntoBoolincrates/vm/src/stdlib/_io.rs, andblockingandinheritableincrates/vm/src/stdlib/posix.rs. Signatures are unchanged. - Add cases to
extra_tests/snippets/stdlib_io.pyandextra_tests/snippets/stdlib_os.py. - Out of scope: the keyword-only flags in
os(follow_symlinks,effective_ids), theclosefdofopen(), whoseOpenArgsis also built from Rust incrates/capi, and what I could not build: the Windows versions innt.rsand_WindowsConsoleIO, and the positionaltarget_is_directoryofos.symlink, which is only read innt.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.pyandstdlib_os.pyfail 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, astrand0give the same result as CPython 3.15.2 fortranslate,closefd,blockingandinheritable. rustpython -m test test_io test_os: 1,592 run, 202 skipped, all pass, as on the unpatched build.cargo fmt --checkclean,cargo clippy -p rustpython-vm -p rustpython-stdlib --all-targetsreports nothing new, and the pre-commit hooks other thancspellandprettierpass 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
Noneand strings. - POSIX blocking and descriptor-inheritance options now accept boolean-like values, such as
Noneand truthy strings.
- I/O newline-decoder options and file-closing controls now accept boolean-like values, including
- 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
dc38d
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
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-2jseop-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.
Your team has set up Codex to review pull requests in this repo . Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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
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 , |