Skip to content

Preserve bytes subclasses when encoding headers - #300

Draft
AryanRG wants to merge 1 commit into
python-hyper:masterfrom
AryanRG:fix/preserve-bytes-subclass-headers
Draft

AryanRG wants to merge 1 commit into
python-hyper:masterfrom
AryanRG:fix/preserve-bytes-subclass-headers

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 16, 2026 •

Copy link
Copy Markdown

Encoder.encode() silently changes header names and values supplied as ordinary bytes subclasses. For example, a subclass containing b'custom-key' is encoded as the literal text b"b'custom-key'". A subclass dictionary key containing b':method' also stops being recognized as a pseudo-header.

Use isinstance(value, bytes) in _to_bytes() to preserve the original bytes. This restores the subclass behavior that preceded the performance optimization in #276. Remove the two type ignores made unnecessary by the resulting type narrowing.

Seven regression cases cover empty and non-UTF-8 bytes, exact wire encoding and decoding in both Huffman modes, and dictionary pseudo-header ordering. All seven fail on the original source. The independent reviewer also reproduced all seven failures using the original conversion function.

Validation on macOS:

  • Upstream baseline: 502 tests passed, 100% statement and branch coverage on Python 3.13.12.
  • Candidate: 509 tests passed with 100% statement and branch coverage on Python 3.11.16, 3.12.15, 3.13.12 and 3.14.4.
  • Ruff, strict mypy, git diff --check, check-manifest, wheel/sdist builds and twine check passed.
  • HTML documentation build succeeded with the existing unresolved our github page target at docs/source/installation.rst:10. Existing Hypothesis initialization warnings remain.
  • Separate automated AI review: no blockers, with 8 focused tests, Ruff, mypy and whitespace checks independently passing.

AI disclosure: the implementation, regression tests and this description were developed by AI agents. A separate AI agent performed an automated review. No human review is claimed; this PR is a draft pending maintainer review. Hosted CI is not yet verified.

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