Repository navigation
fix(hip): resolve a str enum name in list-argument makers too - #2401
Conversation
Follow-up to #2356/#2393. That fix covered scalar _make_index arguments whose own default is None, so the namespace couldn't be inferred. A separate 12-site family in hip.py has the same symptom but a different shape: the str name is a loop variable over a list parameter (e.g. _make_param_dh_group_list(groups=['Group_384_bit_group'])), so the member and int forms of the same call already worked while the str-name form raised ProtocolNotImplemented. Each of the 12 makers gets `if X_namespace is None: X_namespace = Enum_Y` hoisted above its build loop, next to the existing `if X is None: X = []` -- one decision per parameter rather than one per item, and every original _make_index call line stays unchanged (an inline conditional at that indentation pushed 10 of 12 lines past 120 columns). _make_param_transport_format_list's list holds parameter codes, so its namespace is Enum_Parameter -- the same enum its own code argument carries, not a namespace of its own. _make_param_reg_failed's scalar sibling failure_type already resolved by inference (its default is a real enum member); left alone, since the two arguments there now resolve against different enums. 5 of the 9 enums these makers need (Enum_Suite, Enum_NATTraversal, Enum_Registration, Enum_ESPTransformSuite, Enum_Transport) were imported only under TYPE_CHECKING, next to Enum_RegistrationFailure from the same pcapkit.const.hip package already imported at runtime. Promoted all 5: pcapkit/const/hip/*.py never imports from pcapkit/protocols, so this cannot create a cycle -- verified with a cold import of pcapkit.protocols.internet.hip as the very first import, not just `import pcapkit`. Tests: tests/protocols/internet/test_hip_list_argument_str_names_2394_unit.py, 7 tests / 17 subtests -- str/member/int parity for all 12 sites, a mixed list, the scalar sibling's inference, an explicit namespace override, an unknown-name raise, the 5 promoted enums, and an AST walk asserting every list-argument _make_index call in hip.py has a covering case.
|
Review: NEEDS CHANGES at One real issue: the new test file's prose and one assertion ( Non-blocking finding from the review, worth knowing: with |
test_hip_list_argument_str_names_2394_unit.py stated counts of the HIP
makers it covers ("twelve", "thirteenth", "five") in prose, and pinned
len(found) == 12 as an assertion -- both forbidden by the project's
state-no-count convention (docs/source/contributing/conventions/
documentation.rst), which extends to count pins and the tests that check
them, not just narrative docs. Found by #2401's own cross-review, which
landed after that PR had already merged.
Reworded the 8 affected lines to describe shape rather than count (e.g.
"every one of them" rather than "all twelve"). Dropped the len(found)
count assertion: it was redundant with the adjacent
assertEqual(found, set(CASES)), whose set equality already forces the
same length check, with a named maker in the failure message, and
without a number that goes stale the moment a 13th site is added.
No behavior change; 7 passed / 17 subtests, same as before.
test_hip_list_argument_str_names_2394_unit.py stated counts of the HIP
makers it covers ("twelve", "thirteenth", "five") in prose, and pinned
len(found) == 12 as an assertion -- both forbidden by the project's
state-no-count convention (docs/source/contributing/conventions/
documentation.rst), which extends to count pins and the tests that check
them, not just narrative docs. Found by #2401's own cross-review, which
landed after that PR had already merged.
Reworded the 8 affected lines to describe shape rather than count (e.g.
"every one of them" rather than "all twelve"). Dropped the len(found)
count assertion: it was redundant with the adjacent
assertEqual(found, set(CASES)), whose set equality already forces the
same length check, with a named maker in the failure message, and
without a number that goes stale the moment a 13th site is added.
No behavior change; 7 passed / 17 subtests, same as before.
make testpasses, and a test case covers the changeWhat is the purpose of your pull request?
fix — bug fixDescription
Closes #2394.
_make_indexarguments whose own default isNone. A separate 12-site family inhip.pyhas the same symptom but a different shape — the str name is a loop variable over a list parameter (e.g._make_param_dh_group_list(groups=['Group_384_bit_group'])) — so the member/int forms of the same call already worked while the str-name form raisedProtocolNotImplemented.if X_namespace is None: X_namespace = Enum_Yhoisted above its build loop, next to the existingif X is None: X = []. Chosen over inlining the conditional at the_make_indexcall site because at that indentation it pushed 10 of 12 lines past 120 columns._make_param_transport_format_list's list holds parameter codes, so its namespace isEnum_Parameter— the same enum its owncodeargument carries._make_param_reg_failed's scalar siblingfailure_typealready resolved by inference (its default is a real enum member); left alone.Enum_Suite,Enum_NATTraversal,Enum_Registration,Enum_ESPTransformSuite,Enum_Transport) wereTYPE_CHECKING-only, next toEnum_RegistrationFailurefrom the samepcapkit.const.hippackage already imported at runtime. Promoted all 5 —pcapkit/const/hip/*.pynever imports frompcapkit/protocols, so this can't create a cycle; verified with a cold import ofpcapkit.protocols.internet.hipas the very first import.tests/protocols/internet/test_hip_list_argument_str_names_2394_unit.py, 7 tests / 17 subtests — str/member/int parity for all 12 sites, a mixed list, the scalar sibling's inference, an explicit namespace override, an unknown-name raise, the 5 promoted enums, and an AST walk asserting every list-argument_make_indexcall inhip.pyhas a covering case.