Skip to content

fix(const): OptionType.register_alias always raises 'not a registered OptionType' - #1369

Merged
JarryShaw merged 1 commit into
mainfrom
fix/option-type-register-alias-1330
Oct 8, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix/option-type-register-alias-1330

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner

Please follow the guide below

  • You will be asked some questions, please read them carefully and answer honestly

  • Put an x into all the boxes [ ] relevant to your pull request (like that [x])

  • Use Preview tab to see how your pull request will actually look like

  • Searched for similar pull requests

  • Followed the coding style (pylint/mypy/isort with the Makefile flags on the three changed files; no new findings)

  • make test passes, and a test case covers the change (only the modules listed below)

  • Added a changelog entry — N/A, added centrally

What is the purpose of your pull request?

  • fix — corrects a defect

Closes #1330

OptionType.register_alias overrides the base, which looked the int code up among the formatted '{name} [{value}]' keys. Namespace rule: value resolves in the alias name's prefix namespace overlaid on opt, as get() does. __members_ns__ is restored after extend_enum, whose throwaway __new__ call otherwise overwrites the member there (measured). Vendor template changed; const re-rendered offline from the committed payload, byte-identical. corekit/enum.py untouched.

probe before after
register_alias(1, 'opt_comment_alias') ValueError opt_comment
register_alias(2, 'if_label') ValueError if_name; __members_ns__['if'][2] still if_name
register_alias(0x7ABC, 'if_x') ValueError ValueError

Tests: new test_const_option_type_alias_unit.py 7 passed; 5 of 7 fail on the origin/main const file (the two refusal cases pin guards that already held). Also green: test_register_roundtrip_unit 8, test_const_registry_protocol 74, test_const_enum_no_mint 68, test_pcapng_unit 97, tests/project 389 passed / 1 skipped, run_unittest_leg.py const 499 tests, 0 failures.

… OptionType'

- OptionType overrides register_alias: the base tested the int code against
  _value2member_map_, whose keys are the formatted '{name} [{value}]'
  strings, so no call could succeed.
- The member is resolved as get() resolves it: the alias name's namespace
  overlaid on opt. The alias adds a name only; __members_ns__ keeps the
  member, which extend_enum's throwaway __new__ call would overwrite.
- vendor template changed to match; const file re-rendered offline from the
  committed payload, byte-identical.
- new test: tests/const/test_const_option_type_alias_unit.py.

Closes #1330
@JarryShaw JarryShaw added fix Pull requests that fix a defect (fix: subject prefix) const Regenerated IANA or vendor constant tables; members keep their numeric values review: running A cross-review is in flight against the current head - no verdict yet labels Oct 7, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Cross-review verdict on c16fc029d: GOOD TO GO (Sonnet reviewed; author Opus).

  • Repro: on main's const file, all 9 register_alias calls raised … is not a registered OptionType. Here, 8 resolve to the right member across the if, opt, epb, isb, ns and pack namespaces. The 9th (shb_…) is refused because no shb namespace exists.
  • Round trip: after the aliasing, get(code, namespace=ns), get(member.value) and OptionType(member.value) still return the original member in every namespace, and get(alias) returns the aliased one. Aliasing a member made with register() also works.
  • No partial state: a snapshot of __members_ns__ before and after shows zero changed entries, so the finally restore holds. A colliding name, an unknown code and a repeated alias each raise ValueError and leave both maps untouched.
  • Rendering: the PR's template renders its const file byte-for-byte, and main's template reproduces main's.
  • Tests: the revert proof gives 5 of 7 failing. The const leg runs 499 tests with 0 failures; test_pcapng_unit gives 96 passed.

Nits, not blocking:

  • With the arguments reversed, register_alias('name', 1) now raises AttributeError where main raised ValueError. The fix holds for the base's (value, name) order only, so the PR body's "either argument order" overstates it. A type check that raises ValueError would keep main's behaviour.
  • The error message reads "namespace 'opt' or opt".
  • No test covers the epb/isb/ns refusal paths.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Coverage: 88.97% (unit tier, Python 3.14, c16fc029d, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18791 1034 2352 843 90.27%
pcapkit/corekit 1949 84 606 20 94.91%
pcapkit/dumpkit 189 1 68 1 99.22%
pcapkit/foundation 2443 102 852 39 94.39%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 16013 206 4178 177 98.06%
pcapkit/toolkit 539 74 168 3 84.58%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2359 1006 158 42.84%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw
JarryShaw merged commit 3b92dbb into main Oct 8, 2026
42 checks passed
@JarryShaw
JarryShaw deleted the fix/option-type-register-alias-1330 branch October 8, 2026 00:53
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 8, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

const Regenerated IANA or vendor constant tables; members keep their numeric values fix Pull requests that fix a defect (fix: subject prefix)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(const): OptionType.register_alias always raises 'not a registered OptionType'

1 participant