Repository navigation
fix(protocols): resolve a str enum name in makers whose argument defaults to None (#2356) - #2361
Conversation
…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.
|
Review: NEEDS CHANGES at 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. 3. Recommended, not required: a case that an unknown name still raises Verified independently:
One correction for the PR body: it says #2350 is merged — it's still open ( #5, disclosed in the PR body and not a blocker: Follow-up, not blocking: HIP's list-form makers ( |
Please follow the guide below
make pylint,make mypy,make isort)make testpasses, and a test case covers the changedocs/source/changelog/and regeneratedCHANGELOG.md, if the change is user-visibleWhat is the purpose of your pull request?
fix— corrects a defectDescription of your pull request and other information
Fixes #2356
_make_indexresolves astrname against the enum of the argument's default when no namespace is given. Five makers have arguments that default toNone, so a member name had no enum to resolve against and raisedProtocolNotImplemented:_make_opt_mpl:seed_type→ falls back toSeedID_make_opt_smf_dpd:tid_type→ falls back toTaggerID_make_start_line:status→ falls back toStatusCodeEach site now passes
<arg>_namespace if <arg>_namespace is not None else Enum_X, so an explicit namespace still wins. An AST scan ofpcapkit/protocolsfound no other_make_indexcall with aNonedefault and no fallback.Tests:
tests/protocols/test_make_str_enum_name_none_default_2356_unit.pychecks 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 onmain(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/isortraise nothing new on the changed files; only the counts on existingtoo-many-locals/too-many-lineswarnings went up.Side note, not changed here:
status='CODE_200'(likestatus=200) gives an empty reason phrase (HTTP/1.1 200 \r\n), while passingStatusCode.CODE_200gives200 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.