Skip to content

refactor(protocols)!: make() takes an enum member or an int, with no keyword groups (#2594) - #2692

Merged
JarryShaw merged 1 commit into
mainfrom
refactor/2594-make-enum-or-int
Nov 3, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
refactor/2594-make-enum-or-int

Conversation

@JarryShaw

@JarryShaw JarryShaw commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

What is the purpose of your pull request?

  • refactor — changes neither behaviour nor performance

Description of your pull request and other information

The owner's option 1 on #2593 and #2594. A make() field that holds an enum takes the member or an int, resolved with the enum's get. The X_default/X_namespace/X_reversed keyword groups and _make_index's inspection of the caller's frame are removed from every make() and _make_*, SCTP and 802.11 included.

  • Resolver: Protocol._make_index(value, Enum, *, bits, name) checks the code as _make_uint does, then returns the member. A name, a bool wider than one bit, or a code that does not fit raises ProtocolError. This settles refactor(protocols)!: range-check the registry codes, timestamp counts and byte fields the makers still mask #2676's first bullet: IPv4(protocol=256) and IPv6_Route(next=256) raise where they wrote 0x00. The enum's own range is not applied: a code that fits its field resolves to the member get gives, which minting registries create, or to an int where get refuses. Captures with unassigned codes therefore still rebuild.
  • Strings: callers holding a string use the new public Protocol.resolve_index(name, default=None, *, namespace, reversed=False), which pep.rst describes.
  • Docs: classes that shipped the keywords get versionchanged and versionremoved notes.
  • Option-list codes in MH, IPv4, HIP, TCP, DCCP, SCTP and PCAP-NG go through the same check (fix(protocols): range-check option-list codes in MH, IPv4, TCP, DCCP, SCTP and PCAP-NG makers #2693).
  • Guard: a test fails if a make() regains a group, or if _make_index inspects a frame.

Breaking: the shipped keywords are removed with no deprecation, per the owner's ruling. NGAP criticality no longer takes a str. HTTPv1(status=404) writes 404 Not Found, where it used to write 404 ; an unassigned status writes its registry phrase.

Every leg passes, apart from the CI-script failures main has too, with the same ids. Shipped captures parse identically to main.

Closes #2594
Closes #2693

@JarryShaw JarryShaw added this to the PyPCAPKit v1.6 milestone Nov 2, 2026
@JarryShaw JarryShaw added breaking Breaks public-facing behaviour or API (apply alongside the type label) refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Nov 2, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Nov 2, 2026
@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment and removed review: running A cross-review is in flight against the current head - no verdict yet labels Nov 2, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

NEEDS CHANGES at 22fb952d3, from a sharded Sonnet review with an Opus check of each finding. The core holds: no groups or frame inspection remain, every _make_index site refuses out-of-range values, a bool and a name, and captures rebuild exactly. What has to change:

  1. Regression: _make_index also applies the enum's own range, so HIP transport mode, HIT suite list, MH UPN reason and FBM fb_type refuse codes that fit their wire field. Keep only the width check plus get.
  2. Option-list codes are still masked in MH and IPv4 (and in TCP, DCCP, SCTP and PCAP-NG, per fix(protocols): range-check option-list codes in MH, IPv4, TCP, DCCP, SCTP and PCAP-NG makers #2693). Range-check them the way HOPOPT does. This folds fix(protocols): range-check option-list codes in MH, IPv4, TCP, DCCP, SCTP and PCAP-NG makers #2693 into this PR.
  3. Prose: a code no member holds comes back as a minted member where the registry mints, and as an int only where get refuses. Fix this in _make_index, registry-protocol.rst and the body. Drop the timed context in resolve_index, pep.rst, the dumpkit NOTE and the test docstrings.
  4. Tests: PCAPIO(protocol='ETHERNET') has no test; add one, with an unknown name. Type HTTP/2 settings as Enum_Setting | int.

@JarryShaw
JarryShaw force-pushed the refactor/2594-make-enum-or-int branch from 22fb952 to e7bc62c Compare November 3, 2026 00:29
@JarryShaw JarryShaw added review: running A cross-review is in flight against the current head - no verdict yet and removed review: needs-changes Cross-review at the current head says changes are required; see the verdict comment labels Nov 3, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Pushed the fix round 22fb952d3→e7bc62ce5, rebased onto 57a6c366d. Every finding from the sharded review is addressed:

  • _make_index drops the enum-range check, so HIP Transport, HITSuite, MH UPN and FBM codes build up to their field width.
  • Option-list codes are range-checked in every family. This closes fix(protocols): range-check option-list codes in MH, IPv4, TCP, DCCP, SCTP and PCAP-NG makers #2693, and MH _make_msg_be now takes BindingError.
  • The prose is corrected: a minting registry returns a member, and only an enum whose get refuses returns an int. Timed wording is removed.
  • New: a PCAPIO link-type-name test, and HTTP/2 settings typed Enum_Setting | int.

A Sonnet re-review is running.

@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment and removed review: running A cross-review is in flight against the current head - no verdict yet labels Nov 3, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

NEEDS CHANGES at e7bc62ce5, for prose only, from a Sonnet re-review. Every code fix holds:

  • the four fields build up to their field width;
  • all 114 _make_index sites refuse out-of-width values, -1, True and names;
  • option-list codes are range-checked in every family, in both branches;
  • shipped captures rebuild byte-exactly.

Timed words remain in four test docstrings and comments: test_hip_list_argument_str_names_2394_unit.py ("before #2594" twice, "before #2394") and test_protocol_base_unit.py ("the old keyword group"). Restate each as what holds now.

…keyword groups (#2594)

- _make_index: takes (value, enumeration, bits=, name=), checks the code as
  _make_uint does, and returns what get resolves; where get raises for a code
  the field carries, the code comes back as an int. The field width alone
  decides a refusal. The frame inspection and its helpers go.
- Protocol.resolve_index: public helper taking the name/default/namespace/
  reversed group explicitly, for a caller holding a name.
- Every make() and _make_* maker, and every (code, arguments) option,
  sub-option, extension and chunk list: the groups are removed with no shim,
  each enumeration field is typed Enum | int and resolved by _make_index; a
  name, a wide bool or a code its field cannot carry raises ProtocolError.
  Also SCTP, DCCP, NGAP, IGMPv3, IPv6_Ext and the transport ports, and MH
  Binding Error's status, typed BindingError.
- Breaking: an int HTTP/1 status with no message writes its member's phrase,
  as a member did: 404 writes "404 Not Found" where it wrote "404 ", and a
  code the registry does not assign writes its minted member's phrase
  ("299 Unassigned", "600 Unknown").
- Docs: versionchanged/versionremoved on every class that shipped the
  keywords; pep.rst and registry-protocol.rst record the rule.
- Tests: a guard against the groups and frame inspection, refusal tables per
  family and a PCAP dumper test that fail on main; name-inference tests
  rewritten.

Every tests/ leg matches main's results.

Closes #2693
@JarryShaw
JarryShaw force-pushed the refactor/2594-make-enum-or-int branch from e7bc62c to 3d1dea6 Compare November 3, 2026 00:49
@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: needs-changes Cross-review at the current head says changes are required; see the verdict comment labels Nov 3, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

GOOD TO GO at 3d1dea6f1. This amend changes comments and docstrings only; I checked that all seven changed files have identical syntax trees once docstrings are stripped. The four flagged test docstrings, and a few other timed phrases in the touched files, now state what holds. The re-review confirmed every code fix:

  • the four fields build up to their field width;
  • all 114 _make_index sites refuse out-of-width values, -1, True and names;
  • option-list codes are checked in every family;
  • captures rebuild byte-exactly.

Merging this first will make the other protocol PRs cheaper to rebase.

@JarryShaw
JarryShaw merged commit a78e0c5 into main Nov 3, 2026
60 checks passed
@JarryShaw
JarryShaw deleted the refactor/2594-make-enum-or-int branch November 3, 2026 02:10
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Nov 3, 2026
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Nov 3, 2026
JarryShaw added a commit that referenced this pull request Nov 3, 2026
… helpers, MH options 6 and 27, the cut SCTP and option-area schemas and dict-built secrets into 1.6.0 (#2449)

- Breaking: a make() enumeration field takes a member or an int, its
  X_default/X_namespace/X_reversed keywords removed with no alias, and names,
  wide codes and wide option codes are refused (#2692); the schema helpers
  move to pcapkit.corekit.schema and pcapkit.corekit.fields.byteorder is
  removed (#2704); MobileNetworkPrefixOption gains prefix_length and keeps an
  IPv6Address prefix, and TimestampOption's timestamp is None past 9999
  (#2709). Folded into the MH data-model entry; old values measured against
  v1.5.1.
- Fixed: the SCTP schema cut inside its padding and a header schema cut
  inside an option area pack back as captured (#2682), into the SCTP entry;
  a Decryption Secrets Block rebuilds from its dict as captured (#2707), into
  the DSB entry.
- Folded into unreleased entries: FRAD's Q.922 address refusal and quiet cut
  rebuild (#2719); a from_data rebuild's checksum status (#2712); a failed
  ListField fill's ledger (#2706); pad_length's path (#2704); TLS's enumeration
  fields (#2692); the make() and schema-helper rulings, into the conventions
  entry (#2692, #2704); the GraalPy shards, into the CI-legs entry (#2720).
- 1.5.0's corekit.fields.byteorder role points at corekit.schema.byteorder,
  where #2704 moved it, so the nitpicky build does not warn on it; 1.5.0's
  text unchanged.
- No entry for the test-only 72b2bd8 (#2715), or the docs-and-test-only
  0c07940 (#2718).
- CHANGELOG.md regenerated; util/changelog_md.py --check passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaks public-facing behaviour or API (apply alongside the type label) refactor Restructuring for its own sake — neither a fix nor a new capability (refactor: prefix)

Projects

Status: Done

1 participant