Skip to content

Match binascii hex separator validation - #9643

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/binascii-hex-separator-20261103
Nov 7, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/binascii-hex-separator-20261103

Conversation

@youknowdot

Copy link
Copy Markdown
Contributor

Summary

Align binascii.hexlify and b2a_hex separator validation with CPython's bytes-output path. Check the object's length first, then accept a str containing only Latin-1 code points or a bytes object, including subclasses. This permits separators such as b'\xff' and 'é' while rejecting length-one bytearray and memoryview separators. It also preserves the observable __len__ callback and reads the first underlying character or byte when a subclass overrides its reported length.

ASCII strings use the cached kind fast path. For a non-ASCII string subclass that reports length one despite having longer underlying content, checking whether all code points fit in Latin-1 scans the string; CPython caches its internal string width. Generic argument-binding diagnostics, lower-level bytes-per-separator conversion, output-buffer lifetime, and allocation limits are outside this change.

Validation

  • Compared CPython 3.15.0 binascii and pystrhex source and reproduced high-byte/Latin-1 separators, out-of-range characters, buffer rejection, callback ordering and subclasses with overridden __len__.
  • Independent source review, normal commit hooks and diff checks passed.
  • RustPython was not built or executed locally. No tests were added or changed; hosted CI can run existing test_binascii coverage.

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

coderabbitai Bot commented Nov 3, 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

data: ArgBytesLike,
#[pyarg(any, optional)]
sep: OptionalArg<ArgAsciiBuffer>,
sep: OptionalArg<PyObjectRef>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

check this change is necessary after #9563

@youknowone
youknowone marked this pull request as ready for review November 7, 2026 11:58
@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-07T11:58:10.539098Z
We couldn’t complete this review. Comment @codex review to try again.
b3ac819 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.

@youknowone
youknowone merged commit 1f5f5f0 into RustPython:main Nov 7, 2026
20 checks passed
@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