Skip to content

Return the correct bytes reconstruction arguments - #9326

Merged
youknowone merged 1 commit into
RustPython:mainfrom
1ndahous3:bytes_newargs
Oct 23, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
1ndahous3:bytes_newargs

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Return a one-element tuple containing base bytes from bytes.__getnewargs__, instead of a tuple of individual byte values.
  • Reuse exact bytes and convert subclasses without invoking their overrides.

Performance

Windows 11 x64

Operation Main Patch Speedup
getnewargs, 4 KiB bytes 6.93 µs 0.17 µs 41.6×

Debian 13 amd64

Operation Main Patch Speedup
getnewargs, 4 KiB bytes 7.55 µs 0.14 µs 53.9×

AI assistance

Written with Codex (GPT-6), reviewed by a human before submission.

Summary by CodeRabbit

  • Bug Fixes
    • bytes.__getnewargs__() now returns a one-item tuple containing the bytes object, instead of a tuple of its integer values. This preserves the bytes payload when the method’s result is used to reconstruct a bytes object, including for bytes subclasses.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 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-23T06:38:30.808930Z f50601c PR opened
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between e5554e2 and f50601c.

📒 Files selected for processing: 2
  • crates/vm/src/builtins/bytes.rs
  • extra_tests/snippets/builtin_bytes.py

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

📝 Walkthrough

bytes.__getnewargs__ now returns a one-element tuple containing the bytes payload. Tests cover both bytes and a subclass.

Changes: Bytes new-argument behavior

Layer / File(s) Summary
Update and test bytes new arguments
crates/vm/src/builtins/bytes.rs, extra_tests/snippets/builtin_bytes.py
__getnewargs__ now consumes its receiver and returns the payload in a one-element tuple. Tests check the tuple contents and confirm its element has exact type bytes for a base instance and a subclass.

Priority: ➖ Normal

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

Change: Bug fix

Suggested reviewers: youknowone

Merge Risk: ⚪ Minimal · up to f5060

No concrete current-head correctness or operational risk is evidenced; the change is mergeable.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Return the correct bytes reconstruction arguments" matches the main change. The PR changes bytes.getnewargs to return a one-element tuple holding the bytes object, instead of a tuple of…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Return the correct bytes reconstruction arguments" matches the main change. The PR changes bytes.getnewargs to return a one-element tuple holding the bytes object, instead of a tuple of integer byte values. The title names the reconstruction arguments, which is the core behavior. It does not mention the performance gain or the subclass handling, which is acceptable for a title.

✨ 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.

@youknowone
youknowone merged commit fd3c3fc into RustPython:main Oct 23, 2026
21 checks passed
@1ndahous3
1ndahous3 deleted the bytes_newargs branch October 25, 2026 09:34
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