Skip to content

Preserve HeaderTuple fields when copying or pickling - #301

Open
AryanRG wants to merge 1 commit into
python-hyper:masterfrom
AryanRG:fix/header-tuple-pickling
Open

AryanRG wants to merge 1 commit into
python-hyper:masterfrom
AryanRG:fix/header-tuple-pickling

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 17, 2026

Copy link
Copy Markdown

Summary

Preserve the two fields of HeaderTuple and NeverIndexedHeaderTuple when they are copied or serialized. The inherited tuple reconstruction hook passes the entire pair as one argument to these classes' variadic constructor; copying or pickling therefore nests the pair, and re-encoding a copied decoded header can raise IndexError.

__getnewargs__() now supplies the two fields as separate constructor arguments. The change also adds copy, deepcopy, pickle-protocol, and decode–copy–encode regressions, plus a changelog entry.

Validation

  • The new regression selection has 14 failures and 4 passing controls on the base; all 18 pass with this patch.
  • Full local suite: 520 passed each on Python 3.11, 3.13, and 3.14, with 100% reported statement/branch coverage.
  • Ruff, strict mypy, and whitespace checks pass. Other platforms, hosted CI, packaging, and documentation builds remain unverified.
  • Existing malformed pickles are not repaired.

AI assistance was used to prepare the implementation, tests, and this description.

@agammann agammann 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.

__getnewargs__ supplies the tuple’s two fields as separate arguments to HeaderTuple.__new__, so copy and pickle reconstruct both values instead of nesting them as one item. The tests cover both concrete header classes, shallow and deep copy, every pickle protocol, and re-encoding a copied decoder result. I reviewed the patch and tests; I did not run them locally.

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