Skip to content

Support slicing header sequences - #209

Open
xiehuanyi wants to merge 2 commits into
python-hyper:masterfrom
xiehuanyi:fix-header-sequence-slicing
Open

xiehuanyi wants to merge 2 commits into
python-hyper:masterfrom
xiehuanyi:fix-header-sequence-slicing

Conversation

@xiehuanyi

Copy link
Copy Markdown

The Headers sequence exposed through Request.headers and other events currently treats slice indices as integer indices. A one-element or empty slice raises ValueError; a three-element slice returns internal three-tuples rather than the public (name, value) pairs.

Handle slices by returning a new Headers instance with the selected entries. This keeps normalized byte-pair iteration and original header-name casing available through raw_items(). Integer indexing and wire parsing retain their existing behavior.

Validation on Python 3.12.3: five regression cases fail against upstream (ordinary, exactly three elements, empty, reverse and stride slices); all 83 project tests pass with the fix. Black, isort and mypy checks pass. The changed header module has 100% coverage. Added a news fragment, to be renamed to this PR's number immediately after creation as described in the contributing guide.

Prepared with AI assistance and independently reviewed before submission.

Copilot AI balanced review requested due to automatic review settings October 11, 2026 12:17

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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