Align patches at test_types.py#8126
Conversation
📝 WalkthroughWalkthrough
Changes_TextIOBase stubs and newlines getter
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/io.py dependencies:
dependent tests: (108 tests)
[x] lib: cpython/Lib/types.py dependencies:
dependent tests: (57 tests)
Legend:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/vm/src/stdlib/_io.rs`:
- Around line 807-810: The readline method in _TextIOBase is missing an optional
size parameter in its signature. Update the readline method to accept an
optional size argument (which can be of type i32 or similar numeric type with a
default value) while keeping the implementation unchanged. This ensures that
calls like readline(1) will properly pass the argument to the method rather than
causing a TypeError, allowing the _unsupported call to handle it with the
correct UnsupportedOperation error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: cb0c7ea7-91e6-48fe-ae33-086e59215c6f
⛔ Files ignored due to path filters (2)
Lib/test/test_memoryio.pyis excluded by!Lib/**Lib/test/test_types.pyis excluded by!Lib/**
📒 Files selected for processing (1)
crates/vm/src/stdlib/_io.rs
| #[pymethod] | ||
| fn readline(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult { | ||
| _unsupported(vm, &zelf, "readline") | ||
| } |
There was a problem hiding this comment.
_TextIOBase.readline is missing the optional size argument
At Line 808, this method currently accepts no size parameter, which changes Python-call behavior (readline(1) can fail with TypeError instead of UnsupportedOperation). Keep the signature compatible and ignore the arg in the stub.
Proposed fix
- fn readline(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult {
+ fn readline(zelf: PyObjectRef, _size: OptionalArg, vm: &VirtualMachine) -> PyResult {
_unsupported(vm, &zelf, "readline")
}🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/vm/src/stdlib/_io.rs` around lines 807 - 810, The readline method in
_TextIOBase is missing an optional size parameter in its signature. Update the
readline method to accept an optional size argument (which can be of type i32 or
similar numeric type with a default value) while keeping the implementation
unchanged. This ensures that calls like readline(1) will properly pass the
argument to the method rather than causing a TypeError, allowing the
_unsupported call to handle it with the correct UnsupportedOperation error.
There was a problem hiding this comment.
this might not be intentional, I've asked at python/cpython#151596
There was a problem hiding this comment.
@ShaharNaveh, interesting find! The CPython issue confirms this is an upstream inconsistency. That said, applying the fix proactively in RustPython is still worthwhile — it costs nothing (the arg is just ignored) and future-proofs the implementation against code that passes a size argument. If CPython eventually fixes #151596, RustPython will already be aligned.
(ᵔᴥᵔ)
✏️ Learnings added
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 8126
File: crates/vm/src/stdlib/_io.rs:807-810
Timestamp: 2026-06-17T10:32:36.012Z
Learning: In `crates/vm/src/stdlib/_io.rs`, `_TextIOBase.readline` in both CPython and RustPython is missing the optional `size` parameter. CPython tracks this as a bug in https://github.com/python/cpython/issues/151596. The fix is to add `_size: OptionalArg` to the stub signature while keeping the `_unsupported` implementation unchanged.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
Summary
Summary by CodeRabbit