Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Feb 11, 2026

Summary by CodeRabbit

  • New Features

    • Added resize() to PyByteArray.
    • Added getbuffer() to BytesIO.
    • BytesIO constructor now accepts an optional initial-bytes argument for direct buffer initialization.
  • Bug Fixes

    • Prevent negative-relative seeks from moving before the buffer start.
    • Close now prevents closing when exports exist and returns proper errors for closed IO.
  • Chores

    • Marked io module dependency on _pyio.py and minor dependency/path updates.
    • UnsupportedOperation now carries correct module metadata for introspection.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds PyByteArray::resize, refactors BytesIO initialization to use BytesIOArgs, tightens BytesIO seek/close/getbuffer semantics (including closed/export checks), sets UnsupportedOperation.module, and records _pyio.py as a hard dependency in update_lib tooling.

Changes

Cohort / File(s) Summary
ByteArray
crates/vm/src/builtins/bytearray.rs
Added PyByteArray::resize(size: isize, vm: &VirtualMachine) -> PyResult<()> — validates non-negative sizes, raises ValueError for negatives, resizes internal buffer and zero-fills new bytes.
BytesIO & IO types
crates/vm/src/stdlib/io.rs
Introduced BytesIOArgs and changed BytesIO::init to accept it; adjusted seek to clamp negative relative seeks; changed close(&self)close(&self, vm: &VirtualMachine) -> PyResult<()> with export-count guard; added getbuffer() returning PyMemoryView with closed-state check; set UnsupportedOperation.__module__ = "io".
update_lib tooling
scripts/update_lib/cmd_quick.py, scripts/update_lib/deps.py
Switched dep_lib_path construction to pathlib.Path("Lib") / dep_name; added _pyio.py as a hard dependency for the io module in dependency mappings.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I nibble bytes and stretch each line,

Resize the heap with hops divine.
No seeking past the start, I say—
Close with care, keep exports at bay.
Memory views gleam in carrot-ray 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and incomplete, using generic phrasing 'and fix' without specifying what is being fixed or updated in the io module. Revise the title to be more specific about the changes, such as 'Add resize method to PyByteArray and enhance BytesIO' or 'Update io module with PyByteArray resize and BytesIO improvements'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

Code has been automatically formatted

The code in this PR has been formatted using:

  • cargo fmt --all
    Please pull the latest changes before pushing again:
git pull origin io

@youknowone youknowone force-pushed the io branch 4 times, most recently from 1924eb7 to 0b79cf4 Compare February 12, 2026 09:29
@youknowone youknowone force-pushed the io branch 2 times, most recently from 34fe444 to 0a3ac12 Compare February 13, 2026 05:10
CPython Developers and others added 3 commits February 13, 2026 14:13
- Add bytearray.resize() method
- BytesIO: support keyword arg for initial_bytes
- BytesIO.seek: clamp negative positions to 0
- BytesIO.close: raise BufferError on active exports
- BytesIO.getbuffer: check closed state
- Set UnsupportedOperation.__module__ to "io"
@youknowone youknowone marked this pull request as ready for review February 13, 2026 06:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@scripts/update_lib/cmd_quick.py`:
- Around line 409-410: The code sets dep_lib_path =
pathlib.Path("crates/pylib/Lib") / dep_name which stages hard dependencies from
the generated location; change it to use the canonical Lib directory by setting
dep_lib_path = pathlib.Path("Lib") / dep_name (matching how lib_file_path is
derived) so hard deps are sourced from Lib/ rather than crates/pylib/Lib; update
any related references in the same block that rely on dep_lib_path to use the
new path variable.

@youknowone youknowone merged commit 743780f into RustPython:main Feb 13, 2026
13 of 14 checks passed
@youknowone youknowone deleted the io branch February 13, 2026 06:20
@github-actions
Copy link
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] lib: cpython/Lib/io.py
[x] lib: cpython/Lib/_pyio.py
[ ] test: cpython/Lib/test/test_io.py (TODO: 25)
[x] test: cpython/Lib/test/test_bufio.py
[ ] test: cpython/Lib/test/test_fileio.py (TODO: 2)
[ ] test: cpython/Lib/test/test_memoryio.py (TODO: 29)

dependencies:

  • io

dependent tests: (87 tests)

  • io: test__colorize test_android test_argparse test_ast test_asyncio test_bufio test_builtin test_bz2 test_calendar test_cmd test_cmd_line_script test_codecs test_compileall test_compiler_assemble test_concurrent_futures test_configparser test_contextlib test_csv test_dbm_dumb test_dis test_email test_enum test_file test_fileinput test_fileio test_ftplib test_getpass test_gzip test_hashlib test_httplib test_httpservers test_importlib test_inspect test_io test_json test_largefile test_logging test_lzma test_mailbox test_marshal test_memoryio test_memoryview test_mimetypes test_optparse test_pathlib test_pickle test_pickletools test_plistlib test_pprint test_print test_pty test_pulldom test_pyexpat test_regrtest test_robotparser test_shlex test_shutil test_site test_smtplib test_socket test_socketserver test_subprocess test_support test_sys test_tarfile test_tempfile test_threadedtempfile test_timeit test_tokenize test_traceback test_typing test_unittest test_univnewlines test_urllib test_urllib2 test_uuid test_wave test_wsgiref test_xml_dom_xmlbuilder test_xml_etree test_xml_etree_c test_xmlrpc test_zipapp test_zipfile test_zipimport test_zoneinfo test_zstd

[x] lib: cpython/Lib/typing.py
[ ] test: cpython/Lib/test/test_typing.py (TODO: 5)
[x] test: cpython/Lib/test/test_type_aliases.py
[x] test: cpython/Lib/test/test_type_annotations.py (TODO: 1)
[x] test: cpython/Lib/test/test_type_params.py (TODO: 10)
[x] test: cpython/Lib/test/test_genericalias.py

dependencies:

  • typing

dependent tests: (13 tests)

  • typing: test_annotationlib test_builtin test_enum test_fractions test_funcattrs test_functools test_genericalias test_grammar test_isinstance test_type_aliases test_type_params test_types test_typing

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

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.

1 participant