Skip to content

fix(protocols): resolve a str enum name in makers whose argument defaults to None (#2356) - #2361

Closed
Muhtasim-Munif-Fahim wants to merge 1 commit into
JarryShaw:mainfrom
Muhtasim-Munif-Fahim:fix/make-str-enum-name-none-default-2356
Closed

Muhtasim-Munif-Fahim wants to merge 1 commit into
JarryShaw:mainfrom
Muhtasim-Munif-Fahim:fix/make-str-enum-name-none-default-2356

Conversation

@Muhtasim-Munif-Fahim

Copy link
Copy Markdown

Please follow the guide below

  • Searched for similar pull requests
  • Followed the coding style (make pylint, make mypy, make isort)
  • make test passes, and a test case covers the change
  • Added a changelog entry under docs/source/changelog/ and regenerated CHANGELOG.md, if the change is user-visible

What is the purpose of your pull request?

  • fix — corrects a defect

Description of your pull request and other information

Fixes #2356

_make_index resolves a str name against the enum of the argument's default when no namespace is given. Five makers have arguments that default to None, so a member name had no enum to resolve against and raised ProtocolNotImplemented:

  • HOPOPT / IPv6-Opts _make_opt_mpl: seed_type → falls back to SeedID
  • HOPOPT / IPv6-Opts _make_opt_smf_dpd: tid_type → falls back to TaggerID
  • HTTP/1.* _make_start_line: status → falls back to StatusCode

Each site now passes <arg>_namespace if <arg>_namespace is not None else Enum_X, so an explicit namespace still wins. An AST scan of pcapkit/protocols found no other _make_index call with a None default and no fallback.

Tests: tests/protocols/test_make_str_enum_name_none_default_2356_unit.py checks that a name gives the same octets as the member it names for all five sites, and that an explicit namespace still takes precedence. It fails on main (10 subtests) and passes with the fix. The HOPOPT/IPv6/HTTP test modules fail in the same 8 runtime tests before and after the change (missing local fixtures). pylint/mypy/isort raise nothing new on the changed files; only the counts on existing too-many-locals/too-many-lines warnings went up.

Side note, not changed here: status='CODE_200' (like status=200) gives an empty reason phrase (HTTP/1.1 200 \r\n), while passing StatusCode.CODE_200 gives 200 OK. I can follow up on that if you'd like.


AI-assistance disclosure: I wrote this fix with help from an AI coding assistant. I reviewed the change and ran the tests and linters above myself.

…ults to None (JarryShaw#2356)

The MPL option's seed_type and the SMF_DPD option's tid_type makers (of
both HOPOPT and IPv6-Opts), and the HTTP/1.* start line's status, passed
their None default's (absent) enum to _make_index, so a str member name
raised ProtocolNotImplemented. Fall back to the argument's own enum when
no namespace is given, and pin name/member parity with a unit test.
@JarryShaw JarryShaw added the review: running A cross-review is in flight against the current head - no verdict yet label Oct 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner

Review: NEEDS CHANGES at d222b1d45 (Sonnet). Thanks — the fix itself is correct and complete; the test file needs a few additions.

1. Reword the module docstring. "They now fall back…" and the "raised … for a name such as 'IPv4'" framing are change-relative wording this repo's test prose avoids. "A name builds the same octets as the member it names" is also not quite true for HTTP — see #5 below.

2. test_an_explicit_namespace_still_wins only covers 2 of the 5 fixed sites (the two _make_opt_mpls). Please extend it to tid_type_namespace (both _make_opt_smf_dpds) and status_namespace (HTTP), so an explicit namespace overriding the fallback is pinned everywhere the fix touches.

3. Recommended, not required: a case that an unknown name still raises ProtocolNotImplemented, and one where a valid name beats a conflicting *_default.

Verified independently:

  • All five call sites named in fix: several makers reject a str enum name when their argument defaults to None #2356 are fixed (two bullets each covered both modules); an AST scan of all 112 _make_index calls in pcapkit/ found no other single-valued argument with this gap.
  • Invalid names still raise correctly, explicit namespaces still win, and nothing regressed (308 vs. 304 passed on the nearest-tests selection, +4 being exactly the new tests; 390 passed / 21 skipped on the convention guards, identical on both trees).
  • Fail-without-fix: 10 failed on origin/main. On the head, 4 passed, 12 subtests. Leave-one-out confirms each site is individually pinned.

One correction for the PR body: it says #2350 is merged — it's still open (review: good-to-go, not yet landed).

#5, disclosed in the PR body and not a blocker: status='CODE_404' gives a blank reason phrase (HTTP/1.1 404 \r\n) where the enum member gives Not Found. Pre-existing for status=404 too.

Follow-up, not blocking: HIP's list-form makers (groups, suite, cipher, reg, tf, mode) have the same str-name gap in a different shape (list items, not a single value) — worth its own issue if you'd like to file it.

@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 Oct 27, 2026
@github-actions github-actions Bot added this to the PyPCAPKit v1.5 milestone Oct 27, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 27, 2026
@JarryShaw

Copy link
Copy Markdown
Owner

Closing — the fix this duplicated (#2356) is already resolved on main by our own #2393, which merged.

@JarryShaw JarryShaw closed this Oct 27, 2026
@JarryShaw JarryShaw removed the review: needs-changes Cross-review at the current head says changes are required; see the verdict comment label Oct 27, 2026
@github-project-automation github-project-automation Bot moved this from In review to Done in PyPCAPKit Oct 27, 2026
@github-actions github-actions Bot removed this from the PyPCAPKit v1.5 milestone Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix: several makers reject a str enum name when their argument defaults to None

2 participants