Skip to content

Align bytes and bytearray operations with Python 3.15 - #9165

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/bytes-315-compatibility
Oct 17, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/bytes-315-compatibility

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Extract the remaining bytes/bytearray compatibility fixes from #8954 onto current main:

  • Escape the selected quote consistently in bytearray repr/str.
  • Accept the count keyword in bytes and bytearray replace().
  • Use an unsigned magnitude for hex grouping at the minimum signed integer.
  • Release nonempty bytearray storage on clear(), while preserving an empty exported buffer as a successful no-op.

Refresh test_bytes.py from CPython 3.15.0 through scripts/update_lib. The updater preserves the existing optional C-API import, three Vec-allocation assertion adaptations and their explanation comments, with fail-closed/idempotence tests. All other canonical test bodies remain unchanged. Retire only the two obsolete test_mod expected-failure wrappers after both concrete inheritors passed fresh matching tests.

The added block in the existing bytearray snippet covers only the exported-empty-clear gap; canonical repr, replacement, hex and allocation coverage is not duplicated.

Validation

  • Release test_bytes: 332 tests, 13 existing skips and 10 expected failures; no failures or unexpected successes.
  • CPython 3.15.0 canonical test_bytes oracle: 332 tests, 8 skips.
  • Existing bytearray snippet: focused RustPython pytest selection and standalone CPython 3.15.0 both passed.
  • Updater tooling: 248 tests passed.
  • Normal pre-commit hooks and cargo fmt --all -- --check passed.
  • Strict workspace and separate C-API Clippy (-D warnings) passed.
  • Native workspace: 1,359 passed across 22 harnesses; separate ABI3T C-API: 123 passed, 4 existing ignores.
  • Workspace doctests: 24 passed, 18 existing ignores; C-API has no doctests.
  • Debug canonical hex-boundary selector: both bytes and bytearray passed, including the minimum signed integer.

The full snippets suite was not run locally because it includes AF_UNIX operations restricted in this environment. The focused snippet result is not a full-suite claim; hosted CI must complete the normal full suite for this exact head. No tests were changed to work around that environment restriction.

AI assistance

Implementation, canonical-source comparison, independent source review, and test execution were assisted by OpenAI Codex (model version unavailable).

Correct quote escaping, replacement count keyword binding, signed-minimum hex grouping, and clear storage/export handling. Migrate canonical bytes coverage through fail-closed preservation of the existing RustPython customizations, and retire only two freshly verified formatting guards.

Assisted-by: OpenAI Codex:model version unavailable
@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5f8e3e6b-3849-4ff4-aa72-39597210662a
📥 Commits

Reviewing files that changed from the base of the PR and between 8720306 and 1e9e19b.

⛔ Files ignored due to path filters: 1
  • Lib/test/test_bytes.py is excluded by !Lib/**
📒 Files selected for processing: 5
  • crates/vm/src/builtins/bytearray.rs
  • crates/vm/src/bytes_inner.rs
  • extra_tests/snippets/builtin_bytearray.py
  • scripts/update_lib/cmd_migrate.py
  • scripts/update_lib/tests/test_migrate.py
+-----------------------------------------------+
| Optimization hinders evolution. - Alan Perlis |
+-----------------------------------------------+
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ 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

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

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
:4: SyntaxWarning: invalid decimal literal
:7: SyntaxWarning: "\z" is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\z"? A raw string is also an option.
:10: SyntaxWarning: "\400" is an invalid octal escape sequence. Such sequences will not work in the future. Did you mean "\400"? A raw string is also an option.
[ ] test: cpython/Lib/test/test_bytes.py (TODO: 12)

dependencies:

dependent tests: (no tests depend on bytes)

Legend:

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

@youknowone
youknowone marked this pull request as ready for review October 17, 2026 02:33
@youknowone
youknowone merged commit 19d2fe3 into RustPython:main Oct 17, 2026
22 checks passed
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T02:37:42.905655Z 1e9e19b 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 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: 1e9e19bc8f

ℹ️ 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 Lib/test/test_bytes.py
self.assertEqual(three_bytes.hex(sep=':', bytes_per_sep=2), 'b9:01ef')
self.assertEqual(three_bytes.hex(sep='*', bytes_per_sep=-2), 'b901*ef')
for bytes_per_sep in 3, -3, 2**31-1, -(2**31-1):
for bytes_per_sep in 3, -3, sys.maxsize, -sys.maxsize:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep existing test bodies unchanged

This refresh changes the existing test data in test_hex_separator_basics, and the patch makes similar additions and edits to other test bodies, but the repository's critical test policy forbids modifying assertions, logic, or data and permits test-file edits only for expected-failure marker changes. Keep the canonical test bodies unchanged and restrict this change to the allowed marker edits and runtime implementation.

AGENTS.md reference: AGENTS.md:L276-L282

Useful? React with 👍 / 👎.

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