Skip to content

Accept contiguous bytes-like input in pyexpat.Parse - #9187

Open
1ndahous3 wants to merge 1 commit into
RustPython:mainfrom
1ndahous3:pyexpat_byteslike
Open

1ndahous3 wants to merge 1 commit into
RustPython:mainfrom
1ndahous3:pyexpat_byteslike

Conversation

@1ndahous3

@1ndahous3 1ndahous3 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Found while parsing buffered XML with xmltodict 1.0.4 and defusedxml 0.7.1.

Summary

  • Accept contiguous buffer objects, including bytearray and memoryview, in pyexpat.Parse().
  • Preserve buffer conversion errors and keep the input export alive while callbacks run.

AI assistance

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

Summary by CodeRabbit

  • New Features
    • pyexpat.Parse now accepts contiguous bytearray and memoryview inputs in addition to strings and bytes.
  • Bug Fixes
    • Non-contiguous memoryviews raise BufferError. Resizing an input bytearray during a parsing callback also raises BufferError; the bytearray can be resized once parsing finishes.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 18, 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-18T08:58:36.435643Z 8908683 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 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: RustPython/RustPython/.coderabbit.yml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5903df95-e7d3-47ff-a63e-6f589f767217
📥 Commits

Reviewing files that changed from the base of the PR and between 9f6f771 and 8908683.

📒 Files selected for processing: 2
  • crates/stdlib/src/pyexpat.rs
  • extra_tests/snippets/stdlib_pyexpat.py

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

📝 Walkthrough

PyExpatLikeXmlParser.Parse now accepts ArgStrOrBytesLike and obtains input bytes with borrow_bytes(). Tests cover contiguous buffers, non-contiguous memoryviews, and bytearray resizing during and after parsing.

Changes: Expat parser input

Layer / File(s) Summary
Parse buffer input
crates/stdlib/src/pyexpat.rs, extra_tests/snippets/stdlib_pyexpat.py
Parse accepts ArgStrOrBytesLike and uses borrow_bytes() to obtain input bytes. Tests cover contiguous bytearray and memoryview inputs, rejection of a non-contiguous view, and bytearray resizing during and after parsing.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: youknowone, youknowdot

Merge Risk: ⚪ Minimal · up to 89086

The buffer-input change is ready to merge after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: pyexpat.Parse now accepts contiguous bytes-like input, including bytearray and memoryview.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
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.
✨ 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.

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