Make Packet pull its weight: type indexing, hashing, delete .payload - #130
Merged
Conversation
Packet[TCP] returns the first matching layer in wire order (KeyError on no match); Packet.get(TCP) returns None instead. packet[0] keeps indexing positionally — __getitem__ branches on int vs type. Packet.__hash__ mirrors exactly what __eq__ already compares (layers, and stopped_by's type + str(), not identity, since ProtocolError has no custom __eq__), so Packet is now usable as a dict key or set member. BREAKING: Packet.payload is deleted outright. It was always exactly bytes(self), a redundant duplicate of __bytes__/bytes(packet), which is the unambiguous spelling. This is the breaking change behind the 2.0.0 major bump. Closes#90. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SVCFe7B1U5VeJRoUbx24vb
Adds the packet[TCP] / packet.get(TCP) example alongside the existing packet[1] positional one in the decode_frame() walkthrough (#90). Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SVCFe7B1U5VeJRoUbx24vb
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Sep 4, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes#90.
Packetgains type-keyed access and becomes hashable; the redundant.payloadproperty is deleted, which is the breaking change behind the 2.0.0 major bump (Tier 2, #104).What's included
Packet.__getitem__branches onint(unchanged positional indexing) vs. a protocol type (packet[TCP]returns the first matching layer in wire order,KeyErroron no match).Packet.get(TCP)— same lookup, returnsNoneon no match instead of raising (dict-like.get()convention).Packet.__hash__, mirroring exactly what the existing__eq__compares (layers, andstopped_by's type andstr(), not identity —ProtocolErrorhas no custom__eq__).Packetis now usable as a dict key or set member.Packet.payloadis deleted outright (not deprecated). It was always exactlybytes(self), a redundant duplicate of__bytes__/bytes(packet), which is the unambiguous spelling and already existed.tests/test_packet.py: type-key hit/miss, int-key hit/miss (unchanged),.get()hit/miss, hash consistency with==(equal packets hash equal,stopped_bychanges the hash),Packetas a dict key / set member,.payloadraisesAttributeError.CHANGELOG.mdentry under## [Unreleased](### Removedfor the breaking change,### Addedfor the new capabilities).Verification
uv run --frozen ruff check .anduv run --frozen ruff format --check .are cleanuv run --frozen mypyis clean (strict)uv run --frozen pytestpasses locallyuv run --frozen python scripts/benchmark.py --check --threshold 15— within threshold (+35.2% vs. baseline)CHANGELOG.mdhas an entry under## [Unreleased]No new protocol/dispatch change, so that checklist block doesn't apply.
Notes
Per the roadmap's working agreement (#107), this is the first of three remaining Tier 2 issues (#90 → #89 → #92) — merged one at a time, not auto-merged.
🤖 Generated with Claude Code
https://claude.ai/code/session_01SVCFe7B1U5VeJRoUbx24vb
Generated by Claude Code