Skip to content

Align text and bytes argument and buffer controls - #9698

Merged
youknowone merged 4 commits into
RustPython:mainfrom
youknowdot:fix/text-bytes-controls-20261104
Nov 6, 2026
Merged

youknowone merged 4 commits into
RustPython:mainfrom
youknowdot:fix/text-bytes-controls-20261104

Conversation

@youknowdot

@youknowdot youknowdot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Group related CPython 3.15 text/bytes controls in 357 substantive changed lines (+200/-157):

  • Share startswith/endswith argument conversion and validate affix items before invalid-range short-circuits, preserving tuple success short-circuiting and exporter errors.
  • Reuse one borrowed bytes/buffer helper for bytes affixes and translation, including direct bytes-subclass access where CPython bypasses buffer overrides.
  • Make bytes/bytearray maketrans use the last mapping for duplicate source bytes and the native length-error diagnostic.
  • Preserve bytes.translate table/delete buffer acquisition, mutation visibility and release order. Return unchanged exact bytes by identity while normalizing subclasses.
  • Validate bytes results before fallback conversion and fix exact bytes.bytes identity.

Four production Rust files only. No Python, Lib, test, expected-failure marker or workflow changes. Partition/rpartition remain unchanged: pinned CPython intentionally retains the supplied separator object.

Reference and validation

Compared with CPython commit d220409a13b77de7a6c30abe16ea90db01528edc: bytes implementation, bytes helpers, and Unicode implementation.

50,330 bounded CPython/source-model assertions and 12,028 independent assertions passed. Coverage includes Unicode/surrogate bounds, tuple item validation, repeated mappings, bytes/bytearray consumers, exact/subclass identities and PEP 688 buffer acquisition/release callbacks with mutation and error paths. These are reference/model checks, not Rust implementation execution.

Independent exact-source review passed, including the final two lazy-default Clippy corrections. Bytearray #9694 composition passed git apply --check. Final focused host-env/VM/stdlib threading cargo check, normal all-targets Clippy and ordinary commit hooks passed. Clippy emitted exactly four unchanged main-baseline diagnostics: one POSIX needless-collect and three ElementTree lints. Strict -D warnings remains blocked by that baseline; no warnings were suppressed.

Native RustPython execution was not performed because the required execution guard has not been verified. Full workspace/C-API suites and cross-platform runtime validation remain unrun. Hosted CI is required; no expected failure is claimed resolved without runtime evidence.

Remaining limits

The existing qualified-type-name formatter does not preserve surrogate-containing type metadata. Generic binder diagnostics and pre-existing bytearray translation/export behavior outside these shared changes remain unchanged. Older architecture/GC/fallible-allocation PRs overlap some files and may need later textual reconciliation; no duplicate behavior fix was found in the 210-PR overlap audit.

AI-assisted contribution by OpenAI Codex, disclosed in the commit trailer.

Shared type-name compatibility

The bytes constructor diagnostic uses the existing WTF-8 concatenation helper so it remains lossless when composed with #9700. Other text/bytes control-flow changes are byte-identical to the previously reviewed head. Independent in-memory composition review verified the exact previous head plus this narrow formatting change. Final focused host-env/VM/stdlib threading check, normal all-targets Clippy and ordinary hooks passed; the same four unchanged baseline diagnostics remain. No new runtime execution or test changes are claimed.

Share affix validation and buffer access while preserving translation callbacks, duplicate mappings, and bytes conversion identities.

Assisted-by: OpenAI Codex:model version not exposed
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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

Use the shared lossless concatenation helper so the qualified-name migration composes without restoring Rust Display formatting.

Assisted-by: OpenAI Codex:model version not exposed
@codspeed

codspeed Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:fix/text-bytes-controls-20261104 (b72e268) with main (3485237)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Preserve both buffer and bytes-or-string argument imports while integrating the upstream hex separator conversion.

Assisted-by: OpenAI Codex:model version not exposed
Extract the CPython-style deletion table and application into one pure
helper used by bytes.translate and bytearray's existing slice helper.
Keep acquisition, release ordering, allocation policy, and bytes identity
handling in their existing callers. Preserve the direct zero/single-byte
delete loop instead of paying for another table in those cases.

Assisted-by: OpenAI Codex:model version not exposed
@youknowone
youknowone marked this pull request as ready for review November 6, 2026 11:23
@youknowone
youknowone merged commit 5d5d59e into RustPython:main Nov 6, 2026
18 of 20 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-06T11:23:57.961558Z
We couldn’t complete this review. Comment @codex review to try again.
f539764 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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

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